From 4ec979e001cd67f3344e0955cafe96c3aef4396b Mon Sep 17 00:00:00 2001 From: Mattias Buelens <649348+MattiasBuelens@users.noreply.github.com> Date: Fri, 27 Sep 2024 11:01:10 +0200 Subject: [PATCH 1/3] Improve time display for live streams (#44) * Tweak CurrentTimeDisplay in default UI when playing live or DVR * Use seekable end for duration displays * Update changelog --- CHANGELOG.md | 7 +++++++ .../java/com/theoplayer/android/ui/CurrentTimeDisplay.kt | 2 +- ui/src/main/java/com/theoplayer/android/ui/DefaultUI.kt | 7 ++++++- .../main/java/com/theoplayer/android/ui/DurationDisplay.kt | 2 +- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 64de75f..500b407 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,13 @@ > - 🏠 Internal > - 💅 Polish +## Unreleased + +* 🐛 Fix `DurationDisplay` to show the time of the live point when playing a live or DVR stream. +* 🐛 Fix `CurrentTimeDisplay` to show the time offset to the live point when playing a live or DVR stream with `showRemaining = true`. +* 💅 Changed `DefaultUi` to hide the current time display when playing a live stream. +* 💅 Changed `DefaultUi` to show the time offset to the live point when playing a DVR stream. + ## v1.9.0 (2024-09-10) * 💥 Updated to Jetpack Compose version 1.7.0 ([BOM](https://developer.android.com/jetpack/compose/bom) 2024.09.00). diff --git a/ui/src/main/java/com/theoplayer/android/ui/CurrentTimeDisplay.kt b/ui/src/main/java/com/theoplayer/android/ui/CurrentTimeDisplay.kt index fa32c76..0b83c76 100644 --- a/ui/src/main/java/com/theoplayer/android/ui/CurrentTimeDisplay.kt +++ b/ui/src/main/java/com/theoplayer/android/ui/CurrentTimeDisplay.kt @@ -21,7 +21,7 @@ fun CurrentTimeDisplay( ) { val player = Player.current val currentTime = player?.currentTime ?: 0.0 - val duration = player?.duration ?: Double.NaN + val duration = player?.seekable?.lastEnd ?: player?.duration ?: Double.NaN val time = if (showRemaining) { -(duration - currentTime) diff --git a/ui/src/main/java/com/theoplayer/android/ui/DefaultUI.kt b/ui/src/main/java/com/theoplayer/android/ui/DefaultUI.kt index e5ee866..f433613 100644 --- a/ui/src/main/java/com/theoplayer/android/ui/DefaultUI.kt +++ b/ui/src/main/java/com/theoplayer/android/ui/DefaultUI.kt @@ -112,7 +112,12 @@ fun DefaultUI( Row(verticalAlignment = Alignment.CenterVertically) { MuteButton() LiveButton() - CurrentTimeDisplay(showDuration = true) + if (player.streamType != StreamType.Live) { + CurrentTimeDisplay( + showRemaining = player.streamType == StreamType.Dvr, + showDuration = player.streamType == StreamType.Vod + ) + } Spacer(modifier = Modifier.weight(1f)) FullscreenButton() } diff --git a/ui/src/main/java/com/theoplayer/android/ui/DurationDisplay.kt b/ui/src/main/java/com/theoplayer/android/ui/DurationDisplay.kt index 520929a..3527ab3 100644 --- a/ui/src/main/java/com/theoplayer/android/ui/DurationDisplay.kt +++ b/ui/src/main/java/com/theoplayer/android/ui/DurationDisplay.kt @@ -14,7 +14,7 @@ fun DurationDisplay( modifier: Modifier = Modifier ) { val player = Player.current - val duration = player?.duration ?: Double.NaN + val duration = player?.seekable?.lastEnd ?: player?.duration ?: Double.NaN Text(modifier = modifier, text = formatTime(duration)) } \ No newline at end of file From 9c3ee28443cf69816205f415ac05b701bdb249e6 Mon Sep 17 00:00:00 2001 From: Mattias Buelens <649348+MattiasBuelens@users.noreply.github.com> Date: Tue, 1 Oct 2024 14:22:04 +0200 Subject: [PATCH 2/3] Hide LanguageMenuButton automatically when empty (#45) --- CHANGELOG.md | 1 + .../java/com/theoplayer/android/ui/LanguageMenu.kt | 4 ++-- .../com/theoplayer/android/ui/LanguageMenuButton.kt | 12 +++++++++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 500b407..0c77440 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ * 🐛 Fix `CurrentTimeDisplay` to show the time offset to the live point when playing a live or DVR stream with `showRemaining = true`. * 💅 Changed `DefaultUi` to hide the current time display when playing a live stream. * 💅 Changed `DefaultUi` to show the time offset to the live point when playing a DVR stream. +* 💅 Changed `LanguageMenuButton` to automatically hide itself when there are no alternative audio or subtitle tracks to select. ## v1.9.0 (2024-09-10) diff --git a/ui/src/main/java/com/theoplayer/android/ui/LanguageMenu.kt b/ui/src/main/java/com/theoplayer/android/ui/LanguageMenu.kt index fc1635a..911aa18 100644 --- a/ui/src/main/java/com/theoplayer/android/ui/LanguageMenu.kt +++ b/ui/src/main/java/com/theoplayer/android/ui/LanguageMenu.kt @@ -48,11 +48,11 @@ fun MenuScope.LanguageMenu() { } } -private fun showAudioTracks(player: Player?): Boolean { +internal fun showAudioTracks(player: Player?): Boolean { return player != null && player.audioTracks.size >= 2 } -private fun showSubtitleTracks(player: Player?): Boolean { +internal fun showSubtitleTracks(player: Player?): Boolean { return player != null && player.subtitleTracks.isNotEmpty() } diff --git a/ui/src/main/java/com/theoplayer/android/ui/LanguageMenuButton.kt b/ui/src/main/java/com/theoplayer/android/ui/LanguageMenuButton.kt index 7cb6f85..99f5836 100644 --- a/ui/src/main/java/com/theoplayer/android/ui/LanguageMenuButton.kt +++ b/ui/src/main/java/com/theoplayer/android/ui/LanguageMenuButton.kt @@ -25,10 +25,20 @@ fun MenuScope.LanguageMenuButton( ) } ) { + val player = Player.current + if (!showLanguageMenuButton(player)) { + // Hide when no alternative audio or subtitle tracks are available + return + } + IconButton( modifier = modifier, contentPadding = contentPadding, onClick = { openMenu { LanguageMenu() } }) { content() } -} \ No newline at end of file +} + +internal fun showLanguageMenuButton(player: Player?): Boolean { + return showAudioTracks(player) || showSubtitleTracks(player) +} From 7247074e402aeb291f4affaaf174029d35c2fccc Mon Sep 17 00:00:00 2001 From: "theoplayer-bot[bot]" <873105+theoplayer-bot[bot]@users.noreply.github.com> Date: Tue, 1 Oct 2024 12:22:54 +0000 Subject: [PATCH 3/3] 1.9.1 --- CHANGELOG.md | 2 +- gradle.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c77440..477fe82 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ > - 🏠 Internal > - 💅 Polish -## Unreleased +## v1.9.1 (2024-10-01) * 🐛 Fix `DurationDisplay` to show the time of the live point when playing a live or DVR stream. * 🐛 Fix `CurrentTimeDisplay` to show the time offset to the live point when playing a live or DVR stream with `showRemaining = true`. diff --git a/gradle.properties b/gradle.properties index 9511921..2517350 100644 --- a/gradle.properties +++ b/gradle.properties @@ -24,4 +24,4 @@ android.nonTransitiveRClass=true android.nonFinalResIds=true org.gradle.configuration-cache=true # The version of the THEOplayer Open Video UI for Android. -version=1.9.0 +version=1.9.1