From ff6a0f113866f4f124fa05a72b6ae84145ecf336 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sun, 22 Jan 2023 19:27:08 +0100 Subject: [PATCH] Keep the screen on while playing in the offline player --- .../com/github/libretube/ui/activities/MainActivity.kt | 2 +- .../com/github/libretube/ui/fragments/PlayerFragment.kt | 5 ----- .../com/github/libretube/ui/views/CustomExoPlayerView.kt | 9 +++++++++ 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/github/libretube/ui/activities/MainActivity.kt b/app/src/main/java/com/github/libretube/ui/activities/MainActivity.kt index 12aea12ef..05f4d25e5 100644 --- a/app/src/main/java/com/github/libretube/ui/activities/MainActivity.kt +++ b/app/src/main/java/com/github/libretube/ui/activities/MainActivity.kt @@ -167,7 +167,7 @@ class MainActivity : BaseActivity() { } R.id.searchResultFragment -> { navController.popBackStack(R.id.searchFragment, true) || - navController.popBackStack() + navController.popBackStack() } else -> { navController.popBackStack() diff --git a/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt index fdd295f8a..a038814e7 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt @@ -919,11 +919,6 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions { } override fun onPlaybackStateChanged(playbackState: Int) { - exoPlayerView.keepScreenOn = !( - playbackState == Player.STATE_IDLE || - playbackState == Player.STATE_ENDED - ) - // save the watch position to the database // only called when the position is unequal to 0, otherwise it would become reset // before the player can seek to the saved position from videos of the queue 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 c740b5d78..568b5ef5d 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 @@ -177,6 +177,15 @@ internal class CustomExoPlayerView( updatePlayPauseButton() } } + + 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 ->