twilio / audioswitch

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

Audio is routing via Bluetooth but device list have Earpiece & Speaker phone only and BT option is not available #167

Open tech-ajit-mob opened 1 week ago

tech-ajit-mob commented 1 week ago

The Bluetooth icon is not showing but the audio is routing via Bluetooth.

BT- Bluetooth

  1. Bluetooth is ON and connected> Incoming call is received and user is landed on the ongoing call screen
  2. Audio is coming via Bluetooth but Bluetooth icon is not showing on the ongoing call screen instead phone icon is showing.
  3. If you tap on the phone icon, audio switch options are only phone and speaker.

To Reproduce Steps to reproduce the behavior:

  1. BT is connected and receives the call
  2. Click on the accept button
  3. Voice is routing via BT and it's working fine also you can change the mode from BT to Speaker or Phone.
  4. Disconnect BT from the notification drawer and reconnect again and working fine.
  5. Disconnect the call.
  6. BT is connected, again receives the incoming call, and clicks on the accept button
  7. User can hear the voice through BT but the Devices list shows [Earpiece(name=Earpiece), Speakerphone(name=Speakerphone)] only

Expected behavior BT options should be there in the device list.

Actual behavior The voice is transmitted through Bluetooth, but Bluetooth does not appear in the device list, preventing us from displaying the Bluetooth option in the UI.

Application Logs Steps wise Step1 to 5

Step 6 : Disconnect BT

Step 6: Reconnect BT: Working fine

Step 8: When receiving incoming calls and clicking the accept button, the audio comes through Bluetooth, but the Bluetooth option is not available in the UI:

Sometimes Logcat observation:

AudioSwitch Version

Android Device (please complete the following information):

Screenshots: Audio is coming via BT Issue

My Observation and logs based on steps There are two options to disconnect the call: from the main UI and the notification drawer. The issue typically occurs when I disconnect the call via the notification drawer but the code is same in both cases.

Code snippet related audio switch:

override fun onConnected(call: Call) {
            _audioSwitch.activate()
            mCallListener?.onConnected(call)
            updatedUserConferenceJoinedStatus(isJoined = true)
        }

VoiceCallService:

override fun onDestroy() {
        Timber.d("Service on destroy>>>>>>>>>>>>>>>>>>>>>>>>>>>ready to stop audio service")
        stopAudioService()
        disconnectCall(true)
        mCallServiceInstance = null
        super.onDestroy()
    }

Audio Switch Initialization: _audioSwitch = AudioSwitch(applicationContext, loggingEnabled = true)

tech-ajit-mob commented 13 hours ago

Hi Team, Have you had a chance to review this issue?

ocarevs commented 8 hours ago

Hi @tech-ajit-mob to clarify, in the initial steps 1-5, bluetooth is connected, but does not appear in the list of available devices, only after reconnecting the BT device it becomes listed? And then when you make a second call (while bluetooth is connected and active) then the BT device is missing in the device list again, is that correct?

ocarevs commented 8 hours ago

Are you using BluetoothHeadsetConnectionListener to see bluetooth related callbacks?