8000 Bluetooth switching enabled when switching `enableSpeakerphone` value (if they are connected). #201 by Ayman-Kortobaa · Pull Request #435 · flutter-webrtc/flutter-webrtc · GitHub
[go: up one dir, main page]

Skip to content

Bluetooth switching enabled when switching enableSpeakerphone value (if they are connected). #201 #435

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10000
Original file line number Diff line number Diff line change
Expand Up @@ -352,16 +352,16 @@ private void setAudioDeviceInternal(AudioDevice device) {
public void setDefaultAudioDevice(AudioDevice defaultDevice) {
ThreadUtils.checkIsOnMainThread();
switch (defaultDevice) {
case EARPIECE:
if (hasEarpiece()) {
defaultAudioDevice = defaultDevice;
} else {
defaultAudioDevice = AudioDevice.SPEAKER_PHONE;
}
break;
case SPEAKER_PHONE:
defaultAudioDevice = defaultDevice;
break;
case EARPIECE:
if (hasEarpiece()) {
defaultAudioDevice = defaultDevice;
} else {
defaultAudioDevice = AudioDevice.SPEAKER_PHONE;
}
break;
default:
Log.e(TAG, "Invalid default audio device selection");
break;
Expand Down Expand Up @@ -408,6 +408,14 @@ public void setSpeakerphoneOn(boolean on) {
if (wasOn == on) {
return;
}
final RTCBluetoothManager.State btManagerState = bluetoothManager.getState();
final boolean isBTAvailable =
btManagerState == RTCBluetoothManager.State.SCO_CONNECTED
|| btManagerState == RTCBluetoothManager.State.SCO_CONNECTING
|| btManagerState == RTCBluetoothManager.State.HEADSET_AVAILABLE;
if(!on && isBTAvailable){
bluetoothManager.startScoAudio();
}
audioManager.setSpeakerphoneOn(on);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,12 @@ public boolean startScoAudio() {
Log.e(TAG, "BT SCO connection fails - no more attempts");
return false;
}
List<BluetoothDevice> devices = bluetoothHeadset.getConnectedDevices();
if (!devices.isEmpty()) {
bluetoothDevice = devices.get(0);
bluetoothState = State.HEADSET_AVAILABLE;
}

if (bluetoothState != State.HEADSET_AVAILABLE) {
Log.e(TAG, "BT SCO connection fails - no headset available");
return false;
Expand Down
6 changes: 4 additions & 2 deletions common/darwin/Classes/FlutterWebRTCPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -559,8 +559,10 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult) result
_speakerOn = enable.boolValue;
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord
withOptions:_speakerOn ? AVAudioSessionCategoryOptionDefaultToSpeaker : 0
error:nil];
withOptions:_speakerOn ? AVAudioSessionCategoryOptionDefaultToSpeaker
:
AVAudioSessionCategoryOptionAllowBluetooth|AVAudioSessionCategoryOptionAllowBluetoothA2DP
error:nil];
[audioSession setActive:YES error:nil];
result(nil);
#else
Expand Down
0