opentok-android-sdk-samples
opentok-android-sdk-samples copied to clipboard
Issue with changing AudioDeviceManager output device
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
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
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?
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.
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).