Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify resolution display in the player view. #3071

Merged
merged 1 commit into from
Feb 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ package com.github.libretube.obj

data class VideoResolution(
val name: String,
val resolution: Int? = null,
val adaptiveSourceUrl: String? = null
val resolution: Int
)
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