twilio / voice-quickstart-android

Quickstart app for the Voice Android SDK
https://www.twilio.com/docs/api/voice-sdk/android/getting-started
MIT License
184 stars 140 forks source link

Cannot Switch Audio Devices #581

Closed davidnardya closed 7 months ago

davidnardya commented 7 months ago

Description

In an active call, I try to change the device between speaker and earpiece and while in the logs and debugging it looks like the device is switched, in the conversation the sound come only through the earpiece, never through the loud speaker. I have made sure I use the same instance of AudioSwitch

Steps to Reproduce

  1. Have an active call
  2. Switch device

Code

val selectedDevice: AudioDevice? = audioSwitch.selectedAudioDevice
                    val availableAudioDevices: List<AudioDevice> = audioSwitch.availableAudioDevices

                    if (selectedDevice != null) {
                        val selectedDeviceIndex = availableAudioDevices.indexOf(selectedDevice)
                        val audioDeviceNames = ArrayList<String>()
                        for (a in availableAudioDevices) {
                            audioDeviceNames.add(a.name)
                        }
                        Log.d("123321","audioDeviceNames $audioDeviceNames")
                        Log.d("123321","selectedDevice $selectedDevice")
                        AlertDialog.Builder(context)
                            .setTitle("Select Audio Device")
                            .setSingleChoiceItems(
                                audioDeviceNames.toTypedArray<CharSequence>(),
                                selectedDeviceIndex
                            ) { dialog: DialogInterface, index: Int ->
                                dialog.dismiss()
                                val selectedAudioDevice =
                                    availableAudioDevices[index]
                                Log.d("123321","selectedAudioDevice $selectedAudioDevice")
                                Log.d("123321","index $index")
                                audioSwitch.selectDevice(selectedAudioDevice)
                                Log.d("123321","audioSwitch.selectedAudioDevice ${audioSwitch.selectedAudioDevice}")
                            }.create().show()
                    }

Expected Behavior

Able to switch between devices

Actual Behavior

Sound only plays through earpiece

Reproduces How Often

Every time

Twilio Call SID(s)

CA1bcd25be4d7e68caa27e4e025f78bd9b

Logs

// Log output when the issue occurs

Versions

All relevant version information for the issue.

Voice Android SDK

audioswitch:1.1.8

OS Version

Android 12

Device Model

OnePlus 7 Pro

afalls-twilio commented 7 months ago

@davidnardya this is usually the case when audioswitch has not been activated and/or started prior to the incoming call being received. Please look at the quickstart here and here for more info.

davidnardya commented 7 months ago

I have started & activated the audioswitch exactly the way you showed here, I have debugged and really seems like I've done everything correctly. Please advise

davidnardya commented 7 months ago

Here's the activation: `override fun onConnected(call: Call) { audioSwitch.activate()

            Log.d(TAG, "Connected")
            showToast("Connected")
            activeCall = call
        }`

Also added it to this function: `fun startAudioSwitch() { /*

Here's the log: audioDevice name Earpiece audioDevice name Speakerphone audioDeviceNames [Earpiece, Speakerphone] selectedDevice Earpiece(name=Earpiece) selectedAudioDevice Speakerphone(name=Speakerphone) index 1 audioDevice name Earpiece audioDevice name Speakerphone audioSwitch.selectedAudioDevice Speakerphone(name=Speakerphone) audioDeviceNames [Earpiece, Speakerphone] selectedDevice Speakerphone(name=Speakerphone) selectedAudioDevice Earpiece(name=Earpiece) index 0 audioDevice name Earpiece audioDevice name Speakerphone audioSwitch.selectedAudioDevice Earpiece(name=Earpiece) audioDeviceNames [Earpiece, Speakerphone] selectedDevice Earpiece(name=Earpiece) selectedAudioDevice Speakerphone(name=Speakerphone) index 1 audioDevice name Earpiece audioDevice name Speakerphone audioSwitch.selectedAudioDevice Speakerphone(name=Speakerphone)

Yet still when I switch between them the audio is only played through earpiece

I tried using a BT device, so the call starts on the BT device but when I try to switch to earpiece or speaker it also doesn't work Here's the log: audioDevice name Earpiece audioDevice name Speakerphone audioDevice name JBL TUNE510BT audioDevice name Earpiece audioDevice name Speakerphone audioDeviceNames [JBL TUNE510B selectedDevice BluetoothHeadse audioDeviceNames [JBL TUNE510B selectedDevice BluetoothHeadse audioDeviceNames [JBL TUNE510B selectedDevice BluetoothHeadse selectedAudioDevice Earpiece(n index 1 audioDevice name JBL TUNE510BT audioDevice name Earpiece audioDevice name Speakerphone audioSwitch.selectedAudioDevic audioDeviceNames [JBL TUNE510B selectedDevice Earpiece(name=E selectedAudioDevice Speakerpho index 2 audioDevice name JBL TUNE510BT audioDevice name Earpiece audioDevice name Speakerphone audioSwitch.selectedAudioDevic audioDeviceNames [JBL TUNE510B selectedDevice Speakerphone(na audioDevice name Earpiece audioDevice name Speakerphone

Please advise