StreamVault is a TV-first free IPTV player for Android TV built with Kotlin, Jetpack Compose, Room, Hilt, and Media3.
Kotlin iptv-player
fix(player): smooth preview handoff to fullscreen
Jorge Ceballos44702c51396d
diff --git a/app/src/main/java/com/streamvault/app/ui/screens/player/PlayerPreviewHandoffSupport.kt b/app/src/main/java/com/streamvault/app/ui/screens/player/PlayerPreviewHandoffSupport.ktnew file mode 100644index 00000000..8972e04e--- /dev/null+++ b/app/src/main/java/com/streamvault/app/ui/screens/player/PlayerPreviewHandoffSupport.kt@@ -0,0 +1,9 @@+package com.streamvault.app.ui.screens.player++import com.streamvault.player.PlaybackState+import com.streamvault.player.PlayerStats++internal fun shouldRenewAdoptedPreviewOnFullscreen(+ playbackState: PlaybackState,+ playerStats: PlayerStats+): Boolean = playbackState != PlaybackState.READY || playerStats.ttffMs <= 0Ldiff --git a/app/src/main/java/com/streamvault/app/ui/screens/player/PlayerViewModel.kt b/app/src/main/java/com/streamvault/app/ui/screens/player/PlayerViewModel.ktindex 1a5b631a..190280ba 100644--- a/app/src/main/java/com/streamvault/app/ui/screens/player/PlayerViewModel.kt+++ b/app/src/main/java/com/streamvault/app/ui/screens/player/PlayerViewModel.kt@@ -1062,6 +1062,10 @@ class PlayerViewModel @Inject constructor(val adoptedEngine = session.enginereturn runCatching {+ val shouldRenewAdoptedPreview = shouldRenewAdoptedPreviewOnFullscreen(+ playbackState = adoptedEngine.playbackState.value,+ playerStats = adoptedEngine.playerStats.value+ )// Detach the Home preview surface before Player binds its own.adoptedEngine.clearRenderBinding()// Media3 requires a globally unique session ID. Release the main engine's@@ -1088,13 +1092,12 @@ class PlayerViewModel @Inject constructor(url = session.streamInfo.url))- // Re-prime the adopted engine against the fullscreen surface path.- // Preview-to-fullscreen handoff can temporarily leave the reused live- // player with an audio-only pipeline until the new render view binds.- // Refreshing the current live media source makes the handoff more- // robust without re-resolving provider URLs or abandoning the adopted- // engine instance.- playerEngine.renewStreamUrl(session.streamInfo)+ if (shouldRenewAdoptedPreview) {+ // Re-prime when the preview has not produced video yet. This keeps+ // the previous audio-only/stale-surface recovery path without+ // rebuffering a preview that is already rendering.+ playerEngine.renewStreamUrl(session.streamInfo)+ }playerEngine.play()startTokenRenewalMonitoring(session.streamInfo.expirationTime)maybeStartLiveTimeshift(session.streamInfo)diff --git a/app/src/test/java/com/streamvault/app/ui/screens/player/PlayerPreviewHandoffSupportTest.kt b/app/src/test/java/com/streamvault/app/ui/screens/player/PlayerPreviewHandoffSupportTest.ktnew file mode 100644index 00000000..63fec45b--- /dev/null+++ b/app/src/test/java/com/streamvault/app/ui/screens/player/PlayerPreviewHandoffSupportTest.kt@@ -0,0 +1,48 @@+package com.streamvault.app.ui.screens.player++import com.google.common.truth.Truth.assertThat+import com.streamvault.player.PlaybackState+import com.streamvault.player.PlayerStats+import org.junit.Test++class PlayerPreviewHandoffSupportTest {++ @Test+ fun `ready preview with rendered frame skips fullscreen renewal`() {+ val shouldRenew = shouldRenewAdoptedPreviewOnFullscreen(+ playbackState = PlaybackState.READY,+ playerStats = PlayerStats(ttffMs = 250L)+ )++ assertThat(shouldRenew).isFalse()+ }++ @Test+ fun `ready preview without rendered frame renews fullscreen stream`() {+ val shouldRenew = shouldRenewAdoptedPreviewOnFullscreen(+ playbackState = PlaybackState.READY,+ playerStats = PlayerStats(ttffMs = 0L)+ )++ assertThat(shouldRenew).isTrue()+ }++ @Test+ fun `non ready preview renews fullscreen stream`() {+ val states = listOf(+ PlaybackState.IDLE,+ PlaybackState.BUFFERING,+ PlaybackState.ENDED,+ PlaybackState.ERROR+ )++ states.forEach { state ->+ assertThat(+ shouldRenewAdoptedPreviewOnFullscreen(+ playbackState = state,+ playerStats = PlayerStats(ttffMs = 250L)+ )+ ).isTrue()+ }+ }+}