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,10 +755,20 @@ class MPVPlayer(
playWhenReadyChangeReason = Player.PLAY_WHEN_READY_CHANGE_REASON_USER_REQUEST, playWhenReadyChangeReason = Player.PLAY_WHEN_READY_CHANGE_REASON_USER_REQUEST,
) )
if (isPlayerReady) { if (isPlayerReady) {
// 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) MPVLib.setPropertyBoolean("pause", !playWhenReady)
} }
} }
} }
}
/** /**
* Whether playback will proceed when [.getPlaybackState] == [.STATE_READY]. * Whether playback will proceed when [.getPlaybackState] == [.STATE_READY].

View file

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