Skip to content
Merged
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
20 changes: 20 additions & 0 deletions app/src/main/kotlin/com/arflix/tv/ui/screens/home/HomeScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.Stable
import androidx.compose.runtime.collectAsState
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.compose.currentStateAsState
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.key
Expand Down Expand Up @@ -1044,12 +1045,18 @@ fun HomeScreen(
// moving elsewhere replays it.
var collectionVideoFinishedId by remember { mutableStateOf<Int?>(null) }
val heroVideoAllowed = true
// Leaving the app (Home button / minimize) stops the activity but keeps this
// composition alive, so the hero preview has to follow the lifecycle or its
// audio keeps playing in the background.
val homeLifecycleState by lifecycleOwner.lifecycle.currentStateAsState()
val isHomeStarted = homeLifecycleState.isAtLeast(Lifecycle.State.STARTED)
val serviceHeroVideoUrl = displayHeroItem
?.takeIf { heroVideoAllowed && isHeroCollection && collectionVideoFinishedId != it.id }
?.let { viewModel.getCollectionHeroVideoUrl(it) }
val heroVideoUrl = when {
!isMobile && !focusState.userHasNavigated -> null
!heroVideoAllowed -> null
!isHomeStarted -> null
// Service collection MP4s should start as soon as the card becomes the hero.
// Keep the idle gate for heavier IPTV/live playback, but do not delay MP4 previews.
serviceHeroVideoUrl != null -> serviceHeroVideoUrl
Expand All @@ -1076,6 +1083,19 @@ fun HomeScreen(
}
}

// Fully release the stream while backgrounded: a paused live channel would be
// behind the live window on return, so it gets re-prepared fresh instead.
LaunchedEffect(isHomeStarted) {
if (!isHomeStarted) {
heroPlaybackHandles?.player?.let { player ->
player.playWhenReady = false
player.stop()
player.clearMediaItems()
}
preparedHeroVideoUrl = null
}
}

// Service-collection video lifecycle: play once on focus, with sound,
// then mark the card "played" so subsequent focus returns fall back to
// the stock image. IPTV live streams bypass this (they loop naturally).
Expand Down
Loading