Skip to content

Commit adff87e

Browse files
author
xianing
committed
adapt 3.5.1 audio feature
1 parent 3e64ccf commit adff87e

6 files changed

Lines changed: 156 additions & 83 deletions

File tree

iOS/APIExample/Examples/Advanced/AudioMixing/AudioMixing.swift

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import AgoraRtcKit
1111
import AGEVideoLayout
1212

1313
let EFFECT_ID:Int32 = 1
14+
let BGM_URL = "https://webdemo.agora.io/multi_audioTrack.m4a"
1415

1516
class AudioMixingEntry : UIViewController
1617
{
@@ -86,6 +87,8 @@ class AudioMixingMain: BaseViewController {
8687
@IBOutlet weak var audioEffectVolumeSlider: UISlider!
8788
var audioViews: [UInt:VideoView] = [:]
8889
var timer:Timer?
90+
var monoMode:AgoraAudioMixingDualMonoMode = .L
91+
var trackIndex = 1;
8992

9093
// indicate if current instance has joined channel
9194
var isJoined: Bool = false
@@ -163,6 +166,31 @@ class AudioMixingMain: BaseViewController {
163166
return Array(audioViews.values).sorted(by: { $0.uid < $1.uid })
164167
}
165168

169+
170+
@IBAction func onChangeTrack(_ sender:UISegmentedControl){
171+
switch sender.selectedSegmentIndex {
172+
case 0:
173+
self.trackIndex = 1
174+
case 1:
175+
self.trackIndex = 2
176+
default:
177+
break
178+
}
179+
agoraKit.selectAudioTrack(trackIndex)
180+
}
181+
182+
@IBAction func onChangeMonoMode(_ sender:UISegmentedControl){
183+
switch sender.selectedSegmentIndex {
184+
case 0:
185+
self.monoMode = .L
186+
case 1:
187+
self.monoMode = .R
188+
default:
189+
break
190+
}
191+
agoraKit.setAudioMixingDualMonoMode(monoMode)
192+
}
193+
166194
@IBAction func onChangeAudioMixingVolume(_ sender:UISlider){
167195
let value:Int = Int(sender.value)
168196
print("adjustAudioMixingVolume \(value)")
@@ -188,13 +216,15 @@ class AudioMixingMain: BaseViewController {
188216
}
189217

190218
@IBAction func onStartAudioMixing(_ sender:UIButton){
191-
if let filepath = Bundle.main.path(forResource: "audiomixing", ofType: "mp3") {
192-
let result = agoraKit.startAudioMixing(filepath, loopback: false, replace: false, cycle: -1, startPos: 0)
219+
if let filepath = Bundle.main.path(forResource: "mTrack", ofType: "m4a") {
220+
let result = agoraKit.startAudioMixing(BGM_URL, loopback: false, replace: false, cycle: -1, startPos: 0)
193221
if result != 0 {
194222
self.showAlert(title: "Error", message: "startAudioMixing call failed: \(result), please check your params")
195223
} else {
196224
startProgressTimer()
197225
updateTotalDuration(reset: false)
226+
agoraKit.setAudioMixingDualMonoMode(monoMode)
227+
agoraKit.selectAudioTrack(trackIndex)
198228
}
199229
}
200230
}
@@ -232,8 +262,8 @@ class AudioMixingMain: BaseViewController {
232262
if(timer == nil) {
233263
timer = Timer.scheduledTimer(withTimeInterval: 0.5, repeats: true, block: { [weak self](timer:Timer) in
234264
guard let weakself = self else {return}
235-
guard let filepath = Bundle.main.path(forResource: "audiomixing", ofType: "mp3") else {return}
236-
let progress = Float(weakself.agoraKit.getAudioMixingCurrentPosition()) / Float(weakself.agoraKit.getAudioFileInfo(filepath))
265+
// guard let filepath = Bundle.main.path(forResource: "audiomixing", ofType: "mp3") else {return}
266+
let progress = Float(weakself.agoraKit.getAudioMixingCurrentPosition()) / Float(weakself.agoraKit.getAudioMixingDuration())
237267
weakself.audioMixingProgressView.setProgress(progress, animated: true)
238268
})
239269
}
@@ -251,9 +281,8 @@ class AudioMixingMain: BaseViewController {
251281
if(reset) {
252282
audioMixingDuration.text = "00 : 00"
253283
} else {
254-
guard let filepath = Bundle.main.path(forResource: "audiomixing", ofType: "mp3") else {return}
255-
let duration = agoraKit.getAudioFileInfo(filepath)
256-
let seconds = duration / 1000
284+
// let duration = agoraKit.getAudioFileInfo(BGM_URL)
285+
let seconds = agoraKit.getAudioMixingDuration() / 1000
257286
audioMixingDuration.text = "\(String(format: "%02d", seconds / 60)) : \(String(format: "%02d", seconds % 60))"
258287
}
259288
}

0 commit comments

Comments
 (0)