Skip to content

Commit a15b31e

Browse files
author
zhaoyongqiang
committed
fix MS-198682 听不到声音的问题
1 parent a801bc5 commit a15b31e

1 file changed

Lines changed: 13 additions & 12 deletions

File tree

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

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,20 @@ class CustomPcmAudioSourceMain: BaseViewController {
7171
return
7272
}
7373

74+
agoraKit.setChannelProfile(.liveBroadcasting)
75+
7476
// make myself a broadcaster
7577
agoraKit.setClientRole(.broadcaster)
76-
7778
// disable video module
7879
agoraKit.disableVideo()
80+
// enable audio module
81+
agoraKit.enableAudio()
7982
// Set audio route to speaker
8083
agoraKit.setDefaultAudioRouteToSpeakerphone(true)
8184

8285
// setup external audio source
8386
pcmSourcePush = AgoraPcmSourcePush(delegate: self, filePath: filepath, sampleRate: Int(sampleRate),
8487
channelsPerFrame: Int(channel), bitPerSample: bitPerSample, samples: samples)
85-
agoraKit.adjustPlaybackSignalVolume(0)
86-
agoraKit.enableExternalAudioSource(withSampleRate: sampleRate, channelsPerFrame: channel)
8788

8889
// start joining channel
8990
// 1. Users can only see each other after they join the
@@ -102,15 +103,15 @@ class CustomPcmAudioSourceMain: BaseViewController {
102103
}
103104
}
104105

105-
override func willMove(toParent parent: UIViewController?) {
106-
if parent == nil {
107-
// leave channel when exiting the view
108-
pcmSourcePush?.stop()
109-
if isJoined {
110-
agoraKit.disableExternalAudioSource()
111-
agoraKit.leaveChannel { (stats) -> Void in
112-
LogUtils.log(message: "left channel, duration: \(stats.duration)", level: .info)
113-
}
106+
override func viewDidDisappear(_ animated: Bool) {
107+
super.viewDidDisappear(animated)
108+
// leave channel when exiting the view
109+
pcmSourcePush?.stop()
110+
agoraKit.disableAudio()
111+
if isJoined {
112+
agoraKit.disableExternalAudioSource()
113+
agoraKit.leaveChannel { (stats) -> Void in
114+
LogUtils.log(message: "left channel, duration: \(stats.duration)", level: .info)
114115
}
115116
}
116117
}

0 commit comments

Comments
 (0)