twilio / audioswitch

An Android audio management library for real-time communication apps.
Apache License 2.0
163 stars 50 forks source link

Selected device is not showing in the audio switch list #77

Closed Monika-Paliwal closed 3 years ago

Monika-Paliwal commented 3 years ago

Describe the bug I am facing one issue when we make a call for the second time with an already connected Bluetooth device. So that time I am not getting the Bluetooth device option on a list it's always showing only two options earpiece and speaker

To Reproduce Steps to reproduce the behavior:

Launch the video app. The Bluetooth is already connected with the device, the first call is working fine, but when we make a call a second time with an already connected Bluetooth device so that time in the audio switch list, it's showing only two options Earpiece and Speakerphone.

Expected behavior When a wired headset or Bluetooth is connected it should show the option in an audio switch list.

Actual behavior After Bluetooth is Connected, it changes the audio route automatically from Bluetooth headset to speakerphone or speakerphone to Bluetooth headset/wired headset.

Android Device

Device: Samsung A30 5F API Version: 29 Version 10

Version: 1.0.1 Earlier I was using this snippet but it was not getting the Bluetooth headset in the audio devices list. it's sometimes showing only the earpiece or speaker. AudioSwitch audioSwitch = new AudioSwitch(getApplicationContext()); audioSwitch.start((audioDevices, audioDevice) -> { List availableAudioDevices = audioSwitch.getAvailableAudioDevices(); int selectedDeviceIndex = availableAudioDevices.indexOf(new AudioDevice.BluetoothHeadset("")); if (selectedDeviceIndex < -1) { audioSwitch.selectDevice(availableAudioDevices.get(selectedDeviceIndex)); } return Unit.INSTANCE; }); After I got the response on that link https://github.com/twilio/audioswitch/issues/45 then tried this snippet but still not working this solution for me. AudioSwitch audioSwitch = new AudioSwitch(getApplicationContext()); audioSwitch.start((audioDevices, audioDevice) -> { for(AudioDevice device: audioDevices) { if(device instanceof AudioDevice.BluetoothHeadset) { audioSwitch.selectDevice(device); } } return Unit.INSTANCE; }); But I need to manage all the condition So I added this snippet AudioSwitch twiAudioSwitch = new AudioSwitch(getApplicationContext()); twiAudioSwitch.start((audioDevices, audioDevice) -> { for(AudioDevice device: audioDevices) { if(device instanceof AudioDevice.BluetoothHeadset) { twiAudioSwitch.selectDevice(device); } else if (device instanceof AudioDevice.WiredHeadset) { twiAudioSwitch.selectDevice(device); } else if (device instanceof AudioDevice.Speakerphone) { twiAudioSwitch.selectDevice(device); } } return Unit.INSTANCE; }); I added the above-mentioned code but it's not working in the second call because the Bluetooth headset is already connected So that time Bluetooth headset option is not showing in the audio device list it always shows an earpiece and speakerphone in the list.

Alton09 commented 3 years ago

Hi @Monika-Paliwal ! It looks like you are using an old workaround to control the preferred AudioDevice order. This is no longer needed since the feature is now supported as of 1.1.0. Please use this feature and remove the logic within your AudioDeviceChangeListener lambda to select a device. See this KDoc to learn how to pass a preferredDeviceList to the AudioSwitch constructor.

Please give this a try first and see if it resolves your issue with the BT headset not being available during a second call. Thanks!

Alton09 commented 3 years ago

Closing this issue for now. Please feel free to reach back out if you encounter any other issues. Thanks!

Monika-Paliwal commented 3 years ago

@Alton09 Sorry for the late reply and the solution is working for me. thanks for the solution. but I am facing one issue that is when a call comes on the Android device when it connected with Bluetooth, then the call rings on Bluetooth only, and on the mobile phone, it is not ringing. And some of the users are facing the video/ audio quality issue after implementing the library.
Can you please suggest, how to handle this issue?

Alton09 commented 3 years ago

Hi @Monika-Paliwal . I'm glad to hear that the solution I provided helped! Regarding the other problem you are facing, can you please create a separate issue and follow the steps outlined in the issue template (i.e. logs, reproduction steps, device/API version)? Thanks!