mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 14:20:30 +05:30
Merge pull request #6579 from Bnyro/master
refactor: also respect codec preference in audio mode
This commit is contained in:
commit
81e894fb7e
@ -869,4 +869,30 @@ object PlayerHelper {
|
|||||||
else -> false
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -338,11 +338,11 @@ class OnlinePlayerService : LifecycleService() {
|
|||||||
// prevent android from putting LibreTube to sleep when locked
|
// prevent android from putting LibreTube to sleep when locked
|
||||||
player!!.setWakeMode(WAKE_MODE_NETWORK)
|
player!!.setWakeMode(WAKE_MODE_NETWORK)
|
||||||
|
|
||||||
/**
|
// Listens for changed playbackStates (e.g. pause, end)
|
||||||
* Listens for changed playbackStates (e.g. pause, end)
|
// Plays the next video when the current one ended
|
||||||
* Plays the next video when the current one ended
|
|
||||||
*/
|
|
||||||
player?.addListener(playerListener)
|
player?.addListener(playerListener)
|
||||||
|
|
||||||
|
PlayerHelper.setPreferredCodecs(trackSelector!!)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1348,28 +1348,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
|||||||
viewModel.player.addListener(playerListener)
|
viewModel.player.addListener(playerListener)
|
||||||
|
|
||||||
// control for the track sources like subtitles and audio source
|
// control for the track sources like subtitles and audio source
|
||||||
viewModel.trackSelector.updateParameters {
|
PlayerHelper.setPreferredCodecs(viewModel.trackSelector)
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user