mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-28 16:00:31 +05:30
Simplify getAvailableResolutions().
This commit is contained in:
parent
97ec8bf315
commit
b99fb04cbd
@ -2,6 +2,5 @@ package com.github.libretube.obj
|
|||||||
|
|
||||||
data class VideoResolution(
|
data class VideoResolution(
|
||||||
val name: String,
|
val name: String,
|
||||||
val resolution: Int? = null,
|
val resolution: Int
|
||||||
val adaptiveSourceUrl: String? = null
|
|
||||||
)
|
)
|
||||||
|
@ -1202,29 +1202,18 @@ class PlayerFragment : Fragment(R.layout.fragment_player), OnlinePlayerOptions {
|
|||||||
* Get all available player resolutions
|
* Get all available player resolutions
|
||||||
*/
|
*/
|
||||||
private fun getAvailableResolutions(): List<VideoResolution> {
|
private fun getAvailableResolutions(): List<VideoResolution> {
|
||||||
val resolutions = exoPlayer.currentTracks.groups.asSequence().map { group ->
|
val resolutions = exoPlayer.currentTracks.groups.asSequence()
|
||||||
|
.flatMap { group ->
|
||||||
(0 until group.length).map {
|
(0 until group.length).map {
|
||||||
group.getTrackFormat(it).height
|
group.getTrackFormat(it).height
|
||||||
}
|
}
|
||||||
}.flatten()
|
|
||||||
.filter { it > 0 }
|
|
||||||
.sortedDescending()
|
|
||||||
.distinct()
|
|
||||||
|
|
||||||
return resolutions.map {
|
|
||||||
VideoResolution(
|
|
||||||
name = "${it}p",
|
|
||||||
resolution = it
|
|
||||||
)
|
|
||||||
}.toMutableList().also {
|
|
||||||
it.add(
|
|
||||||
0,
|
|
||||||
VideoResolution(
|
|
||||||
getString(R.string.auto_quality),
|
|
||||||
resolution = Int.MAX_VALUE
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
.filter { it > 0 }
|
||||||
|
.map { VideoResolution("${it}p", it) }
|
||||||
|
.toSortedSet(compareByDescending { it.resolution })
|
||||||
|
|
||||||
|
resolutions.add(VideoResolution(getString(R.string.auto_quality), Int.MAX_VALUE))
|
||||||
|
return resolutions.toList()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setResolutionAndSubtitles() {
|
private fun setResolutionAndSubtitles() {
|
||||||
@ -1366,9 +1355,7 @@ class PlayerFragment : Fragment(R.layout.fragment_player), OnlinePlayerOptions {
|
|||||||
if (currentQuality == it.resolution) "${it.name} ✓" else it.name
|
if (currentQuality == it.resolution) "${it.name} ✓" else it.name
|
||||||
}
|
}
|
||||||
) { which ->
|
) { which ->
|
||||||
resolutions[which].resolution?.let {
|
setPlayerResolution(resolutions[which].resolution)
|
||||||
setPlayerResolution(it)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
.show(childFragmentManager)
|
.show(childFragmentManager)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user