Skip to content

Commit

Permalink
Simplify getAvailableResolutions().
Browse files Browse the repository at this point in the history
  • Loading branch information
Isira-Seneviratne committed Feb 14, 2023
1 parent 97ec8bf commit 443b0e0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ package com.github.libretube.obj

data class VideoResolution(
val name: String,
val resolution: Int? = null,
val resolution: Int,
val adaptiveSourceUrl: String? = null
)
Original file line number Diff line number Diff line change
Expand Up @@ -1202,29 +1202,18 @@ class PlayerFragment : Fragment(R.layout.fragment_player), OnlinePlayerOptions {
* Get all available player resolutions
*/
private fun getAvailableResolutions(): List<VideoResolution> {
val resolutions = exoPlayer.currentTracks.groups.asSequence().map { group ->
(0 until group.length).map {
group.getTrackFormat(it).height
val resolutions = exoPlayer.currentTracks.groups.asSequence()
.flatMap { group ->
(0 until group.length).map {
group.getTrackFormat(it).height
}
}
}.flatten()
.filter { it > 0 }
.sortedDescending()
.distinct()
.map { VideoResolution("${it}p", it) }
.toSortedSet(compareByDescending { it.resolution })

return resolutions.map {
VideoResolution(
name = "${it}p",
resolution = it
)
}.toMutableList().also {
it.add(
0,
VideoResolution(
getString(R.string.auto_quality),
resolution = Int.MAX_VALUE
)
)
}
resolutions.add(VideoResolution(getString(R.string.auto_quality), Int.MAX_VALUE))
return resolutions.toList()
}

private fun setResolutionAndSubtitles() {
Expand Down Expand Up @@ -1366,9 +1355,7 @@ class PlayerFragment : Fragment(R.layout.fragment_player), OnlinePlayerOptions {
if (currentQuality == it.resolution) "${it.name}" else it.name
}
) { which ->
resolutions[which].resolution?.let {
setPlayerResolution(it)
}
setPlayerResolution(resolutions[which].resolution)
}
.show(childFragmentManager)
}
Expand Down

0 comments on commit 443b0e0

Please sign in to comment.