From 6795026a947523a0cd26cc59bb578dc659f0062a Mon Sep 17 00:00:00 2001 From: Praveen Rajput Date: Sat, 28 Jan 2023 05:13:47 +0530 Subject: [PATCH 1/2] Keep screen on only while video is playing #2877 - Fixes Screen stays on when video is paused (no timeout) --- .../libretube/ui/views/CustomExoPlayerView.kt | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt b/app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt index 54377e6ff6..79b5d531e5 100644 --- a/app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt +++ b/app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt @@ -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 { From 2fcaea9ad6cbcece193584d3c1426e6fa19c2fd5 Mon Sep 17 00:00:00 2001 From: Praveen Rajput Date: Sun, 29 Jan 2023 11:08:33 +0530 Subject: [PATCH 2/2] Refactors keepScreenOn method --- .../com/github/libretube/ui/views/CustomExoPlayerView.kt | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt b/app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt index 79b5d531e5..ef13c0e5ae 100644 --- a/app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt +++ b/app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt @@ -172,7 +172,9 @@ internal class CustomExoPlayerView( ) ) { updatePlayPauseButton() - updateScreenOnState() + + // keep screen on if the video is playing + keepScreenOn = player.isPlaying == true } } }) @@ -186,11 +188,6 @@ 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 {