Skip to content

StreamVault is a TV-first free IPTV player for Android TV built with Kotlin, Jetpack Compose, Room, Hilt, and Media3.

refactor: remove withScopedScrubbingMode function and adjust channel change logic for smoother playback

David Nashashfcc619317149
diff --git a/app/src/main/java/com/streamvault/app/ui/screens/player/PlayerZapActions.kt b/app/src/main/java/com/streamvault/app/ui/screens/player/PlayerZapActions.kt
index db7ce028..56809552 100644
--- a/app/src/main/java/com/streamvault/app/ui/screens/player/PlayerZapActions.kt
+++ b/app/src/main/java/com/streamvault/app/ui/screens/player/PlayerZapActions.kt
@@ -68,18 +68,6 @@ internal fun buildLivePlaybackRecordCandidate(
)
}
-internal suspend fun <T> withScopedScrubbingMode(
- setScrubbingMode: (Boolean) -> Unit,
- block: suspend () -> T
-): T {
- setScrubbingMode(true)
- return try {
- block()
- } finally {
- setScrubbingMode(false)
- }
-}
-
internal fun releaseOutgoingLiveZapPlayback(
stopPlayback: () -> Unit,
stopLiveTimeshift: () -> Unit,
@@ -236,21 +224,27 @@ internal fun PlayerViewModel.changeChannel(index: Int, isAutoFallback: Boolean =
displayChannelNumberFlow.value = resolveChannelNumber(channel, index)
recentChannelsFlow.update { channels -> channels.filterNot { it.id == channel.id } }
+ // Start a fresh live channel with scrubbing mode OFF. Scrubbing mode disables the
+ // audio track and changes codec behaviour; previously the whole zap prepare was
+ // wrapped so scrubbing was toggled ON before prepare and OFF at first frame. That
+ // exit toggle re-enabled the audio renderer mid-stream and reset the codec, which
+ // stalled playback for ~1-2s right as sound came in. Channel changes should behave
+ // like normal playback (matching the smooth pro-mode preview).
+ playerEngine.setScrubbingMode(false)
+
viewModelScope.launch {
- withScopedScrubbingMode(playerEngine::setScrubbingMode) {
- val streamInfo = resolvePlaybackStreamInfo(channel.streamUrl, channel.id, channel.providerId, ContentType.LIVE)
- ?: return@withScopedScrubbingMode
- if (!isActivePlaybackSession(requestVersion, channel.streamUrl)) return@withScopedScrubbingMode
- if (!preparePlayer(streamInfo, requestVersion)) return@withScopedScrubbingMode
- playerEngine.play()
-
- playerEngine.playbackState
- .filter {
- it == com.streamvault.player.PlaybackState.READY ||
- !isActivePlaybackSession(requestVersion, channel.streamUrl)
- }
- .first()
- }
+ val streamInfo = resolvePlaybackStreamInfo(channel.streamUrl, channel.id, channel.providerId, ContentType.LIVE)
+ ?: return@launch
+ if (!isActivePlaybackSession(requestVersion, channel.streamUrl)) return@launch
+ if (!preparePlayer(streamInfo, requestVersion)) return@launch
+ playerEngine.play()
+
+ playerEngine.playbackState
+ .filter {
+ it == com.streamvault.player.PlaybackState.READY ||
+ !isActivePlaybackSession(requestVersion, channel.streamUrl)
+ }
+ .first()
}
preloadAdjacentChannel(index)
diff --git a/app/src/test/java/com/streamvault/app/ui/screens/player/PlayerZapActionsTest.kt b/app/src/test/java/com/streamvault/app/ui/screens/player/PlayerZapActionsTest.kt
index 278ba565..21828209 100644
--- a/app/src/test/java/com/streamvault/app/ui/screens/player/PlayerZapActionsTest.kt
+++ b/app/src/test/java/com/streamvault/app/ui/screens/player/PlayerZapActionsTest.kt
@@ -2,7 +2,6 @@ package com.streamvault.app.ui.screens.player
import com.google.common.truth.Truth.assertThat
import com.streamvault.domain.model.ProviderType
-import kotlinx.coroutines.test.runTest
import org.junit.Test
class PlayerZapActionsTest {
@@ -30,30 +29,6 @@ class PlayerZapActionsTest {
assertThat(buffer).isEqualTo("7")
}
- @Test
- fun `withScopedScrubbingMode disables scrubbing after success`() = runTest {
- val states = mutableListOf<Boolean>()
-
- withScopedScrubbingMode(states::add) {
- "done"
- }
-
- assertThat(states).containsExactly(true, false).inOrder()
- }
-
- @Test
- fun `withScopedScrubbingMode disables scrubbing after failure`() = runTest {
- val states = mutableListOf<Boolean>()
-
- runCatching {
- withScopedScrubbingMode(states::add) {
- error("boom")
- }
- }
-
- assertThat(states).containsExactly(true, false).inOrder()
- }
-
@Test
fun `releaseOutgoingLiveZapPlayback closes active fetchers before clearing preload`() {
val calls = mutableListOf<String>()