mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-27 23:40:33 +05:30
add selection logic
This commit is contained in:
parent
d0ef111c2d
commit
bc9110ed27
@ -38,6 +38,7 @@ import com.github.libretube.R
|
||||
import com.github.libretube.api.CronetHelper
|
||||
import com.github.libretube.api.RetrofitInstance
|
||||
import com.github.libretube.api.obj.ChapterSegment
|
||||
import com.github.libretube.api.obj.PipedStream
|
||||
import com.github.libretube.api.obj.SegmentData
|
||||
import com.github.libretube.api.obj.StreamItem
|
||||
import com.github.libretube.api.obj.Streams
|
||||
@ -1407,8 +1408,23 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
||||
.show(childFragmentManager)
|
||||
}
|
||||
|
||||
fun getAudioStreamGroups(audioStreams: List<PipedStream>?): Map<String, List<PipedStream>> {
|
||||
return audioStreams.orEmpty()
|
||||
.filter { it.audioTrackName != null }
|
||||
.groupBy { it.audioTrackName!! }
|
||||
}
|
||||
|
||||
override fun onAudioStreamClicked() {
|
||||
TODO("Not yet implemented")
|
||||
val audioGroups = getAudioStreamGroups(streams.audioStreams)
|
||||
val audioLanguages = audioGroups.map { it.key }
|
||||
|
||||
BaseBottomSheet()
|
||||
.setSimpleItems(audioLanguages) { index ->
|
||||
val audioStreams = audioGroups.values.elementAt(index)
|
||||
val audioUrl = PlayerHelper.getAudioSource(requireContext(), audioStreams)
|
||||
setMediaSource(streams.videoStreams!!.first().url!!.toUri(), audioUrl)
|
||||
}
|
||||
.show(childFragmentManager)
|
||||
}
|
||||
|
||||
override fun onPictureInPictureModeChanged(isInPictureInPictureMode: Boolean) {
|
||||
|
@ -3,6 +3,7 @@ package com.github.libretube.util
|
||||
import android.content.Context
|
||||
import android.content.pm.ActivityInfo
|
||||
import android.view.accessibility.CaptioningManager
|
||||
import com.github.libretube.api.obj.PipedStream
|
||||
import com.github.libretube.constants.PreferenceKeys
|
||||
import com.google.android.exoplayer2.ui.CaptionStyleCompat
|
||||
import com.google.android.exoplayer2.video.VideoSize
|
||||
@ -12,7 +13,7 @@ object PlayerHelper {
|
||||
// get the audio source following the users preferences
|
||||
fun getAudioSource(
|
||||
context: Context,
|
||||
audios: List<com.github.libretube.api.obj.PipedStream>
|
||||
audios: List<PipedStream>
|
||||
): String {
|
||||
val audioFormat = PreferenceHelper.getString(PreferenceKeys.PLAYER_AUDIO_FORMAT, "all")
|
||||
val audioQuality = if (
|
||||
@ -39,7 +40,7 @@ object PlayerHelper {
|
||||
}
|
||||
|
||||
// get the best bit rate from audio streams
|
||||
private fun getMostBitRate(audios: List<com.github.libretube.api.obj.PipedStream>): String {
|
||||
private fun getMostBitRate(audios: List<PipedStream>): String {
|
||||
var bitrate = 0
|
||||
var audioUrl = ""
|
||||
audios.forEach {
|
||||
@ -52,7 +53,7 @@ object PlayerHelper {
|
||||
}
|
||||
|
||||
// get the best bit rate from audio streams
|
||||
private fun getLeastBitRate(audios: List<com.github.libretube.api.obj.PipedStream>): String {
|
||||
private fun getLeastBitRate(audios: List<PipedStream>): String {
|
||||
var bitrate = 1000000000
|
||||
var audioUrl = ""
|
||||
audios.forEach {
|
||||
|
Loading…
x
Reference in New Issue
Block a user