File tree 3 files changed +25
-9
lines changed
android/src/main/java/com/cloudwebrtc/webrtc/utils
3 files changed +25
-9
lines changed Original file line number Diff line number Diff line change @@ -352,16 +352,16 @@ private void setAudioDeviceInternal(AudioDevice device) {
352
352
public void setDefaultAudioDevice (AudioDevice defaultDevice ) {
353
353
ThreadUtils .checkIsOnMainThread ();
354
354
switch (defaultDevice ) {
355
+ case EARPIECE :
356
+ if (hasEarpiece ()) {
357
+ defaultAudioDevice = defaultDevice ;
358
+ } else {
359
+ defaultAudioDevice = AudioDevice .SPEAKER_PHONE ;
360
+ }
361
+ break ;
355
362
case SPEAKER_PHONE :
356
363
defaultAudioDevice = defaultDevice ;
357
364
break ;
358
- case EARPIECE :
359
- if (hasEarpiece ()) {
360
- defaultAudioDevice = defaultDevice ;
361
- } else {
362
- defaultAudioDevice = AudioDevice .SPEAKER_PHONE ;
363
- }
364
- break ;
365
365
default :
366
366
Log .e (TAG , "Invalid default audio device selection" );
367
367
break ;
@@ -408,6 +408,14 @@ public void setSpeakerphoneOn(boolean on) {
408
408
if (wasOn == on ) {
409
409
return
8000
;
410
410
}
411
+ final RTCBluetoothManager .State btManagerState = bluetoothManager .getState ();
412
+ final boolean isBTAvailable =
413
+ btManagerState == RTCBluetoothManager .State .SCO_CONNECTED
414
+ || btManagerState == RTCBluetoothManager .State .SCO_CONNECTING
415
+ || btManagerState == RTCBluetoothManager .State .HEADSET_AVAILABLE ;
416
+ if (!on && isBTAvailable ){
417
+ bluetoothManager .startScoAudio ();
418
+ }
411
419
audioManager .setSpeakerphoneOn (on );
412
420
}
413
421
Original file line number Diff line number Diff line change @@ -324,6 +324,12 @@ public boolean startScoAudio() {
324
324
Log .e (TAG , "BT SCO connection fails - no more attempts" );
325
325
return false ;
326
326
}
327
+ List <BluetoothDevice > devices = bluetoothHeadset .getConnectedDevices ();
328
+ if (!devices .isEmpty ()) {
329
+ bluetoothDevice = devices .get (0 );
330
+ bluetoothState = State .HEADSET_AVAILABLE ;
331
+ }
332
+
327
333
if (bluetoothState != State .HEADSET_AVAILABLE ) {
328
334
Log .e (TAG , "BT SCO connection fails - no headset available" );
329
335
return false ;
Original file line number Diff line number Diff line change @@ -559,8 +559,10 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult) result
559
559
_speakerOn = enable.boolValue ;
560
560
AVAudioSession *audioSession = [AVAudioSession sharedInstance ];
561
561
[audioSession setCategory: AVAudioSessionCategoryPlayAndRecord
562
- withOptions: _speakerOn ? AVAudioSessionCategoryOptionDefaultToSpeaker : 0
563
- error: nil ];
562
+ withOptions: _speakerOn ? AVAudioSessionCategoryOptionDefaultToSpeaker
563
+ :
564
+ AVAudioSessionCategoryOptionAllowBluetooth|AVAudioSessionCategoryOptionAllowBluetoothA2DP
565
+ error: nil ];
564
566
[audioSession setActive: YES error: nil ];
565
567
result (nil );
566
568
#else
You can’t perform that action at this time.
0 commit comments