From a2f92d8a26a2b668c9a19b12bc2c85ccaf29035a Mon Sep 17 00:00:00 2001 From: LagradOst <11805592+LagradOst@users.noreply.github.com> Date: Fri, 4 Mar 2022 18:49:36 +0100 Subject: [PATCH] fixed video error with 0 cache size --- .../cloudstream3/ui/player/CS3IPlayer.kt | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/CS3IPlayer.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/CS3IPlayer.kt index e0b0f9ad..099b5525 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/player/CS3IPlayer.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/CS3IPlayer.kt @@ -40,7 +40,7 @@ class CS3IPlayer : IPlayer { private var isPlaying = false private var exoPlayer: ExoPlayer? = null var cacheSize = 300L * 1024L * 1024L // 300 mb - private var simpleCacheSize = 100L * 1024L * 1024L + private val simpleCacheSize : Long get() = cacheSize / 2 // idk chosen at random kinda private val seekActionTime = 30000L @@ -451,10 +451,19 @@ class CS3IPlayer : IPlayer { .setTrackSelector(trackSelector ?: getTrackSelector(context)) .setLoadControl( DefaultLoadControl.Builder() - .setTargetBufferBytes(if (cacheSize > Int.MAX_VALUE) Int.MAX_VALUE else cacheSize.toInt()) + .setTargetBufferBytes( + if(cacheSize <= 0) { + DefaultLoadControl.DEFAULT_TARGET_BUFFER_BYTES + } else { + if (cacheSize > Int.MAX_VALUE) Int.MAX_VALUE else cacheSize.toInt() + } + ) .setBufferDurationsMs( DefaultLoadControl.DEFAULT_MIN_BUFFER_MS, - ((cacheSize * 75L) / 32768L).toInt(), // 500mb = 20min + maxOf( + DefaultLoadControl.DEFAULT_MAX_BUFFER_MS, + ((cacheSize * 75L) / 32768L).toInt() + ), // 500mb = 20min DefaultLoadControl.DEFAULT_BUFFER_FOR_PLAYBACK_MS, DefaultLoadControl.DEFAULT_BUFFER_FOR_PLAYBACK_AFTER_REBUFFER_MS ).build()