@@ -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