opentok-android-sdk-samples icon indicating copy to clipboard operation
opentok-android-sdk-samples copied to clipboard

Issue with changing AudioDeviceManager output device

Open tokaaliamin opened this issue 4 years ago • 4 comments

I'm facing an issue on com.opentok.android:opentok-android-sdk:2.18.1 When I modify AudioDeviceManager output device to use Handset Here's my code:

@AfterPermissionGranted(Constants.RC_AUDIO_PERM)
    private fun requestPermissions() {
        if (EasyPermissions.hasPermissions(this, *permissions)) {
            mSession = Session.Builder(this, API_KEY, SESSION_ID)
                .sessionOptions(object : Session.SessionOptions() {
                    override fun useTextureViews(): Boolean {
                        return true
                    }

                }).build()
            AudioDeviceManager.getAudioDevice().outputMode = BaseAudioDevice.OutputMode.Handset
            mSession?.setSessionListener(this)
            mSession?.connect(TOKEN_2)
        } else {
            EasyPermissions.requestPermissions(
                this,
                permissionMessage,
                requestCode,
                *permissions
            )
        }
    }

I also tried setting it in onStreamCreated method but it didn't do anything either! I need to change the output device throughout the session too

Originally posted by @tokaaliamien in https://github.com/opentok/opentok-android-sdk-samples/issues/176#issuecomment-767004150

tokaaliamin avatar Jan 26 '21 12:01 tokaaliamin

I actually found a simple work around, using Android's AudioManager class solved both problems

val audioManager = getSystemService(Context.AUDIO_SERVICE) as AudioManager
audioManager.mode = AudioManager.MODE_IN_COMMUNICATION
audioManager.isSpeakerphoneOn = isSpeakerOn
audioManager.isBluetoothScoOn = !isSpeakerOn

And that's it

tokaaliamin avatar Jan 27 '21 16:01 tokaaliamin

Hey @tokaaliamien , I'm having issue with AudioDeviceManager as well, basically the bluetooth headset stays connected even when the session is disconnected. I'm also seeing memory leak issue with that class holding the context in memory. Did you experience anything like that?

adrienrx avatar Jan 28 '21 08:01 adrienrx

Hi @adrienrx @tokaaliamien, I also have serious issues with the Bluetooth headphones - after connecting them and a call is being performed, the sound sometimes is not being heard anymore at all in the Bluetooth headphones, even if they stay connected.

georgeRaduNeusoft avatar Jun 07 '21 07:06 georgeRaduNeusoft

There is definitely something wrong in the SDK but I can't find the exact issue yet. We are setting the outputMode to Handset in onStreamCreated() but under some circumstances the actual call will go through the phone instead of the bluetooth headphones. All other application or systems sounds are going through the headphones, it's just the phone that is played through the ear piece. I noticed that this happens almost always when you start our application with bluetooth disabled, then you enable it and start call => doesn't work correctly. But restarting the app with bluetooth enabled works fine. It seems like if OpenTok only scans for bluetooth once.

I looked into the private AudioManager.outputType and it's EAR_PIECE in first scenario (bluetooth enabled while app is running) and it's BLUETOOTH if it's working correctly. In both cases the Bluetooth headset is actually connected and working correctly, only OpenTok thinks that bluetooth is disconnected (checking bluetooth state through OpenTok returns Disconnected).

DanielNovak avatar Sep 09 '21 05:09 DanielNovak