From 0533d54bbd0bc3adb79d554e3aadfc2270f054f1 Mon Sep 17 00:00:00 2001 From: Niels van Velzen Date: Sat, 28 Dec 2024 22:51:09 +0100 Subject: [PATCH] Enable audio focus for music playback --- playback/media3/exoplayer/src/main/kotlin/ExoPlayerBackend.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/playback/media3/exoplayer/src/main/kotlin/ExoPlayerBackend.kt b/playback/media3/exoplayer/src/main/kotlin/ExoPlayerBackend.kt index 85cd218e4e..0f0343601a 100644 --- a/playback/media3/exoplayer/src/main/kotlin/ExoPlayerBackend.kt +++ b/playback/media3/exoplayer/src/main/kotlin/ExoPlayerBackend.kt @@ -5,6 +5,7 @@ import android.content.Context import android.view.ViewGroup import androidx.annotation.OptIn import androidx.core.content.getSystemService +import androidx.media3.common.AudioAttributes import androidx.media3.common.C import androidx.media3.common.MediaItem import androidx.media3.common.PlaybackException @@ -101,6 +102,9 @@ class ExoPlayerBackend( setConstantBitrateSeekingAlwaysEnabled(true) } )) + .setAudioAttributes(AudioAttributes.Builder().apply { + setUsage(C.USAGE_MEDIA) + }.build(), true) .setPauseAtEndOfMediaItems(true) .build() .also { player ->