@@ -127,6 +127,11 @@ private FlutterWebRTCPlugin(Registrar registrar, MethodChannel channel) {
127
127
.setVideoDecoderFactory (new DefaultVideoDecoderFactory (eglContext ))
128
128
.setAudioDeviceModule (audioDeviceModule )
129
129
.createPeerConnectionFactory ();
130
+ }
131
+
132
+ private void startAudioManager () {
133
+ if (rtcAudioManager != null )
134
+ return ;
130
135
131
136
rtcAudioManager = RTCAudioManager .create (registrar .context ());
132
137
// Store existing audio settings and change audio mode to
@@ -141,12 +146,14 @@ public void onAudioDeviceChanged(
141
146
onAudioManagerDevicesChanged (audioDevice , availableAudioDevices );
142
147
}
143
148
});
144
- /*
145
- if (audioManager != null) {
146
- audioManager.stop();
147
- audioManager = null;
149
+ }
150
+
151
+ private void stopAudioManager () {
152
+ if (rtcAudioManager != null ) {
153
+ Log .d (TAG , "Stoping the audio manager..." );
154
+ rtcAudioManager .stop ();
155
+ rtcAudioManager = null ;
148
156
}
149
- */
150
157
}
151
158
152
159
// This method is called when the audio manager reports audio device change,
@@ -297,7 +304,7 @@ public void onMethodCall(MethodCall call, Result notSafeResult) {
297
304
result .success (null );
298
305
} else if (call .method .equals ("peerConnectionDispose" )){
299
306
String peerConnectionId = call .argument ("peerConnectionId" );
300
- peerConnectionClose (peerConnectionId );
307
+ peerConnectionDispose (peerConnectionId );
301
308
result .success (null );
302
309
}else if (call .method .equals ("createVideoRenderer" )) {
303
310
TextureRegistry .SurfaceTextureEntry entry = textures .createSurfaceTexture ();
@@ -362,6 +369,9 @@ public void onMethodCall(MethodCall call, Result notSafeResult) {
362
369
result .success (null );
363
370
} else if (call .method .equals ("enableSpeakerphone" )) {
364
371
boolean enable = call .argument ("enable" );
372
+ if (rtcAudioManager == null ){
373
+ startAudioManager ();
374
+ }
365
375
rtcAudioManager .setSpeakerphoneOn (enable );
366
376
result .success (null );
367
377
} else if (call .method .equals ("getDisplayMedia" )) {
@@ -723,6 +733,9 @@ public String peerConnectionInit(
723
733
parseMediaConstraints (constraints ),
724
734
observer );
725
735
observer .setPeerConnection (peerConnection );
736
+ if (mPeerConnectionObservers .size () == 0 ) {
737
+ startAudioManager ();
738
+ }
726
739
mPeerConnectionObservers .put (peerConnectionId , observer );
727
740
return peerConnectionId ;
728
741
}
@@ -1285,6 +1298,9 @@ public void peerConnectionDispose(final String id) {
1285
1298
pco .dispose ();
1286
1299
mPeerConnectionObservers .remove (id );
1287
1300
}
1301
+ if (mPeerConnectionObservers .size () == 0 ) {
1302
+ stopAudioManager ();
1303
+ }
1288
1304
}
1289
1305
1290
1306
public void mediaStreamRelease (final String id ) {
0 commit comments