I got the problem when I'm trying to make my Exoplayer work in compose I tried everything, and nothing is working, my problem is the video and audio works perfect, my IMA work perfect, but I'm not finding anything related when my Bluetooth headset is connected to the phone when i start the video why the first time it sounds in the phone and not in my headset,, This is how I set my player, the setAudioPlayer
val player = remember {
ExoPlayer.Builder(context).apply {
}.build().also { exoPlayer ->
exoPlayer.setAudioAttributes(
AudioAttributes.Builder()
.setContentType(AUDIO_CONTENT_TYPE_MOVIE)
.setUsage(C.USAGE_MEDIA)
.build(),
handleAudioFocus = true
)
exoPlayer.prepare()
playerInstance(exoPlayer)
exoPlayer.playWhenReady = true
}
}
I was expecting to have the sound on my Bluetooth headset I found this, and this is currently working to connect Bluetooth, but the volume isn't possible to control
val audioDeviceCallback: AudioDeviceCallback = object : AudioDeviceCallback() {
override fun onAudioDevicesAdded(addedDevices: Array<AudioDeviceInfo>) {
for (device in addedDevices) {
if (device.type == AudioDeviceInfo.TYPE_BLUETOOTH_A2DP ||
device.type == AudioDeviceInfo.TYPE_BLUETOOTH_SCO
) {
// El dispositivo Bluetooth se ha conectado, puedes realizar una acción aquí, como reproducir o pausar la música.
}
}
}
override fun onAudioDevicesRemoved(removedDevices: Array<AudioDeviceInfo>) {
for (device in removedDevices) {
if (device.type == AudioDeviceInfo.TYPE_BLUETOOTH_A2DP ||
device.type == AudioDeviceInfo.TYPE_BLUETOOTH_SCO
) {
// El dispositivo Bluetooth se ha desconectado, puedes realizar una acción aquí.
}
}
}
}
audioManager.registerAudioDeviceCallback(audioDeviceCallback, Handler(Looper.getMainLooper()))*/
val devices = audioManager.getDevices(AudioManager.GET_DEVICES_OUTPUTS)
for (device in devices) {
if (device.type == AudioDeviceInfo.TYPE_BLUETOOTH_A2DP ||
device.type == AudioDeviceInfo.TYPE_BLUETOOTH_SCO
) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
audioManager.setCommunicationDevice(device)
}else{
}
break
}
} ```