Skip to content

Commit fb46aa2

Browse files
author
zhaoyongqiang
committed
fix bug
1 parent 41ee301 commit fb46aa2

33 files changed

Lines changed: 143 additions & 34 deletions

File tree

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ class AudioMixingMain: BaseViewController {
118118

119119
// disable video module
120120
agoraKit.disableVideo()
121+
agoraKit.enableAudio()
121122

122123
// set audio profile/audio scenario
123124
agoraKit.setAudioProfile(audioProfile)
@@ -158,6 +159,8 @@ class AudioMixingMain: BaseViewController {
158159
if parent == nil {
159160
// leave channel when exiting the view
160161
if isJoined {
162+
agoraKit.disableAudio()
163+
agoraKit.disableVideo()
161164
agoraKit.leaveChannel { (stats) -> Void in
162165
LogUtils.log(message: "left channel, duration: \(stats.duration)", level: .info)
163166
}

iOS/APIExample/Examples/Advanced/ContentInspect/ContentInspect.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class ContentInspectViewController: BaseViewController {
3333

3434
agoraKit = AgoraRtcEngineKit.sharedEngine(withAppId: KeyCenter.AppId, delegate: self)
3535
agoraKit.enableVideo()
36+
agoraKit.enableAudio()
3637

3738
let videoCanvas = AgoraRtcVideoCanvas()
3839
videoCanvas.view = localVideoView
@@ -49,6 +50,8 @@ class ContentInspectViewController: BaseViewController {
4950
agoraKit.enableContentInspect(true, config:inspectConfig)
5051

5152
let options = AgoraRtcChannelMediaOptions()
53+
options.publishCameraTrack = .of(true)
54+
options.publishMicrophoneTrack = .of(true)
5255
options.clientRoleType = .of((Int32)(AgoraClientRole.broadcaster.rawValue))
5356
let result = agoraKit.joinChannel(byToken: KeyCenter.Token, channelId: channelId, uid: 0, mediaOptions: options)
5457
if result != 0 {
@@ -59,6 +62,8 @@ class ContentInspectViewController: BaseViewController {
5962

6063
override func didMove(toParent parent: UIViewController?) {
6164
if parent == nil {
65+
agoraKit.disableAudio()
66+
agoraKit.disableVideo()
6267
agoraKit.leaveChannel(nil)
6368
}
6469
}

iOS/APIExample/Examples/Advanced/CreateDataStream/CreateDataStream.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ class CreateDataStreamMain: BaseViewController {
106106
// the token has to match the ones used for channel join
107107
let option = AgoraRtcChannelMediaOptions()
108108
option.publishCameraTrack = .of(true)
109+
option.publishMicrophoneTrack = .of(true)
109110
option.clientRoleType = .of((Int32)(AgoraClientRole.broadcaster.rawValue))
110111

111112
let result = agoraKit.joinChannel(byToken: KeyCenter.Token, channelId: channelName, uid: 0, mediaOptions: option)
@@ -158,6 +159,8 @@ class CreateDataStreamMain: BaseViewController {
158159
// leave channel when exiting the view
159160
if isJoined {
160161
agoraKit.stopPreview()
162+
agoraKit.disableVideo()
163+
agoraKit.disableAudio()
161164
agoraKit.leaveChannel { (stats) -> Void in
162165
LogUtils.log(message: "left channel, duration: \(stats.duration)", level: .info)
163166
}

iOS/APIExample/Examples/Advanced/CustomAudioRender/CustomAudioRender.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class CustomAudioRenderMain: BaseViewController {
6464

6565
// disable video module
6666
agoraKit.disableVideo()
67+
agoraKit.enableAudio()
6768
// Set audio route to speaker
6869
agoraKit.setDefaultAudioRouteToSpeakerphone(true)
6970

@@ -84,6 +85,8 @@ class CustomAudioRenderMain: BaseViewController {
8485
// when joining channel. The channel name and uid used to calculate
8586
// the token has to match the ones used for channel join
8687
let option = AgoraRtcChannelMediaOptions()
88+
option.publishCameraTrack = .of(false)
89+
option.publishMicrophoneTrack = .of(true)
8790
option.clientRoleType = .of((Int32)(AgoraClientRole.broadcaster.rawValue))
8891

8992
let result = agoraKit.joinChannel(byToken: KeyCenter.Token, channelId: channelName, uid: 0, mediaOptions: option)
@@ -100,6 +103,7 @@ class CustomAudioRenderMain: BaseViewController {
100103
if parent == nil {
101104
// leave channel when exiting the view
102105
if isJoined {
106+
agoraKit.disableAudio()
103107
agoraKit.leaveChannel { (stats) -> Void in
104108
LogUtils.log(message: "left channel, duration: \(stats.duration)", level: .info)
105109
}

iOS/APIExample/Examples/Advanced/CustomAudioSource/CustomAudioSource.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class CustomAudioSourceMain: BaseViewController {
6666

6767
// disable video module
6868
agoraKit.disableVideo()
69+
agoraKit.enableAudio()
6970
// Set audio route to speaker
7071
agoraKit.setDefaultAudioRouteToSpeakerphone(true)
7172

@@ -98,6 +99,7 @@ class CustomAudioSourceMain: BaseViewController {
9899
if parent == nil {
99100
// leave channel when exiting the view
100101
if isJoined {
102+
agoraKit.disableAudio()
101103
exAudio.stopWork()
102104
agoraKit.leaveChannel { (stats) -> Void in
103105
LogUtils.log(message: "left channel, duration: \(stats.duration)", level: .info)

iOS/APIExample/Examples/Advanced/CustomPcmAudioSource/CustomPcmAudioSource.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ class CustomPcmAudioSourceMain: BaseViewController {
110110
// leave channel when exiting the view
111111
pcmSourcePush?.stop()
112112
if isJoined {
113+
agoraKit.disableAudio()
113114
pcmSourcePush?.stop()
114115
agoraKit.leaveChannel { (stats) -> Void in
115116
LogUtils.log(message: "left channel, duration: \(stats.duration)", level: .info)
@@ -124,7 +125,7 @@ class CustomPcmAudioSourceMain: BaseViewController {
124125
option.publishCameraTrack = .of(false)
125126
option.publishMicrophoneTrack = .of(sender.isOn)
126127
option.publishCustomAudioTrack = .of(pushPcmSwitch.isOn)
127-
option.clientRoleType = .of((Int32)(sender.isOn ? AgoraClientRole.broadcaster.rawValue : AgoraClientRole.audience.rawValue))
128+
option.clientRoleType = .of((Int32)(AgoraClientRole.broadcaster.rawValue))
128129
agoraKit.updateChannel(with: option)
129130
}
130131

iOS/APIExample/Examples/Advanced/CustomVideoRender/CustomVideoRender.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class CustomVideoRenderMain: BaseViewController {
6969

7070
// enable video module and set up video encoding configs
7171
agoraKit.enableVideo()
72+
agoraKit.enableAudio()
7273
agoraKit.setVideoEncoderConfiguration(AgoraVideoEncoderConfiguration(size: AgoraVideoDimension640x360,
7374
frameRate: .fps30,
7475
bitrate: AgoraVideoBitrateStandard,
@@ -97,6 +98,8 @@ class CustomVideoRenderMain: BaseViewController {
9798
// when joining channel. The channel name and uid used to calculate
9899
// the token has to match the ones used for channel join
99100
let option = AgoraRtcChannelMediaOptions()
101+
option.publishCameraTrack = .of(true)
102+
option.publishMicrophoneTrack = .of(true)
100103
option.clientRoleType = .of((Int32)(AgoraClientRole.broadcaster.rawValue))
101104

102105
let result = agoraKit.joinChannel(byToken: KeyCenter.Token, channelId: channelName, uid: 0, mediaOptions: option)
@@ -118,6 +121,8 @@ class CustomVideoRenderMain: BaseViewController {
118121
if parent == nil {
119122
// leave channel when exiting the view
120123
if isJoined {
124+
agoraKit.disableAudio()
125+
agoraKit.disableVideo()
121126
agoraKit.leaveChannel { (stats) -> Void in
122127
LogUtils.log(message: "left channel, duration: \(stats.duration)", level: .info)
123128
}

iOS/APIExample/Examples/Advanced/CustomVideoSourcePush/CustomVideoSourcePush.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ class CustomVideoSourcePushMain: BaseViewController {
8484

8585
// enable video module and set up video encoding configs
8686
agoraKit.enableVideo()
87+
agoraKit.enableAudio()
8788

8889
// setup my own camera as custom video source
8990
// note setupLocalVideo is not working when using pushExternalVideoFrame
@@ -112,7 +113,6 @@ class CustomVideoSourcePushMain: BaseViewController {
112113
// when joining channel. The channel name and uid used to calculate
113114
// the token has to match the ones used for channel join
114115
let option = AgoraRtcChannelMediaOptions()
115-
option.publishCameraTrack = .of(false)
116116
option.publishCustomAudioTrack = .of(false)
117117
option.publishCustomVideoTrack = .of(true)
118118
option.clientRoleType = .of((Int32)(AgoraClientRole.broadcaster.rawValue))
@@ -132,9 +132,16 @@ class CustomVideoSourcePushMain: BaseViewController {
132132
customCamera?.stopCapture()
133133
// leave channel when exiting the view
134134
if isJoined {
135+
agoraKit.disableAudio()
136+
agoraKit.disableVideo()
137+
let option = AgoraRtcChannelMediaOptions()
138+
option.publishCustomAudioTrack = .of(false)
139+
option.publishCustomVideoTrack = .of(false)
140+
agoraKit.updateChannel(with: option)
135141
agoraKit.leaveChannel { (stats) -> Void in
136142
LogUtils.log(message: "left channel, duration: \(stats.duration)", level: .info)
137143
}
144+
agoraKit = nil
138145
}
139146
}
140147
}

iOS/APIExample/Examples/Advanced/FusionCDN/FusionCDN.swift

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ class FusionCDNHost: BaseViewController {
126126

127127
// enable video module and set up video encoding configs
128128
agoraKit.enableVideo()
129+
agoraKit.enableAudio()
129130

130131
guard let resolution = GlobalSettings.shared.getSetting(key: "resolution")?.selectedOption().value as? CGSize,
131132
let _ = GlobalSettings.shared.getSetting(key: "fps")?.selectedOption().value as? AgoraVideoFrameRate else {return}
@@ -161,7 +162,7 @@ class FusionCDNHost: BaseViewController {
161162
guard let mode = configs["mode"] as? StreamingMode else {return}
162163
guard let channelName = configs["channelName"] as? String else {return}
163164
if mode == .agoraChannel {
164-
streamingUrl = "rtmp://mdetest.push.agoramde.agoraio.cn/live/\(channelName)"
165+
streamingUrl = "rtmp://push.webdemo.agoraio.cn/lbhd/\(channelName)"
165166
rtcSwitcher.isEnabled = false
166167
}
167168
else {
@@ -262,6 +263,8 @@ class FusionCDNHost: BaseViewController {
262263
if parent == nil {
263264
// leave channel when exiting the view
264265
if rtcStreaming {
266+
agoraKit.disableAudio()
267+
agoraKit.disableVideo()
265268
agoraKit.leaveChannel { (stats) -> Void in
266269
LogUtils.log(message: "left channel, duration: \(stats.duration)", level: .info)
267270
}
@@ -323,7 +326,7 @@ class FusionCDNAudience: BaseViewController {
323326
agoraKit = AgoraRtcEngineKit.sharedEngine(with: config, delegate: self)
324327
agoraKit.setLogFile(LogUtils.sdkLogPath())
325328
// make myself a broadcaster
326-
agoraKit.setClientRole(.broadcaster)
329+
agoraKit.setClientRole(.audience)
327330

328331
// enable video module and set up video encoding configs
329332
agoraKit.enableVideo()
@@ -358,9 +361,11 @@ class FusionCDNAudience: BaseViewController {
358361
guard let mode = configs["mode"] as? StreamingMode else {return}
359362
guard let channelName = configs["channelName"] as? String else {return}
360363
if mode == .agoraChannel {
361-
streamingUrl = "rtmp://push.webdemo.agoraio.cn/lbhd/\(channelName)"
364+
streamingUrl = "rtmp://pull.webdemo.agoraio.cn/lbhd/\(channelName)"
362365
rtcSwitcher.isEnabled = false
363-
let ret = mediaPlayerKit.open(withAgoraCDNSrc: streamingUrl, startPos: 0)
366+
let mediaSource = AgoraMediaSource()
367+
mediaSource.url = streamingUrl
368+
let ret = mediaPlayerKit.open(with: mediaSource)
364369
print(ret)
365370
}
366371
else {
@@ -446,7 +451,14 @@ class FusionCDNAudience: BaseViewController {
446451
})
447452
}
448453

449-
454+
override func viewDidDisappear(_ animated: Bool) {
455+
super.viewDidDisappear(animated)
456+
agoraKit.disableVideo()
457+
agoraKit.disableAudio()
458+
agoraKit.leaveChannel { (stats) -> Void in
459+
LogUtils.log(message: "left channel, duration: \(stats.duration)", level: .info)
460+
}
461+
}
450462
}
451463

452464

iOS/APIExample/Examples/Advanced/JoinMultiChannel/JoinMultiChannel.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ class JoinMultiChannelMain: BaseViewController {
8585

8686
// enable video module and set up video encoding configs
8787
agoraKit.enableVideo()
88+
agoraKit.enableAudio()
8889
agoraKit.setVideoEncoderConfiguration(AgoraVideoEncoderConfiguration(size: AgoraVideoDimension640x360,
8990
frameRate: .fps30,
9091
bitrate: AgoraVideoBitrateStandard,
@@ -110,7 +111,7 @@ class JoinMultiChannelMain: BaseViewController {
110111
var mediaOptions = AgoraRtcChannelMediaOptions()
111112
// publish audio and camera track for channel 1
112113
mediaOptions.publishCameraTrack = .of(true)
113-
mediaOptions.publishCustomAudioTrack = .of(true)
114+
mediaOptions.publishMicrophoneTrack = .of(true)
114115
mediaOptions.autoSubscribeVideo = .of(true)
115116
mediaOptions.autoSubscribeAudio = .of(true)
116117
mediaOptions.clientRoleType = .of((Int32)(AgoraClientRole.broadcaster.rawValue))
@@ -129,7 +130,7 @@ class JoinMultiChannelMain: BaseViewController {
129130
// join channel2
130131
mediaOptions = AgoraRtcChannelMediaOptions()
131132
mediaOptions.clientRoleType = .of(Int32(AgoraClientRole.broadcaster.rawValue))
132-
mediaOptions.publishCustomAudioTrack = .of(false)
133+
mediaOptions.publishMicrophoneTrack = .of(false)
133134
mediaOptions.publishCameraTrack = .of(false)
134135
mediaOptions.autoSubscribeVideo = .of(true)
135136
mediaOptions.autoSubscribeAudio = .of(true)
@@ -152,6 +153,8 @@ class JoinMultiChannelMain: BaseViewController {
152153
agoraKit.stopPreview()
153154
// leave channel when exiting the view
154155
agoraKit.leaveChannel()
156+
agoraKit.disableAudio()
157+
agoraKit.disableVideo()
155158
let channel2 = AgoraRtcConnection()
156159
channel2.channelId = channelName2
157160
channel2.localUid = CONNECTION_2_UID

0 commit comments

Comments
 (0)