fix: don't pause playback on duckable audio focus loss

close #592
This commit is contained in:
edde746
2026-02-28 09:22:13 +01:00
parent 08399e5d37
commit 1bb4adfcf1
2 changed files with 7 additions and 19 deletions
@@ -135,8 +135,7 @@ class ExoPlayerCore(private val activity: Activity) : Player.Listener {
exoPlayer?.pause()
}
}
AudioManager.AUDIOFOCUS_LOSS_TRANSIENT,
AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK -> {
AudioManager.AUDIOFOCUS_LOSS_TRANSIENT -> {
Log.d(TAG, "Audio focus lost transiently")
hasAudioFocus = false
if (isInitialized) {
@@ -144,6 +143,10 @@ class ExoPlayerCore(private val activity: Activity) : Player.Listener {
exoPlayer?.pause()
}
}
AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK -> {
Log.d(TAG, "Audio focus lost transiently (can duck), continuing playback")
// Don't pause — let the system handle volume ducking for notifications
}
}
}
@@ -1105,7 +1108,6 @@ class ExoPlayerCore(private val activity: Activity) : Player.Listener {
.build()
)
.setOnAudioFocusChangeListener(audioFocusChangeListener, handler)
.setWillPauseWhenDucked(true)
.build()
audioFocusRequest = focusRequest
@@ -119,21 +119,8 @@ class MpvPlayerCore(private val activity: Activity) :
}
}
AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK -> {
Log.d(TAG, "Audio focus lost transiently (can duck)")
// For video content, we pause instead of ducking
// since dialogue is typically important
hasAudioFocus = false
if (isInitialized) {
try {
val isPaused = MPVLib.getPropertyBoolean("pause")
wasPlayingBeforeFocusLoss = !isPaused
if (!isPaused) {
MPVLib.setPropertyBoolean("pause", true)
}
} catch (e: Exception) {
Log.w(TAG, "Failed to pause on duck focus loss", e)
}
}
Log.d(TAG, "Audio focus lost transiently (can duck), continuing playback")
// Don't pause — let the system handle volume ducking for notifications
}
}
}
@@ -361,7 +348,6 @@ class MpvPlayerCore(private val activity: Activity) :
.build()
)
.setOnAudioFocusChangeListener(audioFocusChangeListener, handler)
.setWillPauseWhenDucked(true)
.build()
audioFocusRequest = focusRequest