Merge pull request #5697 from Bnyro/master

fix: paused video autoplays when unlock screen after few minutes locked
This commit is contained in:
Bnyro 2024-03-05 18:56:44 +01:00 committed by GitHub
commit 4ead29e7c4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 2 deletions

View File

@ -41,4 +41,5 @@ object IntentData {
const val maxAudioQuality = "maxAudioQuality" const val maxAudioQuality = "maxAudioQuality"
const val audioLanguage = "audioLanguage" const val audioLanguage = "audioLanguage"
const val captionLanguage = "captionLanguage" const val captionLanguage = "captionLanguage"
const val wasIntentStopped = "wasIntentStopped"
} }

View File

@ -113,7 +113,6 @@ import com.github.libretube.util.PlayingQueue
import com.github.libretube.util.TextUtils import com.github.libretube.util.TextUtils
import com.github.libretube.util.TextUtils.toTimeInSeconds import com.github.libretube.util.TextUtils.toTimeInSeconds
import com.github.libretube.util.YoutubeHlsPlaylistParser import com.github.libretube.util.YoutubeHlsPlaylistParser
import java.util.*
import java.util.concurrent.Executors import java.util.concurrent.Executors
import kotlin.math.abs import kotlin.math.abs
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
@ -782,6 +781,11 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
) { ) {
exoPlayer.pause() exoPlayer.pause()
} }
// the app was put somewhere in the background - remember to not automatically continue
// playing on re-creation of the app
requireArguments().putBoolean(IntentData.wasIntentStopped, true)
super.onPause() super.onPause()
} }
@ -948,7 +952,11 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
initializePlayerView() initializePlayerView()
exoPlayer.playWhenReady = PlayerHelper.playAutomatically // don't continue playback when the fragment is re-created after Android killed it
val wasIntentStopped = requireArguments().getBoolean(IntentData.wasIntentStopped, false)
exoPlayer.playWhenReady = PlayerHelper.playAutomatically && !wasIntentStopped
requireArguments().putBoolean(IntentData.wasIntentStopped, false)
exoPlayer.prepare() exoPlayer.prepare()
if (binding.playerMotionLayout.progress != 1.0f) { if (binding.playerMotionLayout.progress != 1.0f) {