8000 Fixed the interruption of the Bluetooth headset that was playing musi… · Condelab/flutter-webrtc@cc37c80 · GitHub
[go: up one dir, main page]

Skip to content

Commit cc37c80

Browse files
committed
Fixed the interruption of the Bluetooth headset that was playing music after the plugin started.
1 parent d770a63 commit cc37c80

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

android/src/main/java/com/cloudwebrtc/webrtc/FlutterWebRTCPlugin.java

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,11 @@ private FlutterWebRTCPlugin(Registrar registrar, MethodChannel channel) {
127127
.setVideoDecoderFactory(new DefaultVideoDecoderFactory(eglContext))
128128
.setAudioDeviceModule(audioDeviceModule)
129129
.createPeerConnectionFactory();
130+
}
131+
132+
private void startAudioManager() {
133+
if(rtcAudioManager != null)
134+
return;
130135

131136
rtcAudioManager = RTCAudioManager.create(registrar.context());
132137
// Store existing audio settings and change audio mode to
@@ -141,12 +146,14 @@ public void onAudioDeviceChanged(
141146
onAudioManagerDevicesChanged(audioDevice, availableAudioDevices);
142147
}
143148
});
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;
148156
}
149-
*/
150157
}
151158

152159
// This method is called when the audio manager reports audio device change,
@@ -297,7 +304,7 @@ public void onMethodCall(MethodCall call, Result notSafeResult) {
297304
result.success(null);
298305
} else if(call.method.equals("peerConnectionDispose")){
299306
String peerConnectionId = call.argument("peerConnectionId");
300-
peerConnectionClose(peerConnectionId);
307+
peerConnectionDispose(peerConnectionId);
301308
result.success(null);
302309
}else if (call.method.equals("createVideoRenderer")) {
303310
TextureRegistry.SurfaceTextureEntry entry = textures.createSurfaceTexture();
@@ -362,6 +369,9 @@ public void onMethodCall(MethodCall call, Result notSafeResult) {
362369
result.success(null);
363370
} else if (call.method.equals("enableSpeakerphone")) {
364371
boolean enable = call.argument("enable");
372+
if(rtcAudioManager == null ){
373+
startAudioManager();
374+
}
365375
rtcAudioManager.setSpeakerphoneOn(enable);
366376
result.success(null);
367377
} else if(call.method.equals("getDisplayMedia")) {
@@ -723,6 +733,9 @@ public String peerConnectionInit(
723733
parseMediaConstraints(constraints),
724734
observer);
725735
observer.setPeerConnection(peerConnection);
736+
if(mPeerConnectionObservers.size() == 0) {
737+
startAudioManager();
738+
}
726739
mPeerConnectionObservers.put(peerConnectionId, observer);
727740
return peerConnectionId;
728741
}
@@ -1285,6 +1298,9 @@ public void peerConnectionDispose(final String id) {
12851298
pco.dispose();
12861299
mPeerConnectionObservers.remove(id);
12871300
}
1301+
if(mPeerConnectionObservers.size() == 0) {
1302+
stopAudioManager();
1303+
}
12881304
}
12891305

12901306
public void mediaStreamRelease(final String id) {

android/src/main/java/com/cloudwebrtc/webrtc/PeerConnectionObserver.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ void close() {
8282
remoteTracks.clear();
8383
dataChannels.clear();
8484
}
85-
void dispose(){
85+
86+
void dispose() {
8687
this.close();
8788
peerConnection.dispose();
8889
eventChannel.setStreamHandler(null);

0 commit comments

Comments
 (0)
0