Keep screen on only while video is playing #2877

- Fixes Screen stays on when video is paused (no timeout)
This commit is contained in:
Praveen Rajput 2023-01-28 05:13:47 +05:30
parent 326df3970a
commit 6795026a94

View File

@ -172,17 +172,9 @@ internal class CustomExoPlayerView(
)
) {
updatePlayPauseButton()
updateScreenOnState()
}
}
override fun onPlaybackStateChanged(playbackState: Int) {
// keep the screen on if the video is not ended or paused
keepScreenOn = !(
listOf(Player.STATE_IDLE, Player.STATE_ENDED)
.contains(playbackState)
)
super.onPlaybackStateChanged(playbackState)
}
})
playerViewModel?.isFullscreen?.observe(viewLifecycleOwner!!) { isFullscreen ->
@ -194,6 +186,11 @@ internal class CustomExoPlayerView(
}
}
private fun updateScreenOnState() {
// keep screen on if the video is playing
keepScreenOn = player?.isPlaying == true
}
private fun updatePlayPauseButton() {
binding.playPauseBTN.setImageResource(
when {