Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7e596fe

Browse files
author
Arlin
committed
Add localizable string by ios
1 parent b5bb2e4 commit 7e596fe

File tree

3 files changed

+49
-43
lines changed

3 files changed

+49
-43
lines changed

iOS/APIExample/Examples/Advanced/SpatialAudio/SpatialAudio.storyboard

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,10 @@
100100
<action selector="startBtnClicked:" destination="Y6W-OH-hqX" eventType="touchUpInside" id="prV-Za-pzQ"/>
101101
</connections>
102102
</button>
103-
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="请插入耳机体验空间音效效果" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="2" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Mot-iW-9hr">
104-
<rect key="frame" x="15" y="94" width="384" height="21.5"/>
105-
<fontDescription key="fontDescription" type="boldSystem" pointSize="18"/>
106-
<nil key="textColor"/>
103+
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="请插入耳机体验空间音效效果" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Mot-iW-9hr">
104+
<rect key="frame" x="15" y="79" width="384" height="21.5"/>
105+
<fontDescription key="fontDescription" type="system" pointSize="18"/>
106+
<color key="textColor" white="0.33333333333333331" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
107107
<nil key="highlightedColor"/>
108108
</label>
109109
<imageView hidden="YES" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="spatial_self" translatesAutoresizingMaskIntoConstraints="NO" id="Iy1-zt-cYH">
@@ -129,7 +129,7 @@
129129
<constraint firstItem="MmB-d4-Cfb" firstAttribute="centerX" secondItem="5EZ-qb-Rvc" secondAttribute="centerX" id="bkA-9E-91k"/>
130130
<constraint firstItem="vDu-zF-Fre" firstAttribute="bottom" secondItem="agC-Bm-evH" secondAttribute="bottom" constant="50" id="dpn-pX-GzL"/>
131131
<constraint firstItem="MmB-d4-Cfb" firstAttribute="centerY" secondItem="5EZ-qb-Rvc" secondAttribute="centerY" id="gOb-eN-tr6"/>
132-
<constraint firstItem="Mot-iW-9hr" firstAttribute="top" secondItem="vDu-zF-Fre" secondAttribute="top" constant="50" id="lJ8-ed-Byx"/>
132+
<constraint firstItem="Mot-iW-9hr" firstAttribute="top" secondItem="vDu-zF-Fre" secondAttribute="top" constant="35" id="lJ8-ed-Byx"/>
133133
<constraint firstItem="Iy1-zt-cYH" firstAttribute="centerX" secondItem="5EZ-qb-Rvc" secondAttribute="centerX" id="s5d-aK-0ag"/>
134134
<constraint firstItem="vDu-zF-Fre" firstAttribute="trailing" secondItem="Mot-iW-9hr" secondAttribute="trailing" constant="15" id="yda-AF-HXf"/>
135135
</constraints>

iOS/APIExample/Examples/Advanced/SpatialAudio/SpatialAudio.swift

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ class SpatialAudioMain: BaseViewController {
4343
}
4444

4545
func setupUI() {
46-
infoLabel.text = "请插入耳机体验空间音效效果".localized
46+
infoLabel.text = "Please insert headphones to experience the spatial audio effect".localized
47+
startButton.setTitle("Start".localized, for: .normal)
4748

4849
let panGesture = UIPanGestureRecognizer(target: self, action: #selector(panGestureChanged))
4950
self.soundSourceView.addGestureRecognizer(panGesture)
@@ -66,10 +67,12 @@ class SpatialAudioMain: BaseViewController {
6667
self.peopleView.isHidden = false
6768
self.soundSourceView.isHidden = false
6869
} else {
69-
self.infoLabel.text = "你会听到一段音乐, \(self.downCount - timeout)秒后这段音乐会通过空间音效的方式播放"
70+
let text = "You will hear a piece of music, and after 10 seconds this piece of music will be played through spatial audio effects".localized
71+
self.infoLabel.text = "\(text)(\(self.downCount - timeout))"
7072
}
7173
} else {
72-
self.infoLabel.text = "现在您可以移动喇叭图标到不同的位置, 体验空间音效效果(\(self.downCount))".localized
74+
let text = "Now you can move the speaker icon to experience the spatial audio effect".localized
75+
self.infoLabel.text = "\(text)(\(self.downCount))"
7376
if self.downCount == 0 {
7477
self.agoraKit.stopEchoTest()
7578
self.agoraKit.enableSpatialAudio(false)
@@ -78,55 +81,54 @@ class SpatialAudioMain: BaseViewController {
7881
self.peopleView.isHidden = true
7982
self.soundSourceView.isHidden = true
8083
self.startButton.isHidden = false
81-
self.infoLabel.text = "请插入耳机体验空间音效效果".localized
84+
self.infoLabel.text = "Please insert headphones to experience the spatial audio effect".localized
8285
}
8386
}
8487
}
8588
}
8689

8790
@objc func panGestureChanged(gesture: UIPanGestureRecognizer) {
88-
let circleCenter = self.peopleView.center
8991
let move = gesture.translation(in: self.view)
90-
var newCenter = gesture.view!.center
91-
newCenter = CGPoint(x: newCenter.x + move.x, y: newCenter.y + move.y)
92-
93-
let deltaX = newCenter.x - circleCenter.x
94-
let deltaY = circleCenter.y - newCenter.y
95-
if deltaX == 0 {return}
96-
97-
// In spatial audio, angle is range [0, 360], it is angle 0 when at Y direction.
98-
let tanValue = abs(deltaY) / abs(deltaX)
99-
let tanAngle = atan(tanValue) * 180.0 / Double.pi
100-
var spatialAngle = 0.0
101-
if deltaX > 0 && deltaY > 0 { // scope I
102-
spatialAngle = 270.0 + tanAngle
103-
} else if deltaX < 0 && deltaY > 0 { // scope II
104-
spatialAngle = 90.0 - tanAngle
105-
} else if deltaX < 0 && deltaY < 0 { // scope III
106-
spatialAngle = 90.0 + tanAngle
107-
} else if deltaX > 0 && deltaY < 0 { // scope IV
108-
spatialAngle = 270.0 - tanAngle
92+
var objectCenter = gesture.view!.center
93+
objectCenter = CGPoint(x: objectCenter.x + move.x, y: objectCenter.y + move.y)
94+
soundSourceView.center = objectCenter
95+
gesture.setTranslation(.zero, in: self.view)
96+
97+
if gesture.state == .ended {
98+
updatePosition(objectCenter: objectCenter)
10999
}
100+
}
101+
102+
func updatePosition(objectCenter: CGPoint) {
103+
let circleCenter = self.peopleView.center
104+
let deltaX = objectCenter.x - circleCenter.x
105+
let deltaY = circleCenter.y - objectCenter.y
106+
let R = sqrt(deltaX * deltaX + deltaY * deltaY)
110107

111-
if gesture.state == .ended {
112-
let L = sqrt(deltaX * deltaX + deltaY * deltaY)
113-
let maxL = UIScreen.main.bounds.height / 2.0
114-
let maxSpatailDistance = 30.0
115-
let spatialDistance = L * maxSpatailDistance / maxL
116-
currentAngle = spatialAngle
117-
currentDistance = spatialDistance
118-
119-
self.updateRemoteUserSpatialAudioPositon()
108+
// In spatial audio, angle is range [0, 360], it is angle 0 when at Y direction with anti-clockwise
109+
let TwoPI = Double.pi * 2.0
110+
let cosAngle = acos(deltaX / R)
111+
let mathAngle = deltaY > 0 ? cosAngle : (TwoPI - cosAngle)
112+
var spatialAngle = mathAngle - TwoPI / 4.0
113+
if spatialAngle < 0 {
114+
spatialAngle = TwoPI + spatialAngle
120115
}
121116

122-
self.soundSourceView.center = newCenter
123-
gesture.setTranslation(.zero, in: self.view)
117+
currentAngle = spatialAngle
118+
currentDistance = R
119+
self.updateRemoteUserSpatialAudioPositon()
120+
print("\(mathAngle), \(spatialAngle), \(deltaX), \(deltaY)")
124121
}
125122

126123
func updateRemoteUserSpatialAudioPositon() {
124+
let maxR = UIScreen.main.bounds.height / 2.0
125+
let maxSpatailDistance = 30.0
126+
let spatialDistance = currentDistance * maxSpatailDistance / maxR
127+
let spatialAngle = currentAngle * 180.0 / Double.pi
128+
127129
let spatialParams = AgoraSpatialAudioParams()
128-
spatialParams.speaker_azimuth = .of(Double(currentAngle))
129-
spatialParams.speaker_distance = .of(currentDistance)
130+
spatialParams.speaker_azimuth = .of(spatialAngle)
131+
spatialParams.speaker_distance = .of(spatialDistance)
130132
spatialParams.speaker_elevation = .of(0)
131133
spatialParams.enable_blur = .of(false)
132134
spatialParams.enable_air_absorb = .of(true)

iOS/APIExample/zh-Hans.lproj/Localizable.strings

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,12 @@
124124
"Stop Video/Audio Test" = "停止音视频测试";
125125
"push" = "推流";
126126
"stop" = "停止";
127-
"Spatial Audio" = "空间音效";
128127
"Start Share" = "开始屏幕共享";
129128
"Stop Share" = "停止屏幕共享";
130129
"Open App Audio" = "打开应用内音频";
131130
"Close App Audio" = "关闭应用内音频";
131+
"Spatial Audio" = "空间音效";
132+
"Start" = "点击开始";
133+
"Please insert headphones to experience the spatial audio effect" = "请插入耳机体验空间音效效果";
134+
"You will hear a piece of music, and after 10 seconds this piece of music will be played through spatial audio effects" = "你会听到一段音乐,10秒后这段音乐会通过空间音效的方式播放";
135+
"Now you can move the speaker icon to experience the spatial audio effect" = "现在您可以移动喇叭图标到不同的位置,体验空间音效效果";

0 commit comments

Comments
 (0)