Don't start PiP when the video is paused

This commit is contained in:
Bnyro 2022-12-15 19:40:32 +01:00
parent 6fccb2ad16
commit 8a8ece49da

View File

@ -822,6 +822,9 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
if (isPlaying) { if (isPlaying) {
// Stop [BackgroundMode] service if it is running. // Stop [BackgroundMode] service if it is running.
BackgroundHelper.stopBackgroundPlay(requireContext()) BackgroundHelper.stopBackgroundPlay(requireContext())
if (usePiP()) activity?.setPictureInPictureParams(getPipParams())
} else {
disableAutoPiP()
} }
if (isPlaying && PlayerHelper.sponsorBlockEnabled) { if (isPlaying && PlayerHelper.sponsorBlockEnabled) {
@ -850,6 +853,9 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
playbackState == Player.STATE_ENDED playbackState == Player.STATE_ENDED
) )
// save the watch position every time the state changes
saveWatchPosition()
// check if video has ended, next video is available and autoplay is enabled. // check if video has ended, next video is available and autoplay is enabled.
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
if ( if (
@ -858,7 +864,6 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
binding.player.autoplayEnabled binding.player.autoplayEnabled
) { ) {
transitioning = true transitioning = true
// check whether autoplay is enabled
playNextVideo() playNextVideo()
} }
@ -869,12 +874,6 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
if (usePiP()) activity?.setPictureInPictureParams(getPipParams()) if (usePiP()) activity?.setPictureInPictureParams(getPipParams())
} }
// save the watch position when paused
if (playbackState == PlaybackState.STATE_PAUSED) {
saveWatchPosition()
disableAutoPiP()
}
// listen for the stop button in the notification // listen for the stop button in the notification
if (playbackState == PlaybackState.STATE_STOPPED && usePiP()) { if (playbackState == PlaybackState.STATE_STOPPED && usePiP()) {
// finish PiP by finishing the activity // finish PiP by finishing the activity
@ -1422,9 +1421,7 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
.build() .build()
private fun shouldStartPiP(): Boolean { private fun shouldStartPiP(): Boolean {
if (!PlayerHelper.pipEnabled || if (!PlayerHelper.pipEnabled || Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
exoPlayer.playbackState == PlaybackState.STATE_PAUSED
) {
return false return false
} }