Merge pull request #5587 from manish99verma/Give-up-timer-on-long-buffering

feat: stop loading after long unsuccessful buffering
This commit is contained in:
Bnyro 2024-02-05 16:47:13 +01:00 committed by GitHub
commit f9fa732cb4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 1 deletions

View File

@ -52,7 +52,12 @@ object PlayerHelper {
const val CONTROL_TYPE = "control_type" const val CONTROL_TYPE = "control_type"
const val SPONSOR_HIGHLIGHT_CATEGORY = "poi_highlight" const val SPONSOR_HIGHLIGHT_CATEGORY = "poi_highlight"
const val ROLE_FLAG_AUTO_GEN_SUBTITLE = C.ROLE_FLAG_SUPPLEMENTARY 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( val repeatModes = listOf(
Player.REPEAT_MODE_OFF to R.string.repeat_mode_none, Player.REPEAT_MODE_OFF to R.string.repeat_mode_none,

View File

@ -254,6 +254,8 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
// schedule task to save the watch position each second // schedule task to save the watch position each second
private var watchPositionTimer: Timer? = null private var watchPositionTimer: Timer? = null
private var bufferingTimeoutTask: Runnable? = null
private val playerListener = object : Player.Listener { private val playerListener = object : Player.Listener {
override fun onIsPlayingChanged(isPlaying: Boolean) { override fun onIsPlayingChanged(isPlaying: Boolean) {
if (PlayerHelper.pipEnabled) { if (PlayerHelper.pipEnabled) {
@ -347,6 +349,20 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
// finish PiP by finishing the activity // finish PiP by finishing the activity
activity?.finish() 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) super.onPlaybackStateChanged(playbackState)
} }