diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/AbstractPlayerFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/AbstractPlayerFragment.kt index 6489b665..64769cd9 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/player/AbstractPlayerFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/AbstractPlayerFragment.kt @@ -339,14 +339,21 @@ abstract class AbstractPlayerFragment( SubtitlesFragment.applyStyleEvent += ::onSubStyleChanged try { - context?.let { + context?.let { ctx -> val settingsManager = PreferenceManager.getDefaultSharedPreferences( - it + ctx ) - val currentPrefSize = - settingsManager.getInt(getString(R.string.video_cache_key), 300) - player.cacheSize = currentPrefSize * 1024L * 1024L + val currentPrefCacheSize = + settingsManager.getInt(getString(R.string.video_buffer_size_key), 0) + val currentPrefDiskSize = + settingsManager.getInt(getString(R.string.video_buffer_disk_key), 0) + val currentPrefBufferSec = + settingsManager.getInt(getString(R.string.video_buffer_length_key), 0) + + player.cacheSize = currentPrefCacheSize * 1024L * 1024L + player.simpleCacheSize = currentPrefDiskSize * 1024L * 1024L + player.videoBufferMs = currentPrefBufferSec * 1000L } } catch (e: Exception) { logError(e) 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 099b5525..dcfb6a0e 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 @@ -39,8 +39,9 @@ const val TAG = "CS3ExoPlayer" class CS3IPlayer : IPlayer { private var isPlaying = false private var exoPlayer: ExoPlayer? = null - var cacheSize = 300L * 1024L * 1024L // 300 mb - private val simpleCacheSize : Long get() = cacheSize / 2 // idk chosen at random kinda + var cacheSize = 0L + var simpleCacheSize = 0L + var videoBufferMs = 0L private val seekActionTime = 30000L @@ -423,6 +424,7 @@ class CS3IPlayer : IPlayer { playBackSpeed: Float, subtitleOffset: Long, cacheSize: Long, + videoBufferMs: Long, playWhenReady: Boolean = true, cacheFactory: CacheDataSource.Factory? = null, trackSelector: TrackSelector? = null, @@ -460,10 +462,11 @@ class CS3IPlayer : IPlayer { ) .setBufferDurationsMs( DefaultLoadControl.DEFAULT_MIN_BUFFER_MS, - maxOf( - DefaultLoadControl.DEFAULT_MAX_BUFFER_MS, - ((cacheSize * 75L) / 32768L).toInt() - ), // 500mb = 20min + if(videoBufferMs <= 0) { + DefaultLoadControl.DEFAULT_MAX_BUFFER_MS + } else { + videoBufferMs.toInt() + }, DefaultLoadControl.DEFAULT_BUFFER_FOR_PLAYBACK_MS, DefaultLoadControl.DEFAULT_BUFFER_FOR_PLAYBACK_AFTER_REBUFFER_MS ).build() @@ -574,6 +577,7 @@ class CS3IPlayer : IPlayer { playbackPosition, playBackSpeed, cacheSize = cacheSize, + videoBufferMs = videoBufferMs, playWhenReady = isPlaying, // this keep the current state of the player cacheFactory = cacheFactory, subtitleOffset = currentSubtitleOffset diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsFragment.kt index 8256e348..aa85c08f 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsFragment.kt @@ -209,21 +209,61 @@ class SettingsFragment : PreferenceFragmentCompat() { setPreferencesFromResource(R.xml.settings, rootKey) val settingsManager = PreferenceManager.getDefaultSharedPreferences(requireContext()) - getPref(R.string.video_cache_key)?.setOnPreferenceClickListener { - val prefNames = resources.getStringArray(R.array.video_cache_size_names) - val prefValues = resources.getIntArray(R.array.video_cache_size_values) + getPref(R.string.video_buffer_length_key)?.setOnPreferenceClickListener { + val prefNames = resources.getStringArray(R.array.video_buffer_length_names) + val prefValues = resources.getIntArray(R.array.video_buffer_length_values) val currentPrefSize = - settingsManager.getInt(getString(R.string.video_cache_key), 300) + settingsManager.getInt(getString(R.string.video_buffer_length_key), 0) - activity?.showBottomDialog( + activity?.showDialog( prefNames.toList(), prefValues.indexOf(currentPrefSize), - getString(R.string.video_cache_settings), + getString(R.string.video_buffer_length_settings), true, {}) { settingsManager.edit() - .putInt(getString(R.string.video_cache_key), prefValues[it]) + .putInt(getString(R.string.video_buffer_length_key), prefValues[it]) + .apply() + } + return@setOnPreferenceClickListener true + } + + getPref(R.string.video_buffer_size_key)?.setOnPreferenceClickListener { + val prefNames = resources.getStringArray(R.array.video_buffer_size_names) + val prefValues = resources.getIntArray(R.array.video_buffer_size_values) + + val currentPrefSize = + settingsManager.getInt(getString(R.string.video_buffer_size_key), 0) + + activity?.showDialog( + prefNames.toList(), + prefValues.indexOf(currentPrefSize), + getString(R.string.video_buffer_size_settings), + true, + {}) { + settingsManager.edit() + .putInt(getString(R.string.video_buffer_size_key), prefValues[it]) + .apply() + } + return@setOnPreferenceClickListener true + } + + getPref(R.string.video_buffer_disk_key)?.setOnPreferenceClickListener { + val prefNames = resources.getStringArray(R.array.video_buffer_size_names) + val prefValues = resources.getIntArray(R.array.video_buffer_size_values) + + val currentPrefSize = + settingsManager.getInt(getString(R.string.video_buffer_disk_key), 0) + + activity?.showDialog( + prefNames.toList(), + prefValues.indexOf(currentPrefSize), + getString(R.string.video_buffer_disk_settings), + true, + {}) { + settingsManager.edit() + .putInt(getString(R.string.video_buffer_disk_key), prefValues[it]) .apply() } return@setOnPreferenceClickListener true diff --git a/app/src/main/res/values-ar/strings.xml b/app/src/main/res/values-ar/strings.xml index dc6f7569..b50a31e5 100644 --- a/app/src/main/res/values-ar/strings.xml +++ b/app/src/main/res/values-ar/strings.xml @@ -232,7 +232,7 @@ لا تظهر مرة أخرى تحديث جودة المشاهدة المفضلة - حجم ذاكرة التخزين المؤقت للفيديو + حجم ذاكرة التخزين المؤقت للفيديو DNS فوق HTTPS مفيد لتجاوز كتل مزود خدمة الإنترنت diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 77e92e87..c98002a0 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -186,7 +186,7 @@ \n%s -> %s Épisode spécial Qualité de visionnage préférée - Taille de la mémoire cache + Taille de la mémoire cache Étendre Non-responsabilité Couleur principale diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index f8fa3592..74e8d9f8 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -269,7 +269,7 @@ Non mostrare di nuovo Aggiorna Risoluzione preferita - Dimensione cache video + Dimensione cache video DNS over HTTPS Utile per bypassare i blocchi ISP diff --git a/app/src/main/res/values-vi/strings.xml b/app/src/main/res/values-vi/strings.xml index 299d6a4a..e518f420 100644 --- a/app/src/main/res/values-vi/strings.xml +++ b/app/src/main/res/values-vi/strings.xml @@ -232,7 +232,7 @@ Không hiển thị lại Cập nhật Tự động chọn chất lượng phim - Kích thước video cache + Kích thước video cache Rất hữu ích để bỏ chặn ISP Đường dẫn tải xuống diff --git a/app/src/main/res/values/array.xml b/app/src/main/res/values/array.xml index cd73e2a8..e08c7280 100644 --- a/app/src/main/res/values/array.xml +++ b/app/src/main/res/values/array.xml @@ -56,20 +56,88 @@ 1 2 - - @string/none + + + @string/automatic + 1min + 1min 30s + 2min + 2min 30s + 3min + 3min 30s + 4min + 5min + 6min + 7min + 8min + 9min + 10min + 15min + 20min + 30min + + + + 0 + 60 + 90 + 120 + 150 + 180 + 210 + 240 + 300 + 360 + 420 + 480 + 540 + 600 + 900 + 1200 + 1800 + + + + @string/automatic + 10MB + 20MB + 30MB + 40MB + 50MB + 60MB + 70MB + 80MB + 90MB 100MB + 150MB 200MB + 250MB 300MB + 350MB 400MB + 450MB 500MB - + + 0 + 10 + 20 + 30 + 40 + 50 + 60 + 70 + 80 + 90 100 + 150 200 + 250 300 + 350 400 + 450 500 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c6f60da3..ae03e7b6 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -13,7 +13,9 @@ subtitle_settings_key subtitle_settings_chromecast_key quality_pref_key - video_cache_key + video_buffer_size_key + video_buffer_length_key + video_buffer_disk_key unknown_prerelease use_system_brightness_key swipe_enabled_key @@ -319,7 +321,11 @@ Don\'t show again Update Preferred watch quality - Video cache size + Video buffer size + Video buffer length + Video cache on disk + May cause problems on systems with low ram or storage such as Android TV devices or old phones if you set it too high + DNS over HTTPS Useful for bypassing ISP blocks diff --git a/app/src/main/res/xml/settings.xml b/app/src/main/res/xml/settings.xml index c1fec4aa..4104e6d1 100644 --- a/app/src/main/res/xml/settings.xml +++ b/app/src/main/res/xml/settings.xml @@ -20,10 +20,7 @@ android:key="@string/quality_pref_key" android:title="@string/watch_quality_pref" android:icon="@drawable/ic_baseline_hd_24" /> - + + + + + +