added video cache

This commit is contained in:
LagradOst 2022-02-01 21:05:16 +01:00
parent 47745ec9e3
commit c35364fb82
7 changed files with 107 additions and 73 deletions

View file

@ -18,6 +18,7 @@ import androidx.annotation.StringRes
import androidx.core.view.isVisible import androidx.core.view.isVisible
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.media.session.MediaButtonReceiver import androidx.media.session.MediaButtonReceiver
import androidx.preference.PreferenceManager
import androidx.vectordrawable.graphics.drawable.AnimatedVectorDrawableCompat import androidx.vectordrawable.graphics.drawable.AnimatedVectorDrawableCompat
import com.google.android.exoplayer2.ExoPlayer import com.google.android.exoplayer2.ExoPlayer
import com.google.android.exoplayer2.PlaybackException import com.google.android.exoplayer2.PlaybackException
@ -332,6 +333,17 @@ abstract class AbstractPlayerFragment(
subStyle = SubtitlesFragment.getCurrentSavedStyle() subStyle = SubtitlesFragment.getCurrentSavedStyle()
player.initSubtitles(subView, subtitle_holder, subStyle) player.initSubtitles(subView, subtitle_holder, subStyle)
SubtitlesFragment.applyStyleEvent += ::onSubStyleChanged SubtitlesFragment.applyStyleEvent += ::onSubStyleChanged
try {
val settingsManager = PreferenceManager.getDefaultSharedPreferences(context)
val currentPrefSize =
settingsManager.getInt(getString(R.string.video_cache_key), 300)
player.cacheSize = currentPrefSize * 1024L * 1024L
} catch (e : Exception) {
logError(e)
}
} }
/*context?.let { ctx -> /*context?.let { ctx ->

View file

@ -37,11 +37,11 @@ import javax.net.ssl.SSLSession
const val TAG = "CS3ExoPlayer" const val TAG = "CS3ExoPlayer"
/** Cache */ /** Cache */
private const val cacheSize = 300L * 1024L * 1024L // 300 mb TODO MAKE SETTING
class CS3IPlayer : IPlayer { class CS3IPlayer : IPlayer {
private var isPlaying = false private var isPlaying = false
private var exoPlayer: ExoPlayer? = null private var exoPlayer: ExoPlayer? = null
var cacheSize = 300L * 1024L * 1024L // 300 mb
private val seekActionTime = 30000L private val seekActionTime = 30000L

View file

@ -197,6 +197,28 @@ class SettingsFragment : PreferenceFragmentCompat() {
val preferedMediaTypePreference = findPreference<Preference>(getString(R.string.prefer_media_type_key))!! val preferedMediaTypePreference = findPreference<Preference>(getString(R.string.prefer_media_type_key))!!
val appThemePreference = findPreference<Preference>(getString(R.string.app_theme_key))!! val appThemePreference = findPreference<Preference>(getString(R.string.app_theme_key))!!
val subPreference = findPreference<Preference>(getString(R.string.subtitle_settings_key))!! val subPreference = findPreference<Preference>(getString(R.string.subtitle_settings_key))!!
val videoCachePreference = findPreference<Preference>(getString(R.string.video_cache_key))!!
videoCachePreference.setOnPreferenceClickListener {
val prefNames = resources.getStringArray(R.array.video_cache_size_names)
val prefValues = resources.getIntArray(R.array.video_cache_size_values)
val settingsManager = PreferenceManager.getDefaultSharedPreferences(context)
val currentPrefSize =
settingsManager.getInt(getString(R.string.video_cache_key), 300)
activity?.showBottomDialog(
prefNames.toList(),
prefValues.indexOf(currentPrefSize),
getString(R.string.video_cache_settings),
true,
{}) {
settingsManager.edit()
.putInt(getString(R.string.video_cache_key), prefValues[it])
.apply()
}
return@setOnPreferenceClickListener true
}
subPreference.setOnPreferenceClickListener { subPreference.setOnPreferenceClickListener {
SubtitlesFragment.push(activity, false) SubtitlesFragment.push(activity, false)

View file

@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#FFFFFF"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M2,20h20v-4L2,16v4zM4,17h2v2L4,19v-2zM2,4v4h20L22,4L2,4zM6,7L4,7L4,5h2v2zM2,14h20v-4L2,10v4zM4,11h2v2L4,13v-2z"/>
</vector>

View file

@ -56,6 +56,22 @@
<item>1</item> <item>1</item>
<item>2</item> <item>2</item>
</array> </array>
<array name="video_cache_size_names">
<item>@string/none</item>
<item>100MB</item>
<item>200MB</item>
<item>300MB</item>
<item>400MB</item>
<item>500MB</item>
</array>
<array name="video_cache_size_values">
<item>0</item>
<item>100</item>
<item>200</item>
<item>300</item>
<item>400</item>
<item>500</item>
</array>
<array name="episode_long_click_options"> <array name="episode_long_click_options">
<item>@string/episode_action_chomecast_episode</item> <item>@string/episode_action_chomecast_episode</item>

View file

@ -12,6 +12,7 @@
<string name="benene_count" translatable="false">benene_count</string> <string name="benene_count" translatable="false">benene_count</string>
<string name="subtitle_settings_key" translatable="false">subtitle_settings_key</string> <string name="subtitle_settings_key" translatable="false">subtitle_settings_key</string>
<string name="quality_pref_key" translatable="false">quality_pref_key</string> <string name="quality_pref_key" translatable="false">quality_pref_key</string>
<string name="video_cache_key" translatable="false">video_cache_key</string>
<string name="prerelease_commit_hash" translatable="false">unknown_prerelease</string> <string name="prerelease_commit_hash" translatable="false">unknown_prerelease</string>
<string name="use_system_brightness_key" translatable="false">use_system_brightness_key</string> <string name="use_system_brightness_key" translatable="false">use_system_brightness_key</string>
<string name="swipe_enabled_key" translatable="false">swipe_enabled_key</string> <string name="swipe_enabled_key" translatable="false">swipe_enabled_key</string>
@ -296,6 +297,7 @@
<string name="dont_show_again">Don\'t show again</string> <string name="dont_show_again">Don\'t show again</string>
<string name="update">Update</string> <string name="update">Update</string>
<string name="watch_quality_pref">Preferred watch quality</string> <string name="watch_quality_pref">Preferred watch quality</string>
<string name="video_cache_settings">Video cache size</string>
<string name="dns_pref">DNS over HTTPS</string> <string name="dns_pref">DNS over HTTPS</string>
<string name="dns_pref_summary">Useful for bypassing ISP blocks</string> <string name="dns_pref_summary">Useful for bypassing ISP blocks</string>

View file

@ -5,68 +5,62 @@
<PreferenceCategory <PreferenceCategory
android:key="video" android:key="video"
android:title="Player" android:title="Player"
app:isPreferenceVisible="true" app:isPreferenceVisible="true">
>
<Preference <Preference
android:key="@string/subtitle_settings_key" android:key="@string/subtitle_settings_key"
android:title="@string/player_subtitles_settings" android:title="@string/player_subtitles_settings"
android:icon="@drawable/ic_outline_subtitles_24" android:icon="@drawable/ic_outline_subtitles_24"
app:summary="@string/player_subtitles_settings_des"> app:summary="@string/player_subtitles_settings_des" />
</Preference>
<Preference <Preference
android:key="@string/quality_pref_key" android:key="@string/quality_pref_key"
android:title="@string/watch_quality_pref" android:title="@string/watch_quality_pref"
android:icon="@drawable/ic_baseline_hd_24"> android:icon="@drawable/ic_baseline_hd_24" />
</Preference> <Preference
android:key="@string/video_cache_key"
android:title="@string/video_cache_settings"
android:icon="@drawable/ic_baseline_storage_24" />
<SwitchPreference <SwitchPreference
android:icon="@drawable/ic_baseline_picture_in_picture_alt_24" android:icon="@drawable/ic_baseline_picture_in_picture_alt_24"
app:key="@string/pip_enabled_key" app:key="@string/pip_enabled_key"
android:title="@string/picture_in_picture" android:title="@string/picture_in_picture"
android:summary="@string/picture_in_picture_des" android:summary="@string/picture_in_picture_des"
app:defaultValue="true" app:defaultValue="true" />
/>
<SwitchPreference <SwitchPreference
android:icon="@drawable/ic_baseline_aspect_ratio_24" android:icon="@drawable/ic_baseline_aspect_ratio_24"
app:key="@string/player_resize_enabled_key" app:key="@string/player_resize_enabled_key"
android:title="@string/player_size_settings" android:title="@string/player_size_settings"
android:summary="@string/player_size_settings_des" android:summary="@string/player_size_settings_des"
app:defaultValue="true" app:defaultValue="true" />
/>
<SwitchPreference <SwitchPreference
android:icon="@drawable/ic_baseline_speed_24" android:icon="@drawable/ic_baseline_speed_24"
app:key="@string/playback_speed_enabled_key" app:key="@string/playback_speed_enabled_key"
android:title="@string/eigengraumode_settings" android:title="@string/eigengraumode_settings"
android:summary="@string/eigengraumode_settings_des" android:summary="@string/eigengraumode_settings_des"
app:defaultValue="false" app:defaultValue="false" />
/>
<SwitchPreference <SwitchPreference
android:icon="@drawable/ic_baseline_ondemand_video_24" android:icon="@drawable/ic_baseline_ondemand_video_24"
app:key="@string/swipe_enabled_key" app:key="@string/swipe_enabled_key"
android:title="@string/swipe_to_seek_settings" android:title="@string/swipe_to_seek_settings"
android:summary="@string/swipe_to_seek_settings_des" android:summary="@string/swipe_to_seek_settings_des"
app:defaultValue="true" app:defaultValue="true" />
/>
<SwitchPreference <SwitchPreference
android:icon="@drawable/ic_baseline_ondemand_video_24" android:icon="@drawable/ic_baseline_ondemand_video_24"
app:key="@string/swipe_vertical_enabled_key" app:key="@string/swipe_vertical_enabled_key"
android:title="@string/swipe_to_change_settings" android:title="@string/swipe_to_change_settings"
android:summary="@string/swipe_to_change_settings_des" android:summary="@string/swipe_to_change_settings_des"
app:defaultValue="true" app:defaultValue="true" />
/>
<SwitchPreference <SwitchPreference
android:icon="@drawable/ic_baseline_touch_app_24" android:icon="@drawable/ic_baseline_touch_app_24"
app:key="@string/double_tap_enabled_key" app:key="@string/double_tap_enabled_key"
android:title="@string/double_tap_to_seek_settings" android:title="@string/double_tap_to_seek_settings"
android:summary="@string/double_tap_to_seek_settings_des" android:summary="@string/double_tap_to_seek_settings_des"
app:defaultValue="false" app:defaultValue="false" />
/>
<SwitchPreference <SwitchPreference
android:icon="@drawable/netflix_pause" android:icon="@drawable/netflix_pause"
app:key="@string/double_tap_pause_enabled_key" app:key="@string/double_tap_pause_enabled_key"
android:title="@string/double_tap_to_pause_settings" android:title="@string/double_tap_to_pause_settings"
android:summary="@string/double_tap_to_pause_settings_des" android:summary="@string/double_tap_to_pause_settings_des"
app:defaultValue="false" app:defaultValue="false" />
/>
<!-- <!--
<SwitchPreference <SwitchPreference
android:icon="@drawable/ic_baseline_brightness_7_24" android:icon="@drawable/ic_baseline_brightness_7_24"
@ -80,28 +74,23 @@
<PreferenceCategory <PreferenceCategory
android:key="general" android:key="general"
android:title="@string/general" android:title="@string/general"
app:isPreferenceVisible="true" app:isPreferenceVisible="true">
>
<Preference <Preference
android:icon="@drawable/ic_baseline_language_24" android:icon="@drawable/ic_baseline_language_24"
android:key="@string/provider_lang_key" android:key="@string/provider_lang_key"
android:title="@string/provider_lang_settings"> android:title="@string/provider_lang_settings" />
</Preference>
<Preference <Preference
android:key="@string/locale_key" android:key="@string/locale_key"
android:title="@string/app_language" android:title="@string/app_language"
android:icon="@drawable/ic_baseline_language_24"> android:icon="@drawable/ic_baseline_language_24" />
</Preference>
<Preference <Preference
android:key="@string/prefer_media_type_key" android:key="@string/prefer_media_type_key"
android:title="@string/preferred_media_settings" android:title="@string/preferred_media_settings"
android:icon="@drawable/ic_baseline_play_arrow_24"> android:icon="@drawable/ic_baseline_play_arrow_24" />
</Preference>
<Preference <Preference
android:key="@string/display_sub_key" android:key="@string/display_sub_key"
android:title="@string/display_subbed_dubbed_settings" android:title="@string/display_subbed_dubbed_settings"
android:icon="@drawable/ic_outline_voice_over_off_24"> android:icon="@drawable/ic_outline_voice_over_off_24" />
</Preference>
<SwitchPreference <SwitchPreference
android:key="@string/show_fillers_key" android:key="@string/show_fillers_key"
android:icon="@drawable/ic_baseline_skip_next_24" android:icon="@drawable/ic_baseline_skip_next_24"
@ -111,53 +100,44 @@
android:key="@string/dns_key" android:key="@string/dns_key"
android:title="@string/dns_pref" android:title="@string/dns_pref"
android:summary="@string/dns_pref_summary" android:summary="@string/dns_pref_summary"
android:icon="@drawable/ic_baseline_dns_24"> android:icon="@drawable/ic_baseline_dns_24" />
</Preference>
<Preference <Preference
android:key="@string/download_path_key" android:key="@string/download_path_key"
android:title="@string/download_path_pref" android:title="@string/download_path_pref"
android:icon="@drawable/netflix_download"> android:icon="@drawable/netflix_download" />
</Preference>
<Preference <Preference
android:icon="@drawable/ic_baseline_tv_24" android:icon="@drawable/ic_baseline_tv_24"
android:key="@string/app_layout_key" android:key="@string/app_layout_key"
android:title="@string/app_layout"> android:title="@string/app_layout" />
</Preference>
<Preference <Preference
android:icon="@drawable/ic_baseline_color_lens_24" android:icon="@drawable/ic_baseline_color_lens_24"
android:key="@string/primary_color_key" android:key="@string/primary_color_key"
android:title="@string/primary_color_settings"> android:title="@string/primary_color_settings" />
</Preference>
<Preference <Preference
android:icon="@drawable/ic_baseline_color_lens_24" android:icon="@drawable/ic_baseline_color_lens_24"
android:key="@string/app_theme_key" android:key="@string/app_theme_key"
android:title="@string/app_theme_settings"> android:title="@string/app_theme_settings" />
</Preference>
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory <PreferenceCategory
android:key="search" android:key="search"
android:title="@string/search" android:title="@string/search"
app:isPreferenceVisible="true" app:isPreferenceVisible="true">
>
<SwitchPreference <SwitchPreference
android:icon="@drawable/search_icon" android:icon="@drawable/search_icon"
app:key="advanced_search" app:key="advanced_search"
android:title="@string/advanced_search" android:title="@string/advanced_search"
android:summary="@string/advanced_search_des" android:summary="@string/advanced_search_des"
app:defaultValue="true" app:defaultValue="true" />
/>
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory <PreferenceCategory
android:key="info" android:key="info"
android:title="@string/settings_info" android:title="@string/settings_info"
app:isPreferenceVisible="true" app:isPreferenceVisible="true">
>
<Preference <Preference
android:key="@string/legal_notice_key" android:key="@string/legal_notice_key"
android:title="@string/legal_notice" android:title="@string/legal_notice"
android:icon="@drawable/ic_baseline_warning_24"> android:icon="@drawable/ic_baseline_warning_24" />
</Preference>
<SwitchPreference <SwitchPreference
android:key="acra.disable" android:key="acra.disable"
@ -171,37 +151,33 @@
android:title="@string/updates_settings" android:title="@string/updates_settings"
android:summary="@string/updates_settings_des" android:summary="@string/updates_settings_des"
app:defaultValue="true" app:defaultValue="true"
android:icon="@drawable/ic_baseline_notifications_active_24" android:icon="@drawable/ic_baseline_notifications_active_24" />
/>
<SwitchPreference <SwitchPreference
app:key="@string/prerelease_update_key" app:key="@string/prerelease_update_key"
android:title="@string/uprereleases_settings" android:title="@string/uprereleases_settings"
android:summary="@string/uprereleases_settings_des" android:summary="@string/uprereleases_settings_des"
app:defaultValue="false" app:defaultValue="false"
android:icon="@drawable/ic_baseline_developer_mode_24" android:icon="@drawable/ic_baseline_developer_mode_24" />
/>
<Preference <Preference
android:title="@string/check_for_update" android:title="@string/check_for_update"
app:summary="@string/app_version" app:summary="@string/app_version"
app:key="@string/manual_check_update_key" app:key="@string/manual_check_update_key"
app:icon="@drawable/ic_baseline_system_update_24" app:icon="@drawable/ic_baseline_system_update_24" />
/>
<Preference <Preference
android:key="@string/mal_key" android:key="@string/mal_key"
android:icon="@drawable/mal_logo"> android:icon="@drawable/mal_logo" />
</Preference>
<Preference <Preference
android:key="@string/anilist_key" android:key="@string/anilist_key"
android:icon="@drawable/ic_anilist_icon"> android:icon="@drawable/ic_anilist_icon" />
</Preference>
<Preference <Preference
android:title="@string/github" android:title="@string/github"
android:icon="@drawable/ic_github_logo" android:icon="@drawable/ic_github_logo"
app:summary="https://github.com/LagradOst/CloudStream-3"> app:summary="https://github.com/LagradOst/CloudStream-3">
<intent android:action="android.intent.action.VIEW" <intent
android:action="android.intent.action.VIEW"
android:data="https://github.com/LagradOst/CloudStream-3" /> android:data="https://github.com/LagradOst/CloudStream-3" />
</Preference> </Preference>
@ -209,21 +185,22 @@
android:title="@string/lightnovel" android:title="@string/lightnovel"
android:icon="@drawable/quick_novel_icon" android:icon="@drawable/quick_novel_icon"
app:summary="https://github.com/LagradOst/QuickNovel"> app:summary="https://github.com/LagradOst/QuickNovel">
<intent android:action="android.intent.action.VIEW" <intent
android:action="android.intent.action.VIEW"
android:data="https://github.com/LagradOst/QuickNovel" /> android:data="https://github.com/LagradOst/QuickNovel" />
</Preference> </Preference>
<Preference <Preference
android:title="@string/discord" android:title="@string/discord"
android:icon="@drawable/ic_baseline_discord_24" android:icon="@drawable/ic_baseline_discord_24"
app:summary="https://discord.gg/5Hus6fM"> app:summary="https://discord.gg/5Hus6fM">
<intent android:action="android.intent.action.VIEW" <intent
android:action="android.intent.action.VIEW"
android:data="https://discord.gg/5Hus6fM" /> android:data="https://discord.gg/5Hus6fM" />
</Preference> </Preference>
<Preference <Preference
android:key="@string/benene_count" android:key="@string/benene_count"
android:title="@string/benene" android:title="@string/benene"
android:icon="@drawable/benene" android:icon="@drawable/benene"
app:summary="@string/benene_des"> app:summary="@string/benene_des" />
</Preference>
</PreferenceCategory> </PreferenceCategory>
</PreferenceScreen> </PreferenceScreen>