Merge pull request #2060 from Bnyro/fix-pip

fix PiP for some devices
This commit is contained in:
Bnyro 2022-11-26 08:18:50 +01:00 committed by GitHub
commit 852a3311b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -512,11 +512,7 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
super.onDestroy() super.onDestroy()
try { try {
// disable the auto PiP mode for SDK >= 32 // disable the auto PiP mode for SDK >= 32
if (SDK_INT >= Build.VERSION_CODES.S) { disableAutoPiP()
activity?.setPictureInPictureParams(
PictureInPictureParams.Builder().setAutoEnterEnabled(false).build()
)
}
saveWatchPosition() 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 // save the watch position if video isn't finished and option enabled
private fun saveWatchPosition() { private fun saveWatchPosition() {
if (!PlayerHelper.watchPositionsEnabled) return if (!PlayerHelper.watchPositionsEnabled) return
@ -848,7 +853,7 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
) { ) {
transitioning = true transitioning = true
// check whether autoplay is enabled // check whether autoplay is enabled
if (binding.player.autoplayEnabled) playNextVideo() playNextVideo()
} }
when (playbackState) { when (playbackState) {
@ -873,6 +878,7 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
query { query {
Database.watchPositionDao().insertAll(watchPosition) Database.watchPositionDao().insertAll(watchPosition)
} }
disableAutoPiP()
} }
// listen for the stop button in the notification // listen for the stop button in the notification
@ -1463,8 +1469,7 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
val backgroundModeRunning = isServiceRunning(requireContext(), BackgroundMode::class.java) val backgroundModeRunning = isServiceRunning(requireContext(), BackgroundMode::class.java)
return viewModel.isFullscreen.value == true && return exoPlayer.isPlaying && !backgroundModeRunning
(exoPlayer.isPlaying || !backgroundModeRunning)
} }
private fun isServiceRunning(context: Context, serviceClass: Class<*>): Boolean { private fun isServiceRunning(context: Context, serviceClass: Class<*>): Boolean {