1
votes

I make a player that should play only through headphones (wired or Bluetooth), but not through the speaker. If you turn off the headphones during playback, the player automatically pauses. When (Bluetooth) headphones are connected back and I get the ACTION_AUDIO_STATE_CHANGED event, I resume playback. But for a few seconds, the sound goes through the builtin speaker and only then goes to the headphones. I think to fix this by setting the device to output. I can get the device id from AudioManager. But how to pass it to OpenSL ES?

Or maybe there is a way to completely prevent playback through the builtin speaker?

Or another way to solve this problem?

P.S. Santa, where is you when you are so needed? Help me, please!

1
Did you find a way to make opensl play through desired device?rpattabi

1 Answers

0
votes

Maybe you could listen to this other type of events with a BroadcastReceiver:

BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED -> {
            state = intent.getIntExtra(BluetoothA2dp.EXTRA_STATE, -1)
            when (state) {
                BluetoothA2dp.STATE_CONNECTED -> {
                    // Do something
                }
                BluetoothA2dp.STATE_DISCONNECTED -> {
                    // Do something else
                }
            }
        }