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 14c7160b4..18db42ce2 100644
--- a/app/src/main/java/com/github/libretube/constants/PreferenceKeys.kt
+++ b/app/src/main/java/com/github/libretube/constants/PreferenceKeys.kt
@@ -81,6 +81,7 @@ object PreferenceKeys {
const val ALTERNATIVE_PIP_CONTROLS = "alternative_pip_controls"
const val SKIP_SILENCE = "skip_silence"
const val ENABLED_VIDEO_CODECS = "video_codecs"
+ const val ENABLED_AUDIO_CODECS = "audio_codecs"
const val AUTOPLAY_COUNTDOWN = "autoplay_countdown"
const val LBRY_HLS = "lbry_hls"
const val AUTO_FULLSCREEN_SHORTS = "auto_fullscreen_shorts"
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 e27ef87b1..344643ed8 100644
--- a/app/src/main/java/com/github/libretube/helpers/PlayerHelper.kt
+++ b/app/src/main/java/com/github/libretube/helpers/PlayerHelper.kt
@@ -339,6 +339,12 @@ object PlayerHelper {
"all"
)
+ val enabledAudioCodecs: String
+ get() = PreferenceHelper.getString(
+ PreferenceKeys.ENABLED_AUDIO_CODECS,
+ "all"
+ )
+
val playAutomatically: Boolean
get() = PreferenceHelper.getBoolean(
PreferenceKeys.PLAY_AUTOMATICALLY,
diff --git a/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt
index 81acaa88f..bff3e6f30 100644
--- a/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt
+++ b/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt
@@ -17,7 +17,6 @@ import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.os.PowerManager
-import android.util.Log
import android.view.KeyEvent
import android.view.LayoutInflater
import android.view.PixelCopy
@@ -1360,6 +1359,16 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
}
this.setPreferredVideoMimeTypes(*mimeType)
}
+ val enabledAudioCodecs = PlayerHelper.enabledAudioCodecs
+ if (enabledAudioCodecs != "all") {
+ // map the codecs to their corresponding mimetypes
+ val mimeType = when (enabledAudioCodecs) {
+ "opus" -> arrayOf("audio/opus")
+ "mp4" -> arrayOf("audio/mp4a-latm")
+ else -> throw IllegalArgumentException()
+ }
+ this.setPreferredAudioMimeTypes(*mimeType)
+ }
}
}
diff --git a/app/src/main/res/values/array.xml b/app/src/main/res/values/array.xml
index 2a2e7d51e..67420da19 100644
--- a/app/src/main/res/values/array.xml
+++ b/app/src/main/res/values/array.xml
@@ -424,6 +424,18 @@
- avc
+
+ - @string/all
+ - opus
+ - mp4
+
+
+
+ - all
+ - opus
+ - mp4
+
+
- @string/always
- @string/videos
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 62ca4fcef..cb00a7392 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -388,7 +388,8 @@
Skip silence
Help
FAQ
- Codecs
+ Video codecs
+ Audio codecs
Mark as watched
Custom speed
Use a different playback speed than for the normal player
diff --git a/app/src/main/res/xml/audio_video_settings.xml b/app/src/main/res/xml/audio_video_settings.xml
index 88d82852b..1e902b0bd 100644
--- a/app/src/main/res/xml/audio_video_settings.xml
+++ b/app/src/main/res/xml/audio_video_settings.xml
@@ -113,6 +113,15 @@
app:title="@string/codecs"
app:useSimpleSummaryProvider="true" />
+
+
\ No newline at end of file