Merge pull request #6579 from Bnyro/master

refactor: also respect codec preference in audio mode
This commit is contained in:
Bnyro 2024-10-02 13:11:46 +02:00 committed by GitHub
commit 81e894fb7e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 31 additions and 26 deletions

View File

@ -869,4 +869,30 @@ object PlayerHelper {
else -> false
}
}
@OptIn(UnstableApi::class)
fun setPreferredCodecs(trackSelector: DefaultTrackSelector) {
trackSelector.updateParameters {
val enabledVideoCodecs = PlayerHelper.enabledVideoCodecs
if (enabledVideoCodecs != "all") {
// map the codecs to their corresponding mimetypes
val mimeType = when (enabledVideoCodecs) {
"vp9" -> arrayOf("video/webm", "video/x-vnd.on2.vp9")
"avc" -> arrayOf("video/mp4", "video/avc")
else -> throw IllegalArgumentException()
}
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)
}
}
}
}

View File

@ -338,11 +338,11 @@ class OnlinePlayerService : LifecycleService() {
// prevent android from putting LibreTube to sleep when locked
player!!.setWakeMode(WAKE_MODE_NETWORK)
/**
* Listens for changed playbackStates (e.g. pause, end)
* Plays the next video when the current one ended
*/
// Listens for changed playbackStates (e.g. pause, end)
// Plays the next video when the current one ended
player?.addListener(playerListener)
PlayerHelper.setPreferredCodecs(trackSelector!!)
}
/**

View File

@ -1348,28 +1348,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
viewModel.player.addListener(playerListener)
// control for the track sources like subtitles and audio source
viewModel.trackSelector.updateParameters {
val enabledVideoCodecs = PlayerHelper.enabledVideoCodecs
if (enabledVideoCodecs != "all") {
// map the codecs to their corresponding mimetypes
val mimeType = when (enabledVideoCodecs) {
"vp9" -> arrayOf("video/webm", "video/x-vnd.on2.vp9")
"avc" -> arrayOf("video/mp4", "video/avc")
else -> throw IllegalArgumentException()
}
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)
}
}
PlayerHelper.setPreferredCodecs(viewModel.trackSelector)
}
/**