diff --git a/app/src/main/java/com/github/libretube/helpers/PlayerHelper.kt b/app/src/main/java/com/github/libretube/helpers/PlayerHelper.kt index 9434d6301..d9fc92cc9 100644 --- a/app/src/main/java/com/github/libretube/helpers/PlayerHelper.kt +++ b/app/src/main/java/com/github/libretube/helpers/PlayerHelper.kt @@ -52,7 +52,12 @@ object PlayerHelper { const val CONTROL_TYPE = "control_type" const val SPONSOR_HIGHLIGHT_CATEGORY = "poi_highlight" const val ROLE_FLAG_AUTO_GEN_SUBTITLE = C.ROLE_FLAG_SUPPLEMENTARY - const val MINIMUM_BUFFER_DURATION = 1000 * 10 // exo default is 50s + private const val MINIMUM_BUFFER_DURATION = 1000 * 10 // exo default is 50s + + /** + * The maximum amount of time to wait until the video starts playing: 10 minutes + */ + const val MAX_BUFFER_DELAY = 10 * 60 * 1000L val repeatModes = listOf( Player.REPEAT_MODE_OFF to R.string.repeat_mode_none, 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 8c9f34c3d..79e307f3d 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 @@ -254,6 +254,8 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions { // schedule task to save the watch position each second private var watchPositionTimer: Timer? = null + private var bufferingTimeoutTask: Runnable? = null + private val playerListener = object : Player.Listener { override fun onIsPlayingChanged(isPlaying: Boolean) { if (PlayerHelper.pipEnabled) { @@ -347,6 +349,20 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions { // finish PiP by finishing the activity activity?.finish() } + + // Buffering timeout after 10 Minutes + if (playbackState == Player.STATE_BUFFERING) { + if (bufferingTimeoutTask == null) { + bufferingTimeoutTask = Runnable { + exoPlayer.pause() + } + } + + handler.postDelayed(bufferingTimeoutTask!!, PlayerHelper.MAX_BUFFER_DELAY) + } else { + bufferingTimeoutTask?.let { handler.removeCallbacks(it) } + } + super.onPlaybackStateChanged(playbackState) }