fix(mpv): request audio focus

Closes #536
This commit is contained in:
Jarne Demeulemeester 2024-03-04 21:32:12 +01:00
parent 04c6573dfb
commit fcb13d3fc6
No known key found for this signature in database
GPG key ID: 1E5C6AFBD622E9F5
2 changed files with 12 additions and 2 deletions

View file

@ -755,7 +755,17 @@ class MPVPlayer(
playWhenReadyChangeReason = Player.PLAY_WHEN_READY_CHANGE_REASON_USER_REQUEST,
)
if (isPlayerReady) {
MPVLib.setPropertyBoolean("pause", !playWhenReady)
// Request audio focus when starting playback
if (requestAudioFocus && playWhenReady) {
val res = audioManager.requestAudioFocus(audioFocusRequest)
if (res != AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
MPVLib.setPropertyBoolean("pause", true)
} else {
MPVLib.setPropertyBoolean("pause", false)
}
} else {
MPVLib.setPropertyBoolean("pause", !playWhenReady)
}
}
}
}

View file

@ -97,7 +97,7 @@ constructor(
.build()
player = MPVPlayer(
context = application,
requestAudioFocus = false,
requestAudioFocus = true,
trackSelectionParameters = trackSelectionParameters,
seekBackIncrement = appPreferences.playerSeekBackIncrement,
seekForwardIncrement = appPreferences.playerSeekForwardIncrement,