fix: allow pausing when buffer is less than min buffer

Fixes a regression in 42d081f04e132bc4ff5dbf408c596bd1f6927992. The player should pause when it is unable to play, as long as the buffered time is less than the minimum buffer needed for playing.
This commit is contained in:
FineFindus 2023-09-21 10:11:05 +02:00
parent 98334270de
commit adb051e24f
No known key found for this signature in database
GPG Key ID: 64873EE210FF8E6B
2 changed files with 4 additions and 2 deletions

View File

@ -1,6 +1,7 @@
package com.github.libretube.extensions
import androidx.media3.common.Player
import com.github.libretube.helpers.PlayerHelper
fun Player.togglePlayPauseState() {
when {
@ -13,7 +14,7 @@ fun Player.togglePlayPauseState() {
seekTo(0)
}
!isPlaying && totalBufferedDuration > 0 -> play()
!isPlaying && totalBufferedDuration > PlayerHelper.MINIMUM_BUFFER_DURATION -> play()
else -> pause()
}
}

View File

@ -46,6 +46,7 @@ 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
/**
* A list of all categories that are not disabled by default
@ -437,7 +438,7 @@ object PlayerHelper {
// cache the last three minutes
.setBackBuffer(1000 * 60 * 3, true)
.setBufferDurationsMs(
1000 * 10, // exo default is 50s
MINIMUM_BUFFER_DURATION,
bufferingGoal,
DefaultLoadControl.DEFAULT_BUFFER_FOR_PLAYBACK_MS,
DefaultLoadControl.DEFAULT_BUFFER_FOR_PLAYBACK_AFTER_REBUFFER_MS