From 0e23c4976d9ceead7001eecbcc29a8bc8fea9873 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sat, 26 Nov 2022 08:18:26 +0100 Subject: [PATCH] fix PiP for some devices --- .../libretube/ui/fragments/PlayerFragment.kt | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) 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 dad093817..9730a0244 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 @@ -512,11 +512,7 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions { super.onDestroy() try { // disable the auto PiP mode for SDK >= 32 - if (SDK_INT >= Build.VERSION_CODES.S) { - activity?.setPictureInPictureParams( - PictureInPictureParams.Builder().setAutoEnterEnabled(false).build() - ) - } + disableAutoPiP() saveWatchPosition() @@ -535,6 +531,15 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions { } } + private fun disableAutoPiP() { + if (SDK_INT < Build.VERSION_CODES.S) { + return + } + activity?.setPictureInPictureParams( + PictureInPictureParams.Builder().setAutoEnterEnabled(false).build() + ) + } + // save the watch position if video isn't finished and option enabled private fun saveWatchPosition() { if (!PlayerHelper.watchPositionsEnabled) return @@ -848,7 +853,7 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions { ) { transitioning = true // check whether autoplay is enabled - if (binding.player.autoplayEnabled) playNextVideo() + playNextVideo() } when (playbackState) { @@ -873,6 +878,7 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions { query { Database.watchPositionDao().insertAll(watchPosition) } + disableAutoPiP() } // listen for the stop button in the notification @@ -1463,8 +1469,7 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions { val backgroundModeRunning = isServiceRunning(requireContext(), BackgroundMode::class.java) - return viewModel.isFullscreen.value == true && - (exoPlayer.isPlaying || !backgroundModeRunning) + return exoPlayer.isPlaying && !backgroundModeRunning } private fun isServiceRunning(context: Context, serviceClass: Class<*>): Boolean {