Merge pull request #4517 from Bnyro/master

feat(player): show if quality is auto or limited
This commit is contained in:
Bnyro 2023-08-16 18:45:25 +02:00 committed by GitHub
commit 8653143d10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 9 deletions

View File

@ -32,27 +32,21 @@ class OnlinePlayerView(
BottomSheetItem(
context.getString(R.string.quality),
R.drawable.ic_hd,
{ "${player?.videoSize?.height}p" }
this::getCurrentResolutionSummary
) {
playerOptions?.onQualityClicked()
},
BottomSheetItem(
context.getString(R.string.audio_track),
R.drawable.ic_audio,
{ getCurrentAudioTrackTitle() }
this::getCurrentAudioTrackTitle
) {
playerOptions?.onAudioStreamClicked()
},
BottomSheetItem(
context.getString(R.string.captions),
R.drawable.ic_caption,
{
if (trackSelector != null && trackSelector!!.parameters.preferredTextLanguages.isNotEmpty()) {
trackSelector!!.parameters.preferredTextLanguages[0]
} else {
context.getString(R.string.none)
}
}
this::getCurrentCaptionLanguage
) {
playerOptions?.onCaptionsClicked()
},
@ -65,6 +59,29 @@ class OnlinePlayerView(
)
}
@androidx.annotation.OptIn(androidx.media3.common.util.UnstableApi::class)
private fun getCurrentResolutionSummary(): String {
val currentQuality = player?.videoSize?.height ?: 0
var summary = "${currentQuality}p"
val trackSelector = trackSelector ?: return summary
val selectedQuality = trackSelector.parameters.maxVideoHeight
if (selectedQuality == Int.MAX_VALUE) {
summary += " - ${context.getString(R.string.auto)}"
} else if (selectedQuality > currentQuality) {
summary += " - ${context.getString(R.string.resolution_limited)}"
}
return summary
}
@androidx.annotation.OptIn(androidx.media3.common.util.UnstableApi::class)
private fun getCurrentCaptionLanguage(): String {
return if (trackSelector != null && trackSelector!!.parameters.preferredTextLanguages.isNotEmpty()) {
trackSelector!!.parameters.preferredTextLanguages[0]
} else {
context.getString(R.string.none)
}
}
private fun getCurrentAudioTrackTitle(): String {
if (player == null) {
return context.getString(R.string.unknown_or_no_audio)

View File

@ -462,6 +462,7 @@
<string name="no_chapter">No chapter</string>
<string name="screen_orientation">Screen orientation</string>
<string name="auto_generated">auto-generated</string>
<string name="resolution_limited">limited</string>
<!-- Notification channel strings -->
<string name="download_channel_name">Download Service</string>