From 8322fbd5c9c613741c242a4e12e5e7dd477b652a Mon Sep 17 00:00:00 2001 From: Bnyro Date: Wed, 8 Feb 2023 09:41:59 +0100 Subject: [PATCH] Add preference to choose video codecs --- .../libretube/constants/PreferenceKeys.kt | 1 + .../github/libretube/helpers/DashHelper.kt | 12 +++++++++-- .../github/libretube/helpers/PlayerHelper.kt | 8 ++++++- app/src/main/res/drawable/ic_equalizer.xml | 10 +++++++++ app/src/main/res/values/array.xml | 21 +++++++++++-------- app/src/main/res/values/strings.xml | 1 + app/src/main/res/xml/audio_video_settings.xml | 13 ++++++++++++ 7 files changed, 54 insertions(+), 12 deletions(-) create mode 100644 app/src/main/res/drawable/ic_equalizer.xml diff --git a/app/src/main/java/com/github/libretube/constants/PreferenceKeys.kt b/app/src/main/java/com/github/libretube/constants/PreferenceKeys.kt index 7a1e06197..196b80038 100644 --- a/app/src/main/java/com/github/libretube/constants/PreferenceKeys.kt +++ b/app/src/main/java/com/github/libretube/constants/PreferenceKeys.kt @@ -89,6 +89,7 @@ object PreferenceKeys { const val PAUSE_ON_QUIT = "pause_on_quit" const val ALTERNATIVE_PIP_CONTROLS = "alternative_pip_controls" const val SKIP_SILENCE = "skip_silence" + const val ENABLED_VIDEO_CODECS = "video_codecs" /** * Background mode diff --git a/app/src/main/java/com/github/libretube/helpers/DashHelper.kt b/app/src/main/java/com/github/libretube/helpers/DashHelper.kt index f26d7e726..c4c25948a 100644 --- a/app/src/main/java/com/github/libretube/helpers/DashHelper.kt +++ b/app/src/main/java/com/github/libretube/helpers/DashHelper.kt @@ -39,7 +39,15 @@ object DashHelper { val adapSetInfos = ArrayList() - for (stream in streams.videoStreams!!) { + val enabledVideoCodecs = PlayerHelper.enabledVideoCodecs + // filter the codecs according to the user's preferences + for (stream in streams.videoStreams.filter { + if (enabledVideoCodecs != "all") { + it.codec?.lowercase()?.startsWith(enabledVideoCodecs) ?: true + } else { + true + } + }) { // ignore dual format streams if (!stream.videoOnly!!) { continue @@ -64,7 +72,7 @@ object DashHelper { ) } - for (stream in streams.audioStreams!!) { + for (stream in streams.audioStreams) { val adapSetInfo = adapSetInfos.find { it.mimeType == stream.mimeType && it.audioTrackId == stream.audioTrackId diff --git a/app/src/main/java/com/github/libretube/helpers/PlayerHelper.kt b/app/src/main/java/com/github/libretube/helpers/PlayerHelper.kt index 915bd7c40..431de910f 100644 --- a/app/src/main/java/com/github/libretube/helpers/PlayerHelper.kt +++ b/app/src/main/java/com/github/libretube/helpers/PlayerHelper.kt @@ -279,7 +279,7 @@ object PlayerHelper { .roundToInt() .toLong() * 1000 - val playbackSpeed: String + private val playbackSpeed: String get() = PreferenceHelper.getString( PreferenceKeys.PLAYBACK_SPEED, "1" @@ -345,6 +345,12 @@ object PlayerHelper { false ) + val enabledVideoCodecs: String + get() = PreferenceHelper.getString( + PreferenceKeys.ENABLED_VIDEO_CODECS, + "all" + ) + fun getDefaultResolution(context: Context): String { val prefKey = if (NetworkHelper.isNetworkMetered(context)) { PreferenceKeys.DEFAULT_RESOLUTION_MOBILE diff --git a/app/src/main/res/drawable/ic_equalizer.xml b/app/src/main/res/drawable/ic_equalizer.xml new file mode 100644 index 000000000..b9b719130 --- /dev/null +++ b/app/src/main/res/drawable/ic_equalizer.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/values/array.xml b/app/src/main/res/values/array.xml index ce2c0f36f..b43536bf7 100644 --- a/app/src/main/res/values/array.xml +++ b/app/src/main/res/values/array.xml @@ -179,15 +179,6 @@ 5 - - MP4 - MKV - - - .mp4 - .mkv - - 50s 100s @@ -401,4 +392,16 @@ enabled + + @string/all + VP9 + AVC + + + + all + vp9 + avc + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 90285cd73..37f78698e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -440,6 +440,7 @@ Skip silence Help FAQ + Codecs Download Service diff --git a/app/src/main/res/xml/audio_video_settings.xml b/app/src/main/res/xml/audio_video_settings.xml index 217e00cb3..5daf5cf77 100644 --- a/app/src/main/res/xml/audio_video_settings.xml +++ b/app/src/main/res/xml/audio_video_settings.xml @@ -78,4 +78,17 @@ + + + + + + \ No newline at end of file