mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-13 05:40:31 +05:30
feat: Give up timer on long buffering
Stops buffering after 10 minutes
This commit is contained in:
parent
b3e10eb290
commit
7db816d612
@ -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,
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user