mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-28 07:50:31 +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.CronetHelper
|
||||||
import com.github.libretube.api.RetrofitInstance
|
import com.github.libretube.api.RetrofitInstance
|
||||||
import com.github.libretube.api.obj.ChapterSegment
|
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.SegmentData
|
||||||
import com.github.libretube.api.obj.StreamItem
|
import com.github.libretube.api.obj.StreamItem
|
||||||
import com.github.libretube.api.obj.Streams
|
import com.github.libretube.api.obj.Streams
|
||||||
@ -1407,8 +1408,23 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
|||||||
.show(childFragmentManager)
|
.show(childFragmentManager)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getAudioStreamGroups(audioStreams: List<PipedStream>?): Map<String, List<PipedStream>> {
|
||||||
|
return audioStreams.orEmpty()
|
||||||
|
.filter { it.audioTrackName != null }
|
||||||
|
.groupBy { it.audioTrackName!! }
|
||||||
|
}
|
||||||
|
|
||||||
override fun onAudioStreamClicked() {
|
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) {
|
override fun onPictureInPictureModeChanged(isInPictureInPictureMode: Boolean) {
|
||||||
|
@ -3,6 +3,7 @@ package com.github.libretube.util
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.pm.ActivityInfo
|
import android.content.pm.ActivityInfo
|
||||||
import android.view.accessibility.CaptioningManager
|
import android.view.accessibility.CaptioningManager
|
||||||
|
import com.github.libretube.api.obj.PipedStream
|
||||||
import com.github.libretube.constants.PreferenceKeys
|
import com.github.libretube.constants.PreferenceKeys
|
||||||
import com.google.android.exoplayer2.ui.CaptionStyleCompat
|
import com.google.android.exoplayer2.ui.CaptionStyleCompat
|
||||||
import com.google.android.exoplayer2.video.VideoSize
|
import com.google.android.exoplayer2.video.VideoSize
|
||||||
@ -12,7 +13,7 @@ object PlayerHelper {
|
|||||||
// get the audio source following the users preferences
|
// get the audio source following the users preferences
|
||||||
fun getAudioSource(
|
fun getAudioSource(
|
||||||
context: Context,
|
context: Context,
|
||||||
audios: List<com.github.libretube.api.obj.PipedStream>
|
audios: List<PipedStream>
|
||||||
): String {
|
): String {
|
||||||
val audioFormat = PreferenceHelper.getString(PreferenceKeys.PLAYER_AUDIO_FORMAT, "all")
|
val audioFormat = PreferenceHelper.getString(PreferenceKeys.PLAYER_AUDIO_FORMAT, "all")
|
||||||
val audioQuality = if (
|
val audioQuality = if (
|
||||||
@ -39,7 +40,7 @@ object PlayerHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get the best bit rate from audio streams
|
// 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 bitrate = 0
|
||||||
var audioUrl = ""
|
var audioUrl = ""
|
||||||
audios.forEach {
|
audios.forEach {
|
||||||
@ -52,7 +53,7 @@ object PlayerHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get the best bit rate from audio streams
|
// 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 bitrate = 1000000000
|
||||||
var audioUrl = ""
|
var audioUrl = ""
|
||||||
audios.forEach {
|
audios.forEach {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user