added default load control (#202)

This commit is contained in:
Yutatsu 2024-02-20 10:09:21 +06:00 committed by GitHub
parent a74b9e985d
commit eba774618e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -61,6 +61,7 @@ import androidx.media3.exoplayer.util.EventLogger
import androidx.media3.session.MediaSession import androidx.media3.session.MediaSession
import androidx.media3.ui.* import androidx.media3.ui.*
import androidx.media3.ui.CaptionStyleCompat.* import androidx.media3.ui.CaptionStyleCompat.*
import androidx.media3.exoplayer.DefaultLoadControl
import androidx.mediarouter.app.MediaRouteButton import androidx.mediarouter.app.MediaRouteButton
import ani.dantotsu.* import ani.dantotsu.*
import ani.dantotsu.R import ani.dantotsu.R
@ -1448,10 +1449,26 @@ class ExoplayerView : AppCompatActivity(), Player.Listener, SessionAvailabilityL
private fun buildExoplayer() { private fun buildExoplayer() {
//Player //Player
val DEFAULT_MIN_BUFFER_MS = 600000
val DEFAULT_MAX_BUFFER_MS = 600000
val BUFFER_FOR_PLAYBACK_MS = 2500
val BUFFER_FOR_PLAYBACK_AFTER_REBUFFER_MS = 5000
val loadControl = DefaultLoadControl.Builder()
.setBackBuffer(1000 * 60 * 2, true)
.setBufferDurationsMs(
DEFAULT_MIN_BUFFER_MS,
DEFAULT_MAX_BUFFER_MS,
BUFFER_FOR_PLAYBACK_MS,
BUFFER_FOR_PLAYBACK_AFTER_REBUFFER_MS
)
.build()
hideSystemBars() hideSystemBars()
exoPlayer = ExoPlayer.Builder(this) exoPlayer = ExoPlayer.Builder(this)
.setMediaSourceFactory(DefaultMediaSourceFactory(cacheFactory)) .setMediaSourceFactory(DefaultMediaSourceFactory(cacheFactory))
.setTrackSelector(trackSelector) .setTrackSelector(trackSelector)
.setLoadControl(loadControl)
.build().apply { .build().apply {
playWhenReady = true playWhenReady = true
this.playbackParameters = this@ExoplayerView.playbackParameters this.playbackParameters = this@ExoplayerView.playbackParameters