Skip to content

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

refactor: isolate player consumer state

David Nashash772cddde1e5c
diff --git a/app/src/main/java/com/streamvault/app/ui/screens/player/PlayerControlsOverlayHost.kt b/app/src/main/java/com/streamvault/app/ui/screens/player/PlayerControlsOverlayHost.kt
index 530ad56a..973e6937 100644
--- a/app/src/main/java/com/streamvault/app/ui/screens/player/PlayerControlsOverlayHost.kt
+++ b/app/src/main/java/com/streamvault/app/ui/screens/player/PlayerControlsOverlayHost.kt
@@ -1,14 +1,44 @@
package com.streamvault.app.ui.screens.player
+import androidx.compose.animation.core.RepeatMode
+import androidx.compose.animation.core.animateFloat
+import androidx.compose.animation.core.infiniteRepeatable
+import androidx.compose.animation.core.rememberInfiniteTransition
+import androidx.compose.animation.core.tween
+import androidx.compose.foundation.background
+import androidx.compose.foundation.layout.Arrangement
+import androidx.compose.foundation.layout.Box
+import androidx.compose.foundation.layout.Row
+import androidx.compose.foundation.layout.padding
+import androidx.compose.foundation.layout.size
+import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.Composable
+import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
+import androidx.compose.runtime.mutableStateOf
+import androidx.compose.runtime.remember
+import androidx.compose.runtime.setValue
+import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester
+import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.res.stringResource
+import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
+import androidx.tv.material3.MaterialTheme
+import androidx.tv.material3.Text
+import com.streamvault.app.R
+import com.streamvault.app.cast.CastConnectionState
import com.streamvault.app.ui.screens.player.overlay.PlayerControlsOverlay
+import com.streamvault.app.ui.screens.player.overlay.PlayerResolutionBadge
+import com.streamvault.app.ui.screens.player.overlay.PlayerSleepTimerWarningOverlay
import com.streamvault.domain.model.Channel
import com.streamvault.domain.model.Program
+import com.streamvault.domain.model.RecordingStatus
+import com.streamvault.domain.model.VideoFormat
+import com.streamvault.player.PLAYER_TRACK_AUTO_ID
import com.streamvault.player.PlayerEngine
+import com.streamvault.player.PlayerTrack
/**
* Owns the player controls' high-frequency transport state at the overlay boundary.
@@ -19,6 +49,7 @@ import com.streamvault.player.PlayerEngine
@Composable
internal fun PlayerControlsOverlayHost(
playerEngine: PlayerEngine,
+ viewModel: PlayerViewModel,
visible: Boolean,
title: String,
contentType: String,
@@ -30,30 +61,9 @@ internal fun PlayerControlsOverlayHost(
currentChannelName: String?,
displayChannelNumber: Int,
aspectRatioLabel: String,
- subtitleTrackCount: Int,
- liveTranslationAvailable: Boolean,
- audioTrackCount: Int,
- videoQualityCount: Int,
- currentRecordingStatus: com.streamvault.domain.model.RecordingStatus?,
- isMuted: Boolean,
- playbackSpeed: Float,
- mediaTitle: String?,
- sleepTimerUiState: SleepTimerUiState,
- timeshiftUiState: PlayerTimeshiftUiState,
playButtonFocusRequester: FocusRequester,
quickActionsFocusRequester: FocusRequester,
- onClose: () -> Unit,
- onTogglePlayPause: () -> Unit,
- onSeekBackward: () -> Unit,
- onSeekForward: () -> Unit,
- onRestartProgram: () -> Unit,
onOpenArchive: () -> Unit,
- onStartRecording: () -> Unit,
- onStopRecording: () -> Unit,
- onScheduleRecording: () -> Unit,
- onScheduleDailyRecording: () -> Unit,
- onScheduleWeeklyRecording: () -> Unit,
- onToggleAspectRatio: () -> Unit,
onOpenSubtitleTracks: () -> Unit,
onOpenAudioTracks: () -> Unit,
onOpenVideoTracks: () -> Unit,
@@ -61,24 +71,28 @@ internal fun PlayerControlsOverlayHost(
onOpenStopPlaybackTimer: () -> Unit,
onOpenIdleStandbyTimer: () -> Unit,
onOpenAudioVideoSync: () -> Unit,
- audioVideoSyncEnabled: Boolean,
showEpisodesAction: Boolean,
onOpenEpisodes: () -> Unit,
onOpenSplitScreen: () -> Unit,
onEnterPictureInPicture: () -> Unit,
- onToggleMute: () -> Unit,
- isCastConnected: Boolean,
- onCast: () -> Unit,
- onStopCasting: () -> Unit,
- onSeekToLiveEdge: () -> Unit,
- onSeekToPosition: (Long) -> Unit,
- onSetScrubbingMode: (Boolean) -> Unit,
- seekPreview: SeekPreviewState,
- onSeekPreviewPositionChanged: (Long?) -> Unit,
- onUserInteraction: () -> Unit
+ onRunRecordingAction: (() -> Unit) -> Unit,
+ onOpenCastRouteChooser: () -> Unit
) {
val currentPosition by playerEngine.currentPosition.collectAsStateWithLifecycle()
val duration by playerEngine.duration.collectAsStateWithLifecycle()
+ val availableAudioTracks by viewModel.availableAudioTracks.collectAsStateWithLifecycle()
+ val availableSubtitleTracks by viewModel.availableSubtitleTracks.collectAsStateWithLifecycle()
+ val availableVideoQualities by viewModel.availableVideoQualities.collectAsStateWithLifecycle()
+ val liveTranslationAvailable by viewModel.liveTranslationAvailable.collectAsStateWithLifecycle()
+ val currentChannelRecording by viewModel.currentChannelRecording.collectAsStateWithLifecycle()
+ val isMuted by viewModel.isMuted.collectAsStateWithLifecycle()
+ val mediaTitle by viewModel.mediaTitle.collectAsStateWithLifecycle()
+ val playbackSpeed by viewModel.playbackSpeed.collectAsStateWithLifecycle()
+ val audioVideoSyncEnabled by viewModel.audioVideoSyncEnabled.collectAsStateWithLifecycle()
+ val castConnectionState by viewModel.castConnectionState.collectAsStateWithLifecycle()
+ val seekPreview by viewModel.seekPreview.collectAsStateWithLifecycle()
+ val timeshiftUiState by viewModel.timeshiftUiState.collectAsStateWithLifecycle()
+ val sleepTimerUiState by viewModel.sleepTimerUiState.collectAsStateWithLifecycle()
PlayerControlsOverlay(
visible = visible,
@@ -93,11 +107,11 @@ internal fun PlayerControlsOverlayHost(
currentPosition = currentPosition,
duration = duration,
aspectRatioLabel = aspectRatioLabel,
- subtitleTrackCount = subtitleTrackCount,
+ subtitleTrackCount = availableSubtitleTracks.size,
liveTranslationAvailable = liveTranslationAvailable,
- audioTrackCount = audioTrackCount,
- videoQualityCount = videoQualityCount,
- currentRecordingStatus = currentRecordingStatus,
+ audioTrackCount = availableAudioTracks.size,
+ videoQualityCount = availableVideoQualities.size,
+ currentRecordingStatus = currentChannelRecording?.status,
isMuted = isMuted,
playbackSpeed = playbackSpeed,
mediaTitle = mediaTitle,
@@ -106,18 +120,18 @@ internal fun PlayerControlsOverlayHost(
playButtonFocusRequester = playButtonFocusRequester,
quickActionsFocusRequester = quickActionsFocusRequester,
modifier = modifier,
- onClose = onClose,
- onTogglePlayPause = onTogglePlayPause,
- onSeekBackward = onSeekBackward,
- onSeekForward = onSeekForward,
- onRestartProgram = onRestartProgram,
+ onClose = viewModel::toggleControls,
+ onTogglePlayPause = { if (isPlaying) viewModel.pause() else viewModel.play() },
+ onSeekBackward = viewModel::seekBackward,
+ onSeekForward = viewModel::seekForward,
+ onRestartProgram = viewModel::restartCurrentProgram,
onOpenArchive = onOpenArchive,
- onStartRecording = onStartRecording,
- onStopRecording = onStopRecording,
- onScheduleRecording = onScheduleRecording,
- onScheduleDailyRecording = onScheduleDailyRecording,
- onScheduleWeeklyRecording = onScheduleWeeklyRecording,
- onToggleAspectRatio = onToggleAspectRatio,
+ onStartRecording = { onRunRecordingAction(viewModel::startManualRecording) },
+ onStopRecording = viewModel::stopCurrentRecording,
+ onScheduleRecording = { onRunRecordingAction(viewModel::scheduleRecording) },
+ onScheduleDailyRecording = { onRunRecordingAction(viewModel::scheduleDailyRecording) },
+ onScheduleWeeklyRecording = { onRunRecordingAction(viewModel::scheduleWeeklyRecording) },
+ onToggleAspectRatio = viewModel::toggleAspectRatio,
onOpenSubtitleTracks = onOpenSubtitleTracks,
onOpenAudioTracks = onOpenAudioTracks,
onOpenVideoTracks = onOpenVideoTracks,
@@ -130,15 +144,125 @@ internal fun PlayerControlsOverlayHost(
onOpenEpisodes = onOpenEpisodes,
onOpenSplitScreen = onOpenSplitScreen,
onEnterPictureInPicture = onEnterPictureInPicture,
- onToggleMute = onToggleMute,
- isCastConnected = isCastConnected,
- onCast = onCast,
- onStopCasting = onStopCasting,
- onSeekToLiveEdge = onSeekToLiveEdge,
- onSeekToPosition = onSeekToPosition,
- onSetScrubbingMode = onSetScrubbingMode,
+ onToggleMute = viewModel::toggleMute,
+ isCastConnected = castConnectionState == CastConnectionState.CONNECTED,
+ onCast = { viewModel.castCurrentMedia(onOpenCastRouteChooser) },
+ onStopCasting = viewModel::stopCasting,
+ onSeekToLiveEdge = viewModel::seekToLiveEdge,
+ onSeekToPosition = viewModel::seekTo,
+ onSetScrubbingMode = viewModel::setScrubbingMode,
seekPreview = seekPreview,
- onSeekPreviewPositionChanged = onSeekPreviewPositionChanged,
- onUserInteraction = onUserInteraction
+ onSeekPreviewPositionChanged = viewModel::updateSeekPreview,
+ onUserInteraction = {
+ viewModel.notifyUserActivity()
+ viewModel.refreshControlsAutoHide()
+ }
)
}
+
+@Composable
+internal fun PlayerRecordingIndicatorHost(
+ viewModel: PlayerViewModel,
+ modifier: Modifier = Modifier
+) {
+ val currentChannelRecording by viewModel.currentChannelRecording.collectAsStateWithLifecycle()
+ if (currentChannelRecording?.status != RecordingStatus.RECORDING) return
+
+ val recordingPulse = rememberInfiniteTransition(label = "recordingPulse")
+ val recordingAlpha by recordingPulse.animateFloat(
+ initialValue = 1f,
+ targetValue = 0.2f,
+ animationSpec = infiniteRepeatable(
+ animation = tween(durationMillis = 750),
+ repeatMode = RepeatMode.Reverse
+ ),
+ label = "recordingAlpha"
+ )
+ Row(
+ modifier = modifier
+ .background(Color.Black.copy(alpha = 0.58f), RoundedCornerShape(999.dp))
+ .padding(horizontal = 12.dp, vertical = 7.dp),
+ horizontalArrangement = Arrangement.spacedBy(8.dp),
+ verticalAlignment = Alignment.CenterVertically
+ ) {
+ Box(
+ modifier = Modifier
+ .size(10.dp)
+ .background(Color(0xFFFF4D4F).copy(alpha = recordingAlpha), RoundedCornerShape(999.dp))
+ )
+ Text(
+ text = stringResource(R.string.settings_recording_status_recording),
+ style = MaterialTheme.typography.labelMedium,
+ color = Color.White
+ )
+ }
+}
+
+@Composable
+internal fun PlayerSleepTimerWarningHost(
+ viewModel: PlayerViewModel,
+ isInPictureInPictureMode: Boolean,
+ modifier: Modifier = Modifier
+) {
+ if (isInPictureInPictureMode) return
+ val sleepTimerUiState by viewModel.sleepTimerUiState.collectAsStateWithLifecycle()
+ PlayerSleepTimerWarningOverlay(
+ state = sleepTimerUiState,
+ modifier = modifier,
+ onExtendStopTimer = viewModel::extendStopPlaybackTimer,
+ onDisableStopTimer = viewModel::disableStopPlaybackTimer,
+ onExtendIdleTimer = viewModel::extendIdleStandbyTimer,
+ onDisableIdleTimer = viewModel::disableIdleStandbyTimer
+ )
+}
+
+@Composable
+internal fun PlayerResolutionBadgeHost(
+ viewModel: PlayerViewModel,
+ streamUrl: String,
+ videoFormat: VideoFormat,
+ controlsVisible: Boolean,
+ modifier: Modifier = Modifier
+) {
+ val videoTracks by viewModel.availableVideoQualities.collectAsStateWithLifecycle()
+ val resolutionBadgeLabel = buildResolutionBadgeLabel(
+ videoFormat = videoFormat,
+ videoTracks = videoTracks,
+ autoResolutionLabel = stringResource(R.string.player_resolution_auto_label, videoFormat.resolutionLabel)
+ )
+ var showResolution by remember(streamUrl) { mutableStateOf(false) }
+ var lastResolutionBadgeLabel by remember(streamUrl) { mutableStateOf<String?>(null) }
+
+ LaunchedEffect(resolutionBadgeLabel) {
+ val nextLabel = resolutionBadgeLabel ?: run {
+ showResolution = false
+ lastResolutionBadgeLabel = null
+ return@LaunchedEffect
+ }
+ if (nextLabel == lastResolutionBadgeLabel) return@LaunchedEffect
+ lastResolutionBadgeLabel = nextLabel
+ showResolution = true
+ kotlinx.coroutines.delay(3000)
+ if (lastResolutionBadgeLabel == nextLabel) showResolution = false
+ }
+
+ PlayerResolutionBadge(
+ visible = showResolution && !controlsVisible && resolutionBadgeLabel != null,
+ resolutionLabel = resolutionBadgeLabel.orEmpty(),
+ modifier = modifier
+ )
+}
+
+private fun buildResolutionBadgeLabel(
+ videoFormat: VideoFormat,
+ videoTracks: List<PlayerTrack>,
+ autoResolutionLabel: String
+): String? {
+ if (videoFormat.isEmpty) return null
+ val selectedTrack = videoTracks.firstOrNull(PlayerTrack::isSelected)
+ return if (selectedTrack == null || selectedTrack.id == PLAYER_TRACK_AUTO_ID) {
+ autoResolutionLabel
+ } else {
+ selectedTrack.name
+ }
+}
diff --git a/app/src/main/java/com/streamvault/app/ui/screens/player/PlayerDiagnosticsHost.kt b/app/src/main/java/com/streamvault/app/ui/screens/player/PlayerDiagnosticsHost.kt
new file mode 100644
index 00000000..1006e3b4
--- /dev/null
+++ b/app/src/main/java/com/streamvault/app/ui/screens/player/PlayerDiagnosticsHost.kt
@@ -0,0 +1,26 @@
+package com.streamvault.app.ui.screens.player
+
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.getValue
+import androidx.compose.ui.Modifier
+import androidx.lifecycle.compose.collectAsStateWithLifecycle
+import com.streamvault.app.ui.screens.player.overlay.DiagnosticsOverlay
+
+/** Collects diagnostics only while the diagnostics overlay can be rendered. */
+@Composable
+internal fun PlayerDiagnosticsHost(
+ viewModel: PlayerViewModel,
+ visible: Boolean,
+ isInPictureInPictureMode: Boolean,
+ modifier: Modifier = Modifier
+) {
+ if (!visible || isInPictureInPictureMode) return
+
+ val playerStats by viewModel.playerStats.collectAsStateWithLifecycle()
+ val playerDiagnostics by viewModel.playerDiagnostics.collectAsStateWithLifecycle()
+ DiagnosticsOverlay(
+ stats = playerStats,
+ diagnostics = playerDiagnostics,
+ modifier = modifier
+ )
+}
diff --git a/app/src/main/java/com/streamvault/app/ui/screens/player/PlayerLiveOverlayHost.kt b/app/src/main/java/com/streamvault/app/ui/screens/player/PlayerLiveOverlayHost.kt
new file mode 100644
index 00000000..f3bbe7a1
--- /dev/null
+++ b/app/src/main/java/com/streamvault/app/ui/screens/player/PlayerLiveOverlayHost.kt
@@ -0,0 +1,234 @@
+package com.streamvault.app.ui.screens.player
+
+import androidx.compose.animation.AnimatedVisibility
+import androidx.compose.animation.fadeIn
+import androidx.compose.animation.fadeOut
+import androidx.compose.animation.slideInHorizontally
+import androidx.compose.animation.slideInVertically
+import androidx.compose.animation.slideOutHorizontally
+import androidx.compose.animation.slideOutVertically
+import androidx.compose.foundation.focusGroup
+import androidx.compose.foundation.layout.BoxScope
+import androidx.compose.foundation.layout.fillMaxHeight
+import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.foundation.layout.padding
+import androidx.compose.foundation.layout.width
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.getValue
+import androidx.compose.ui.Alignment
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.focus.FocusRequester
+import androidx.compose.ui.unit.Dp
+import androidx.lifecycle.compose.collectAsStateWithLifecycle
+import com.streamvault.app.cast.CastConnectionState
+import com.streamvault.app.ui.screens.player.overlay.ChannelInfoOverlay
+import com.streamvault.app.ui.screens.player.overlay.ChannelListOverlay
+import com.streamvault.app.ui.screens.player.overlay.CategoryListOverlay
+import com.streamvault.app.ui.screens.player.overlay.EpgOverlay
+import com.streamvault.app.ui.screens.player.overlay.PlayerNumericInputOverlay
+import com.streamvault.domain.model.Channel
+import com.streamvault.domain.model.Program
+import com.streamvault.domain.model.VideoFormat
+import com.streamvault.player.TrackType
+
+/** Keeps live-only flow reads and overlays outside the player screen coordinator. */
+@Composable
+internal fun PlayerNumericInputOverlayHost(
+ viewModel: PlayerViewModel,
+ visible: Boolean,
+ modifier: Modifier = Modifier
+) {
+ if (!visible) return
+ val numericChannelInput by viewModel.numericChannelInput.collectAsStateWithLifecycle()
+ PlayerNumericInputOverlay(
+ state = numericChannelInput,
+ visible = visible,
+ modifier = modifier
+ )
+}
+
+@Composable
+internal fun BoxScope.PlayerLiveOverlayHost(
+ viewModel: PlayerViewModel,
+ isRtl: Boolean,
+ sideOverlayWidth: Dp,
+ epgOverlayWidth: Dp,
+ showChannelListOverlay: Boolean,
+ showCategoryListOverlay: Boolean,
+ showEpgOverlay: Boolean,
+ showChannelInfoOverlay: Boolean,
+ currentChannel: Channel?,
+ internalChannelId: Long,
+ displayChannelNumber: Int,
+ currentProgram: Program?,
+ nextProgram: Program?,
+ channelListFocusRequester: FocusRequester,
+ categoryListFocusRequester: FocusRequester,
+ channelInfoFocusRequester: FocusRequester,
+ isPlaying: Boolean,
+ aspectRatioLabel: String,
+ showDiagnostics: Boolean,
+ videoFormat: VideoFormat,
+ onOpenModal: (PlayerModal) -> Unit,
+ onEnterPictureInPicture: () -> Unit,
+ onRunRecordingAction: (() -> Unit) -> Unit,
+ onOpenCastRouteChooser: () -> Unit,
+ onTransientPanelVisibilityChanged: (Boolean) -> Unit
+) {
+ val availableCategories by viewModel.availableCategories.collectAsStateWithLifecycle()
+ val parentalControlLevel by viewModel.parentalControlLevel.collectAsStateWithLifecycle()
+ val activeCategoryId by viewModel.activeCategoryId.collectAsStateWithLifecycle()
+ val currentChannelList by viewModel.currentChannelList.collectAsStateWithLifecycle()
+ val recentChannels by viewModel.recentChannels.collectAsStateWithLifecycle()
+ val lastVisitedCategory by viewModel.lastVisitedCategory.collectAsStateWithLifecycle()
+ val upcomingPrograms by viewModel.upcomingPrograms.collectAsStateWithLifecycle()
+
+ AnimatedVisibility(
+ visible = showChannelListOverlay,
+ enter = slideInHorizontally(initialOffsetX = { if (isRtl) it else -it }),
+ exit = slideOutHorizontally(targetOffsetX = { if (isRtl) it else -it }),
+ modifier = Modifier
+ .align(if (isRtl) Alignment.TopEnd else Alignment.TopStart)
+ .fillMaxHeight()
+ .width(sideOverlayWidth)
+ .focusGroup()
+ ) {
+ ChannelListOverlay(
+ channels = currentChannelList,
+ recentChannels = recentChannels,
+ currentChannelId = currentChannel?.id ?: internalChannelId,
+ overlayFocusRequester = channelListFocusRequester,
+ lastVisitedCategoryName = lastVisitedCategory?.name,
+ onOpenLastGroup = viewModel::openLastVisitedCategory,
+ onSelectChannel = viewModel::zapToChannel,
+ onOpenCategories = viewModel::openCategoryListOverlay,
+ onDismiss = viewModel::closeOverlays,
+ onOverlayInteracted = viewModel::onLiveOverlayInteraction
+ )
+ }
+
+ AnimatedVisibility(
+ visible = showCategoryListOverlay,
+ enter = slideInHorizontally(initialOffsetX = { if (isRtl) it else -it }),
+ exit = slideOutHorizontally(targetOffsetX = { if (isRtl) it else -it }),
+ modifier = Modifier
+ .align(if (isRtl) Alignment.TopEnd else Alignment.TopStart)
+ .fillMaxHeight()
+ .width(sideOverlayWidth)
+ .focusGroup()
+ ) {
+ CategoryListOverlay(
+ categories = availableCategories,
+ currentCategoryId = activeCategoryId,
+ overlayFocusRequester = categoryListFocusRequester,
+ isCategoryLocked = { category ->
+ parentalControlLevel in 1..2 && (category.isAdult || category.isUserProtected)
+ },
+ onSelectCategory = viewModel::selectCategoryFromOverlay,
+ onDismiss = viewModel::closeOverlays,
+ onOverlayInteracted = viewModel::onLiveOverlayInteraction
+ )
+ }
+
+ AnimatedVisibility(
+ visible = showEpgOverlay,
+ enter = slideInHorizontally(initialOffsetX = { if (isRtl) -it else it }),
+ exit = slideOutHorizontally(targetOffsetX = { if (isRtl) -it else it }),
+ modifier = Modifier
+ .align(if (isRtl) Alignment.TopStart else Alignment.TopEnd)
+ .fillMaxHeight()
+ .width(epgOverlayWidth)
+ .focusGroup()
+ ) {
+ EpgOverlay(
+ currentChannel = currentChannel,
+ displayChannelNumber = displayChannelNumber,
+ currentProgram = currentProgram,
+ nextProgram = nextProgram,
+ upcomingPrograms = upcomingPrograms,
+ onDismiss = viewModel::closeOverlays,
+ onOpenArchiveBrowser = {
+ onOpenModal(PlayerModal.ProgramHistory)
+ viewModel.closeOverlays()
+ },
+ onOverlayInteracted = viewModel::onLiveOverlayInteraction
+ )
+ }
+
+ AnimatedVisibility(
+ visible = showChannelInfoOverlay,
+ enter = slideInVertically(initialOffsetY = { it }) + fadeIn(),
+ exit = slideOutVertically(targetOffsetY = { it }) + fadeOut(),
+ modifier = Modifier
+ .align(Alignment.BottomCenter)
+ .fillMaxWidth()
+ .focusGroup()
+ ) {
+ val availableAudioTracks by viewModel.availableAudioTracks.collectAsStateWithLifecycle()
+ val availableSubtitleTracks by viewModel.availableSubtitleTracks.collectAsStateWithLifecycle()
+ val availableVideoQualities by viewModel.availableVideoQualities.collectAsStateWithLifecycle()
+ val liveTranslationAvailable by viewModel.liveTranslationAvailable.collectAsStateWithLifecycle()
+ val currentChannelRecording by viewModel.currentChannelRecording.collectAsStateWithLifecycle()
+ val isMuted by viewModel.isMuted.collectAsStateWithLifecycle()
+ val audioVideoSyncEnabled by viewModel.audioVideoSyncEnabled.collectAsStateWithLifecycle()
+ val castConnectionState by viewModel.castConnectionState.collectAsStateWithLifecycle()
+ val timeshiftUiState by viewModel.timeshiftUiState.collectAsStateWithLifecycle()
+
+ ChannelInfoOverlay(
+ currentChannel = currentChannel,
+ displayChannelNumber = displayChannelNumber,
+ currentProgram = currentProgram,
+ nextProgram = nextProgram,
+ focusRequester = channelInfoFocusRequester,
+ lastVisitedCategoryName = lastVisitedCategory?.name,
+ onDismiss = viewModel::closeChannelInfoOverlay,
+ onOverlayInteracted = viewModel::onLiveOverlayInteraction,
+ onOpenFullEpg = {
+ viewModel.closeChannelInfoOverlay()
+ viewModel.openEpgOverlay()
+ },
+ onOpenLastGroup = {
+ viewModel.closeChannelInfoOverlay()
+ viewModel.openLastVisitedCategory()
+ },
+ currentRecordingStatus = currentChannelRecording?.status,
+ onStartRecording = { onRunRecordingAction(viewModel::startManualRecording) },
+ onStopRecording = viewModel::stopCurrentRecording,
+ onScheduleRecording = { onRunRecordingAction(viewModel::scheduleRecording) },
+ onScheduleDailyRecording = { onRunRecordingAction(viewModel::scheduleDailyRecording) },
+ onScheduleWeeklyRecording = { onRunRecordingAction(viewModel::scheduleWeeklyRecording) },
+ onRestartProgram = viewModel::restartCurrentProgram,
+ onOpenArchive = { onOpenModal(PlayerModal.ProgramHistory) },
+ onToggleAspectRatio = viewModel::toggleAspectRatio,
+ onToggleDiagnostics = viewModel::toggleDiagnostics,
+ onTogglePlayPause = { if (isPlaying) viewModel.pause() else viewModel.play() },
+ onSeekBackward = viewModel::seekBackward,
+ onSeekForward = viewModel::seekForward,
+ onSeekToLiveEdge = viewModel::seekToLiveEdge,
+ isPlaying = isPlaying,
+ currentAspectRatio = aspectRatioLabel,
+ isDiagnosticsEnabled = showDiagnostics,
+ onOpenSplitScreen = { onOpenModal(PlayerModal.Split) },
+ subtitleTrackCount = availableSubtitleTracks.size,
+ liveTranslationAvailable = liveTranslationAvailable,
+ audioTrackCount = availableAudioTracks.size,
+ videoQualityCount = availableVideoQualities.size,
+ channelVariantCount = currentChannel?.variants?.size ?: 0,
+ isMuted = isMuted,
+ onToggleMute = viewModel::toggleMute,
+ onOpenSubtitleTracks = { onOpenModal(PlayerModal.TrackSelection(TrackType.TEXT)) },
+ onOpenAudioTracks = { onOpenModal(PlayerModal.TrackSelection(TrackType.AUDIO)) },
+ onOpenVideoTracks = { onOpenModal(PlayerModal.TrackSelection(TrackType.VIDEO)) },
+ onOpenVariants = { onOpenModal(PlayerModal.VariantSelection) },
+ onOpenAudioVideoSync = { onOpenModal(PlayerModal.AudioVideoOffset) },
+ audioVideoSyncEnabled = audioVideoSyncEnabled,
+ onEnterPictureInPicture = onEnterPictureInPicture,
+ isCastConnected = castConnectionState == CastConnectionState.CONNECTED,
+ onCast = { viewModel.castCurrentMedia(onOpenCastRouteChooser) },
+ onStopCasting = viewModel::stopCasting,
+ timeshiftUiState = timeshiftUiState,
+ onTransientPanelVisibilityChanged = onTransientPanelVisibilityChanged,
+ resolutionLabel = videoFormat.resolutionLabel.takeIf { it.isNotBlank() && !videoFormat.isEmpty }
+ )
+ }
+}
diff --git a/app/src/main/java/com/streamvault/app/ui/screens/player/PlayerModalHosts.kt b/app/src/main/java/com/streamvault/app/ui/screens/player/PlayerModalHosts.kt
index a17f2133..14d73494 100644
--- a/app/src/main/java/com/streamvault/app/ui/screens/player/PlayerModalHosts.kt
+++ b/app/src/main/java/com/streamvault/app/ui/screens/player/PlayerModalHosts.kt
@@ -1,7 +1,12 @@
package com.streamvault.app.ui.screens.player
import androidx.compose.runtime.Composable
+import androidx.compose.runtime.LaunchedEffect
+import androidx.compose.runtime.getValue
import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel
+import androidx.lifecycle.compose.collectAsStateWithLifecycle
+import androidx.compose.ui.res.stringResource
+import com.streamvault.app.R
import com.streamvault.app.ui.components.dialogs.ProgramHistoryDialog
import com.streamvault.app.ui.screens.multiview.MultiViewPlannerDialog
import com.streamvault.app.ui.screens.multiview.MultiViewViewModel
@@ -15,7 +20,6 @@ import com.streamvault.domain.model.Channel
import com.streamvault.domain.model.Episode
import com.streamvault.domain.model.Program
import com.streamvault.domain.model.Season
-import com.streamvault.player.PlayerTrack
import com.streamvault.player.TrackType
@Composable
@@ -51,54 +55,39 @@ internal fun PlayerTopLevelModalHost(
@Composable
internal fun PlayerControlsModalHost(
+ viewModel: PlayerViewModel,
isInPictureInPictureMode: Boolean,
showTrackSelection: TrackType?,
- availableAudioTracks: List<PlayerTrack>,
- availableSubtitleTracks: List<PlayerTrack>,
- availableVideoQualities: List<PlayerTrack>,
- liveTranslationAvailable: Boolean,
- liveTranslationActive: Boolean,
- onDismissTrackSelection: () -> Unit,
- onSelectAudio: (String) -> Unit,
- onSelectVideo: (String) -> Unit,
- onSelectSubtitle: (String?) -> Unit,
- onSelectLiveTranslation: () -> Unit,
showVariantSelection: Boolean,
currentChannel: Channel?,
- onDismissVariantSelection: () -> Unit,
- onSelectVariant: (Long) -> Unit,
showSpeedSelection: Boolean,
- playbackSpeed: Float,
- onDismissSpeedSelection: () -> Unit,
- onSelectSpeed: (Float) -> Unit,
showStopPlaybackTimerDialog: Boolean,
- stopPlaybackTimerTitle: String,
- stopPlaybackTimerMinutes: Int,
- onDismissStopPlaybackTimer: () -> Unit,
- onSelectStopPlaybackTimer: (Int) -> Unit,
showIdleStandbyTimerDialog: Boolean,
- idleStandbyTimerTitle: String,
- idleStandbyTimerMinutes: Int,
- onDismissIdleStandbyTimer: () -> Unit,
- onSelectIdleStandbyTimer: (Int) -> Unit,
- audioVideoOffsetVisible: Boolean,
- audioVideoOffsetState: PlayerAudioVideoOffsetUiState,
canSaveChannel: Boolean,
- onDismissAudioVideoOffset: () -> Unit,
- onAdjustAudioVideoOffset: (Int) -> Unit,
- onResetAudioVideoOffset: () -> Unit,
- onSaveAudioVideoOffsetForChannel: () -> Unit,
- onSaveAudioVideoOffsetAsGlobal: () -> Unit,
- onUseGlobalAudioVideoOffset: () -> Unit,
+ showAudioVideoOffsetDialog: Boolean,
showEpisodePicker: Boolean,
seriesTitle: String,
seasons: List<Season>,
currentEpisodeId: Long,
currentSeasonNumber: Int?,
- onDismissEpisodePicker: () -> Unit,
- onSelectEpisode: (Episode) -> Unit,
+ onDismissModal: () -> Unit,
) {
- if (!isInPictureInPictureMode) {
+ if (showAudioVideoOffsetDialog) {
+ val audioVideoSyncEnabled by viewModel.audioVideoSyncEnabled.collectAsStateWithLifecycle()
+ LaunchedEffect(audioVideoSyncEnabled) {
+ if (!audioVideoSyncEnabled) {
+ onDismissModal()
+ viewModel.dismissAudioVideoOffsetPreview()
+ }
+ }
+ }
+
+ if (!isInPictureInPictureMode && showTrackSelection != null) {
+ val availableAudioTracks by viewModel.availableAudioTracks.collectAsStateWithLifecycle()
+ val availableSubtitleTracks by viewModel.availableSubtitleTracks.collectAsStateWithLifecycle()
+ val availableVideoQualities by viewModel.availableVideoQualities.collectAsStateWithLifecycle()
+ val liveTranslationAvailable by viewModel.liveTranslationAvailable.collectAsStateWithLifecycle()
+ val liveTranslationActive by viewModel.liveTranslationActive.collectAsStateWithLifecycle()
PlayerTrackSelectionDialog(
trackType = showTrackSelection,
audioTracks = availableAudioTracks,
@@ -106,57 +95,95 @@ internal fun PlayerControlsModalHost(
videoTracks = availableVideoQualities,
liveTranslationAvailable = liveTranslationAvailable,
liveTranslationActive = liveTranslationActive,
- onDismiss = onDismissTrackSelection,
- onSelectAudio = onSelectAudio,
- onSelectVideo = onSelectVideo,
- onSelectSubtitle = onSelectSubtitle,
- onSelectLiveTranslation = onSelectLiveTranslation
+ onDismiss = onDismissModal,
+ onSelectAudio = viewModel::selectAudioTrack,
+ onSelectVideo = viewModel::selectVideoQuality,
+ onSelectSubtitle = { trackId ->
+ viewModel.deactivateLiveTranslation()
+ viewModel.selectSubtitleTrack(trackId)
+ },
+ onSelectLiveTranslation = {
+ viewModel.selectSubtitleTrack(null)
+ viewModel.activateLiveTranslation()
+ }
)
+ }
+ if (!isInPictureInPictureMode && showVariantSelection) {
ChannelVariantSelectionDialog(
- visible = showVariantSelection,
+ visible = true,
channel = currentChannel,
- onDismiss = onDismissVariantSelection,
- onSelectVariant = onSelectVariant
+ onDismiss = onDismissModal,
+ onSelectVariant = viewModel::selectLiveVariant
)
+ }
+ if (!isInPictureInPictureMode && showSpeedSelection) {
+ val playbackSpeed by viewModel.playbackSpeed.collectAsStateWithLifecycle()
PlayerSpeedSelectionDialog(
- visible = showSpeedSelection,
+ visible = true,
selectedSpeed = playbackSpeed,
- onDismiss = onDismissSpeedSelection,
- onSelectSpeed = onSelectSpeed
+ onDismiss = onDismissModal,
+ onSelectSpeed = viewModel::setPlaybackSpeed
)
+ }
+ if (!isInPictureInPictureMode && showStopPlaybackTimerDialog) {
+ val sleepTimerUiState by viewModel.sleepTimerUiState.collectAsStateWithLifecycle()
PlayerSleepTimerDialog(
- visible = showStopPlaybackTimerDialog,
- title = stopPlaybackTimerTitle,
- selectedMinutes = stopPlaybackTimerMinutes,
- onDismiss = onDismissStopPlaybackTimer,
- onSelectMinutes = onSelectStopPlaybackTimer
+ visible = true,
+ title = stringResource(R.string.player_stop_playback_after),
+ selectedMinutes = sleepTimerUiState.stopTimerMinutes,
+ onDismiss = onDismissModal,
+ onSelectMinutes = { minutes ->
+ viewModel.notifyUserActivity()
+ viewModel.setStopPlaybackTimer(minutes)
+ onDismissModal()
+ }
)
+ }
+ if (!isInPictureInPictureMode && showIdleStandbyTimerDialog) {
+ val sleepTimerUiState by viewModel.sleepTimerUiState.collectAsStateWithLifecycle()
PlayerSleepTimerDialog(
- visible = showIdleStandbyTimerDialog,
- title = idleStandbyTimerTitle,
- selectedMinutes = idleStandbyTimerMinutes,
- onDismiss = onDismissIdleStandbyTimer,
- onSelectMinutes = onSelectIdleStandbyTimer
+ visible = true,
+ title = stringResource(R.string.player_idle_standby_after),
+ selectedMinutes = sleepTimerUiState.idleTimerMinutes,
+ onDismiss = onDismissModal,
+ onSelectMinutes = { minutes ->
+ viewModel.notifyUserActivity()
+ viewModel.setIdleStandbyTimer(minutes)
+ onDismissModal()
+ }
)
+ }
+ if (!isInPictureInPictureMode && showAudioVideoOffsetDialog) {
+ val audioVideoSyncEnabled by viewModel.audioVideoSyncEnabled.collectAsStateWithLifecycle()
+ val audioVideoOffsetState by viewModel.audioVideoOffsetUiState.collectAsStateWithLifecycle()
+ val castConnectionState by viewModel.castConnectionState.collectAsStateWithLifecycle()
PlayerAudioVideoOffsetDialog(
- visible = audioVideoOffsetVisible,
+ visible = audioVideoSyncEnabled && castConnectionState != com.streamvault.app.cast.CastConnectionState.CONNECTED,
state = audioVideoOffsetState,
canSaveChannel = canSaveChannel,
- onDismiss = onDismissAudioVideoOffset,
- onAdjust = onAdjustAudioVideoOffset,
- onReset = onResetAudioVideoOffset,
- onSaveForChannel = onSaveAudioVideoOffsetForChannel,
- onSaveAsGlobal = onSaveAudioVideoOffsetAsGlobal,
- onUseGlobal = onUseGlobalAudioVideoOffset
+ onDismiss = {
+ onDismissModal()
+ viewModel.dismissAudioVideoOffsetPreview()
+ },
+ onAdjust = viewModel::adjustAudioVideoOffset,
+ onReset = viewModel::resetAudioVideoOffsetPreview,
+ onSaveForChannel = viewModel::saveAudioVideoOffsetForChannel,
+ onSaveAsGlobal = viewModel::saveAudioVideoOffsetAsGlobal,
+ onUseGlobal = viewModel::useGlobalAudioVideoOffset
)
+ }
+ if (!isInPictureInPictureMode && showEpisodePicker) {
PlayerEpisodeSelectionDialog(
- visible = showEpisodePicker,
+ visible = true,
seriesTitle = seriesTitle,
seasons = seasons,
currentEpisodeId = currentEpisodeId,
currentSeasonNumber = currentSeasonNumber,
- onDismiss = onDismissEpisodePicker,
- onSelectEpisode = onSelectEpisode
+ onDismiss = onDismissModal,
+ onSelectEpisode = { episode ->
+ onDismissModal()
+ viewModel.playEpisode(episode)
+ }
)
}
}
diff --git a/app/src/main/java/com/streamvault/app/ui/screens/player/PlayerScreen.kt b/app/src/main/java/com/streamvault/app/ui/screens/player/PlayerScreen.kt
index fb6a90e6..5591025b 100644
--- a/app/src/main/java/com/streamvault/app/ui/screens/player/PlayerScreen.kt
+++ b/app/src/main/java/com/streamvault/app/ui/screens/player/PlayerScreen.kt
@@ -174,38 +174,13 @@ fun PlayerScreen(
val isCatchUpPlayback by viewModel.isCatchUpPlayback.collectAsStateWithLifecycle()
val showChannelListOverlay by viewModel.showChannelListOverlay.collectAsStateWithLifecycle()
val showCategoryListOverlay by viewModel.showCategoryListOverlay.collectAsStateWithLifecycle()
- val availableCategories by viewModel.availableCategories.collectAsStateWithLifecycle()
- val parentalControlLevel by viewModel.parentalControlLevel.collectAsStateWithLifecycle()
- val activeCategoryId by viewModel.activeCategoryId.collectAsStateWithLifecycle()
val showEpgOverlay by viewModel.showEpgOverlay.collectAsStateWithLifecycle()
- val currentChannelList by viewModel.currentChannelList.collectAsStateWithLifecycle()
- val recentChannels by viewModel.recentChannels.collectAsStateWithLifecycle()
- val lastVisitedCategory by viewModel.lastVisitedCategory.collectAsStateWithLifecycle()
val displayChannelNumber by viewModel.displayChannelNumber.collectAsStateWithLifecycle()
- val upcomingPrograms by viewModel.upcomingPrograms.collectAsStateWithLifecycle()
val showChannelInfoOverlay by viewModel.showChannelInfoOverlay.collectAsStateWithLifecycle()
- val numericChannelInput by viewModel.numericChannelInput.collectAsStateWithLifecycle()
-
- val availableAudioTracks by viewModel.availableAudioTracks.collectAsStateWithLifecycle()
- val availableSubtitleTracks by viewModel.availableSubtitleTracks.collectAsStateWithLifecycle()
- val availableVideoQualities by viewModel.availableVideoQualities.collectAsStateWithLifecycle()
- val liveTranslationAvailable by viewModel.liveTranslationAvailable.collectAsStateWithLifecycle()
- val liveTranslationActive by viewModel.liveTranslationActive.collectAsStateWithLifecycle()
val aspectRatio by viewModel.aspectRatio.collectAsStateWithLifecycle()
val showDiagnostics by viewModel.showDiagnostics.collectAsStateWithLifecycle()
- val playerDiagnostics by viewModel.playerDiagnostics.collectAsStateWithLifecycle()
val playerNotice by viewModel.playerNotice.collectAsStateWithLifecycle()
- val currentChannelRecording by viewModel.currentChannelRecording.collectAsStateWithLifecycle()
- val isMuted by viewModel.isMuted.collectAsStateWithLifecycle()
- val mediaTitle by viewModel.mediaTitle.collectAsStateWithLifecycle()
- val playbackSpeed by viewModel.playbackSpeed.collectAsStateWithLifecycle()
- val audioVideoSyncEnabled by viewModel.audioVideoSyncEnabled.collectAsStateWithLifecycle()
- val audioVideoOffsetState by viewModel.audioVideoOffsetUiState.collectAsStateWithLifecycle()
- val castConnectionState by viewModel.castConnectionState.collectAsStateWithLifecycle()
- val seekPreview by viewModel.seekPreview.collectAsStateWithLifecycle()
val preventStandbyDuringPlayback by viewModel.preventStandbyDuringPlayback.collectAsStateWithLifecycle()
- val timeshiftUiState by viewModel.timeshiftUiState.collectAsStateWithLifecycle()
- val sleepTimerUiState by viewModel.sleepTimerUiState.collectAsStateWithLifecycle()
val sleepTimerExitEvent by viewModel.sleepTimerExitEvent.collectAsStateWithLifecycle()
var modalState by remember { mutableStateOf(PlayerModalState()) }
@@ -249,13 +224,6 @@ fun PlayerScreen(
}
}
- LaunchedEffect(audioVideoSyncEnabled) {
- if (!audioVideoSyncEnabled && modalState.showAudioVideoOffsetDialog) {
- modalState = modalState.dismiss()
- viewModel.dismissAudioVideoOffsetPreview()
- }
- }
-
PlayerLifecycleHost(
mainActivity = mainActivity,
playbackState = playbackState,
@@ -290,31 +258,6 @@ fun PlayerScreen(
}
}
- val resolutionBadgeLabel = buildResolutionBadgeLabel(
- videoFormat = videoFormat,
- videoTracks = availableVideoQualities,
- autoResolutionLabel = stringResource(R.string.player_resolution_auto_label, videoFormat.resolutionLabel)
- )
- var showResolution by remember(streamUrl) { mutableStateOf(false) }
- var lastResolutionBadgeLabel by remember(streamUrl) { mutableStateOf<String?>(null) }
-
- LaunchedEffect(resolutionBadgeLabel) {
- val nextLabel = resolutionBadgeLabel ?: run {
- showResolution = false
- lastResolutionBadgeLabel = null
- return@LaunchedEffect
- }
- if (nextLabel == lastResolutionBadgeLabel) {
- return@LaunchedEffect
- }
- lastResolutionBadgeLabel = nextLabel
- showResolution = true
- delay(3000)
- if (lastResolutionBadgeLabel == nextLabel) {
- showResolution = false
- }
- }
-
LaunchedEffect(
playbackState,
videoFormat.width,
@@ -726,39 +669,12 @@ fun PlayerScreen(
)
}
- if (currentChannelRecording?.status == com.streamvault.domain.model.RecordingStatus.RECORDING) {
- val recordingPulse = rememberInfiniteTransition(label = "recordingPulse")
- val recordingAlpha by recordingPulse.animateFloat(
- initialValue = 1f,
- targetValue = 0.2f,
- animationSpec = infiniteRepeatable(
- animation = tween(durationMillis = 750),
- repeatMode = RepeatMode.Reverse
- ),
- label = "recordingAlpha"
- )
- Row(
- modifier = Modifier
- .align(Alignment.TopStart)
- .padding(start = 18.dp, top = 18.dp)
- .background(Color.Black.copy(alpha = 0.58f), RoundedCornerShape(999.dp))
- .padding(horizontal = 12.dp, vertical = 7.dp),
- horizontalArrangement = Arrangement.spacedBy(8.dp),
- verticalAlignment = Alignment.CenterVertically
- ) {
- Box(
- modifier = Modifier
- .size(10.dp)
- .background(Color(0xFFFF4D4F).copy(alpha = recordingAlpha), RoundedCornerShape(999.dp))
- )
- Text(
- text = stringResource(R.string.settings_recording_status_recording),
- style = MaterialTheme.typography.labelMedium,
- color = Color.White,
- fontWeight = FontWeight.Bold
- )
- }
- }
+ PlayerRecordingIndicatorHost(
+ viewModel = viewModel,
+ modifier = Modifier
+ .align(Alignment.TopStart)
+ .padding(start = 18.dp, top = 18.dp)
+ )
when (val resolutionState = playbackResolutionUiState) {
PlaybackResolutionUiState.Resolving -> Box(
@@ -798,6 +714,7 @@ fun PlayerScreen(
PlayerControlsOverlayHost(
playerEngine = playerEngine,
+ viewModel = viewModel,
visible = showControls,
title = playbackTitle.ifBlank { title },
contentType = contentType,
@@ -808,47 +725,10 @@ fun PlayerScreen(
currentChannelName = currentChannel?.name,
displayChannelNumber = displayChannelNumber,
aspectRatioLabel = aspectRatio.modeName,
- subtitleTrackCount = availableSubtitleTracks.size,
- liveTranslationAvailable = liveTranslationAvailable,
- audioTrackCount = availableAudioTracks.size,
- videoQualityCount = availableVideoQualities.size,
- currentRecordingStatus = currentChannelRecording?.status,
- isMuted = isMuted,
- playbackSpeed = playbackSpeed,
- mediaTitle = mediaTitle,
- sleepTimerUiState = sleepTimerUiState,
- timeshiftUiState = timeshiftUiState,
playButtonFocusRequester = playButtonFocusRequester,
quickActionsFocusRequester = quickActionsFocusRequester,
modifier = Modifier.fillMaxSize(),
- onClose = viewModel::toggleControls,
- onTogglePlayPause = { if (isPlaying) viewModel.pause() else viewModel.play() },
- onSeekBackward = viewModel::seekBackward,
- onSeekForward = viewModel::seekForward,
- onRestartProgram = viewModel::restartCurrentProgram,
onOpenArchive = { modalState = modalState.open(PlayerModal.ProgramHistory) },
- onStartRecording = {
- notificationPermissionGate.runRecordingAction {
- viewModel.startManualRecording()
- }
- },
- onStopRecording = viewModel::stopCurrentRecording,
- onScheduleRecording = {
- notificationPermissionGate.runRecordingAction {
- viewModel.scheduleRecording()
- }
- },
- onScheduleDailyRecording = {
- notificationPermissionGate.runRecordingAction {
- viewModel.scheduleDailyRecording()
- }
- },
- onScheduleWeeklyRecording = {
- notificationPermissionGate.runRecordingAction {
- viewModel.scheduleWeeklyRecording()
- }
- },
- onToggleAspectRatio = viewModel::toggleAspectRatio,
onOpenSubtitleTracks = { modalState = modalState.open(PlayerModal.TrackSelection(TrackType.TEXT)) },
onOpenAudioTracks = { modalState = modalState.open(PlayerModal.TrackSelection(TrackType.AUDIO)) },
onOpenVideoTracks = { modalState = modalState.open(PlayerModal.TrackSelection(TrackType.VIDEO)) },
@@ -856,28 +736,16 @@ fun PlayerScreen(
onOpenStopPlaybackTimer = { modalState = modalState.open(PlayerModal.StopPlaybackTimer) },
onOpenIdleStandbyTimer = { modalState = modalState.open(PlayerModal.IdleStandbyTimer) },
onOpenAudioVideoSync = { modalState = modalState.open(PlayerModal.AudioVideoOffset) },
- audioVideoSyncEnabled = audioVideoSyncEnabled,
showEpisodesAction = canOpenEpisodePicker,
onOpenEpisodes = { modalState = modalState.open(PlayerModal.EpisodePicker) },
onOpenSplitScreen = { modalState = modalState.open(PlayerModal.Split) },
onEnterPictureInPicture = enterPictureInPicture,
- onToggleMute = viewModel::toggleMute,
- isCastConnected = castConnectionState == CastConnectionState.CONNECTED,
- onCast = { viewModel.castCurrentMedia { mainActivity?.openCastRouteChooser() } },
- onStopCasting = viewModel::stopCasting,
- onSeekToLiveEdge = viewModel::seekToLiveEdge,
- onSeekToPosition = viewModel::seekTo,
- onSetScrubbingMode = viewModel::setScrubbingMode,
- seekPreview = seekPreview,
- onSeekPreviewPositionChanged = viewModel::updateSeekPreview,
- onUserInteraction = {
- viewModel.notifyUserActivity()
- viewModel.refreshControlsAutoHide()
- }
+ onRunRecordingAction = notificationPermissionGate::runRecordingAction,
+ onOpenCastRouteChooser = { mainActivity?.openCastRouteChooser() }
)
- PlayerNumericInputOverlay(
- state = numericChannelInput,
+ PlayerNumericInputOverlayHost(
+ viewModel = viewModel,
visible = contentType == "LIVE" && !showControls,
modifier = Modifier
.align(Alignment.TopCenter)
@@ -892,26 +760,23 @@ fun PlayerScreen(
.padding(top = 32.dp)
)
- PlayerResolutionBadge(
- visible = showResolution && !showControls && resolutionBadgeLabel != null,
- resolutionLabel = resolutionBadgeLabel.orEmpty(),
+ PlayerResolutionBadgeHost(
+ viewModel = viewModel,
+ streamUrl = streamUrl,
+ videoFormat = videoFormat,
+ controlsVisible = showControls,
modifier = Modifier
.align(Alignment.TopEnd)
.padding(32.dp)
)
- if (!isInPictureInPictureMode) {
- PlayerSleepTimerWarningOverlay(
- state = sleepTimerUiState,
- modifier = Modifier
- .align(Alignment.TopCenter)
- .padding(top = 88.dp),
- onExtendStopTimer = { viewModel.extendStopPlaybackTimer() },
- onDisableStopTimer = viewModel::disableStopPlaybackTimer,
- onExtendIdleTimer = { viewModel.extendIdleStandbyTimer() },
- onDisableIdleTimer = viewModel::disableIdleStandbyTimer
- )
- }
+ PlayerSleepTimerWarningHost(
+ viewModel = viewModel,
+ isInPictureInPictureMode = isInPictureInPictureMode,
+ modifier = Modifier
+ .align(Alignment.TopCenter)
+ .padding(top = 88.dp)
+ )
// Auto-Play Next Episode countdown overlay
val countdownState = autoPlayCountdown
@@ -940,243 +805,59 @@ fun PlayerScreen(
}
PlayerControlsModalHost(
+ viewModel = viewModel,
isInPictureInPictureMode = isInPictureInPictureMode,
showTrackSelection = modalState.trackSelection,
- availableAudioTracks = availableAudioTracks,
- availableSubtitleTracks = availableSubtitleTracks,
- availableVideoQualities = availableVideoQualities,
- liveTranslationAvailable = liveTranslationAvailable,
- liveTranslationActive = liveTranslationActive,
- onDismissTrackSelection = { modalState = modalState.dismiss() },
- onSelectAudio = viewModel::selectAudioTrack,
- onSelectVideo = viewModel::selectVideoQuality,
- onSelectSubtitle = { trackId ->
- viewModel.deactivateLiveTranslation()
- viewModel.selectSubtitleTrack(trackId)
- },
- onSelectLiveTranslation = {
- viewModel.selectSubtitleTrack(null)
- viewModel.activateLiveTranslation()
- },
showVariantSelection = modalState.showVariantSelection,
currentChannel = currentChannel,
- onDismissVariantSelection = { modalState = modalState.dismiss() },
- onSelectVariant = viewModel::selectLiveVariant,
showSpeedSelection = modalState.showSpeedSelection,
- playbackSpeed = playbackSpeed,
- onDismissSpeedSelection = { modalState = modalState.dismiss() },
- onSelectSpeed = viewModel::setPlaybackSpeed,
showStopPlaybackTimerDialog = modalState.showStopPlaybackTimerDialog,
- stopPlaybackTimerTitle = stringResource(R.string.player_stop_playback_after),
- stopPlaybackTimerMinutes = sleepTimerUiState.stopTimerMinutes,
- onDismissStopPlaybackTimer = { modalState = modalState.dismiss() },
- onSelectStopPlaybackTimer = { minutes ->
- viewModel.notifyUserActivity()
- viewModel.setStopPlaybackTimer(minutes)
- modalState = modalState.dismiss()
- },
showIdleStandbyTimerDialog = modalState.showIdleStandbyTimerDialog,
- idleStandbyTimerTitle = stringResource(R.string.player_idle_standby_after),
- idleStandbyTimerMinutes = sleepTimerUiState.idleTimerMinutes,
- onDismissIdleStandbyTimer = { modalState = modalState.dismiss() },
- onSelectIdleStandbyTimer = { minutes ->
- viewModel.notifyUserActivity()
- viewModel.setIdleStandbyTimer(minutes)
- modalState = modalState.dismiss()
- },
- audioVideoOffsetVisible = modalState.showAudioVideoOffsetDialog &&
- audioVideoSyncEnabled &&
- castConnectionState != CastConnectionState.CONNECTED,
- audioVideoOffsetState = audioVideoOffsetState,
canSaveChannel = currentChannel != null,
- onDismissAudioVideoOffset = {
- modalState = modalState.dismiss()
- viewModel.dismissAudioVideoOffsetPreview()
- },
- onAdjustAudioVideoOffset = viewModel::adjustAudioVideoOffset,
- onResetAudioVideoOffset = viewModel::resetAudioVideoOffsetPreview,
- onSaveAudioVideoOffsetForChannel = viewModel::saveAudioVideoOffsetForChannel,
- onSaveAudioVideoOffsetAsGlobal = viewModel::saveAudioVideoOffsetAsGlobal,
- onUseGlobalAudioVideoOffset = viewModel::useGlobalAudioVideoOffset,
+ showAudioVideoOffsetDialog = modalState.showAudioVideoOffsetDialog,
showEpisodePicker = modalState.showEpisodePicker,
seriesTitle = currentSeries?.name ?: playbackTitle.ifBlank { title },
seasons = currentSeriesSeasons.orEmpty(),
currentEpisodeId = currentEpisode?.id ?: internalChannelId,
currentSeasonNumber = currentEpisode?.seasonNumber ?: seasonNumber,
- onDismissEpisodePicker = { modalState = modalState.dismiss() },
- onSelectEpisode = { episode ->
- modalState = modalState.dismiss()
- viewModel.playEpisode(episode)
- }
+ onDismissModal = { modalState = modalState.dismiss() }
)
// --- Overlays ---
- if (!isInPictureInPictureMode && showDiagnostics) {
- val playerStats by viewModel.playerStats.collectAsStateWithLifecycle()
- DiagnosticsOverlay(
- stats = playerStats,
- diagnostics = playerDiagnostics,
- modifier = Modifier.align(Alignment.TopStart).padding(32.dp)
- )
- }
-
+ PlayerDiagnosticsHost(
+ viewModel = viewModel,
+ visible = showDiagnostics,
+ isInPictureInPictureMode = isInPictureInPictureMode,
+ modifier = Modifier.align(Alignment.TopStart).padding(32.dp)
+ )
if (contentType == "LIVE") {
- AnimatedVisibility(
- visible = showChannelListOverlay,
- enter = slideInHorizontally(initialOffsetX = { if (isRtl) it else -it }),
- exit = slideOutHorizontally(targetOffsetX = { if (isRtl) it else -it }),
- modifier = Modifier
- .align(if (isRtl) Alignment.TopEnd else Alignment.TopStart)
- .fillMaxHeight()
- .width(sideOverlayWidth)
- .focusGroup()
- ) {
- ChannelListOverlay(
- channels = currentChannelList,
- recentChannels = recentChannels,
- currentChannelId = currentChannel?.id ?: internalChannelId,
- overlayFocusRequester = channelListFocusRequester,
- lastVisitedCategoryName = lastVisitedCategory?.name,
- onOpenLastGroup = { viewModel.openLastVisitedCategory() },
- onSelectChannel = { channelId -> viewModel.zapToChannel(channelId) },
- onOpenCategories = { viewModel.openCategoryListOverlay() },
- onDismiss = { viewModel.closeOverlays() },
- onOverlayInteracted = viewModel::onLiveOverlayInteraction
- )
- }
-
- AnimatedVisibility(
- visible = showCategoryListOverlay,
- enter = slideInHorizontally(initialOffsetX = { if (isRtl) it else -it }),
- exit = slideOutHorizontally(targetOffsetX = { if (isRtl) it else -it }),
- modifier = Modifier
- .align(if (isRtl) Alignment.TopEnd else Alignment.TopStart)
- .fillMaxHeight()
- .width(sideOverlayWidth)
- .focusGroup()
- ) {
- CategoryListOverlay(
- categories = availableCategories,
- currentCategoryId = activeCategoryId,
- overlayFocusRequester = categoryListFocusRequester,
- isCategoryLocked = { category ->
- parentalControlLevel in 1..2 && (category.isAdult || category.isUserProtected)
- },
- onSelectCategory = { category ->
- viewModel.selectCategoryFromOverlay(category)
- },
- onDismiss = { viewModel.closeOverlays() },
- onOverlayInteracted = viewModel::onLiveOverlayInteraction
- )
- }
-
- AnimatedVisibility(
- visible = showEpgOverlay,
- enter = slideInHorizontally(initialOffsetX = { if (isRtl) -it else it }),
- exit = slideOutHorizontally(targetOffsetX = { if (isRtl) -it else it }),
- modifier = Modifier
- .align(if (isRtl) Alignment.TopStart else Alignment.TopEnd)
- .fillMaxHeight()
- .width(epgOverlayWidth)
- .focusGroup()
- ) {
- EpgOverlay(
- currentChannel = currentChannel,
- displayChannelNumber = displayChannelNumber,
- currentProgram = currentProgram,
- nextProgram = nextProgram,
- upcomingPrograms = upcomingPrograms,
- onDismiss = { viewModel.closeOverlays() },
- onOpenArchiveBrowser = {
- modalState = modalState.open(PlayerModal.ProgramHistory)
- viewModel.closeOverlays()
- },
- onOverlayInteracted = viewModel::onLiveOverlayInteraction
- )
- }
-
- AnimatedVisibility(
- visible = showChannelInfoOverlay,
- enter = slideInVertically(initialOffsetY = { it }) + fadeIn(),
- exit = slideOutVertically(targetOffsetY = { it }) + fadeOut(),
- modifier = Modifier
- .align(Alignment.BottomCenter)
- .fillMaxWidth()
- .focusGroup()
- ) {
- ChannelInfoOverlay(
- currentChannel = currentChannel,
- displayChannelNumber = displayChannelNumber,
- currentProgram = currentProgram,
- nextProgram = nextProgram,
- focusRequester = channelInfoFocusRequester,
- lastVisitedCategoryName = lastVisitedCategory?.name,
- onDismiss = { viewModel.closeChannelInfoOverlay() },
- onOverlayInteracted = viewModel::onLiveOverlayInteraction,
- onOpenFullEpg = {
- viewModel.closeChannelInfoOverlay()
- viewModel.openEpgOverlay()
- },
- onOpenLastGroup = {
- viewModel.closeChannelInfoOverlay()
- viewModel.openLastVisitedCategory()
- },
- currentRecordingStatus = currentChannelRecording?.status,
- onStartRecording = {
- notificationPermissionGate.runRecordingAction {
- viewModel.startManualRecording()
- }
- },
- onStopRecording = viewModel::stopCurrentRecording,
- onScheduleRecording = {
- notificationPermissionGate.runRecordingAction {
- viewModel.scheduleRecording()
- }
- },
- onScheduleDailyRecording = {
- notificationPermissionGate.runRecordingAction {
- viewModel.scheduleDailyRecording()
- }
- },
- onScheduleWeeklyRecording = {
- notificationPermissionGate.runRecordingAction {
- viewModel.scheduleWeeklyRecording()
- }
- },
- onRestartProgram = { viewModel.restartCurrentProgram() },
- onOpenArchive = { modalState = modalState.open(PlayerModal.ProgramHistory) },
- onToggleAspectRatio = { viewModel.toggleAspectRatio() },
- onToggleDiagnostics = { viewModel.toggleDiagnostics() },
- onTogglePlayPause = { if (isPlaying) viewModel.pause() else viewModel.play() },
- onSeekBackward = viewModel::seekBackward,
- onSeekForward = viewModel::seekForward,
- onSeekToLiveEdge = viewModel::seekToLiveEdge,
- isPlaying = isPlaying,
- currentAspectRatio = aspectRatio.modeName,
- isDiagnosticsEnabled = showDiagnostics,
- onOpenSplitScreen = { modalState = modalState.open(PlayerModal.Split) },
- subtitleTrackCount = availableSubtitleTracks.size,
- liveTranslationAvailable = liveTranslationAvailable,
- audioTrackCount = availableAudioTracks.size,
- videoQualityCount = availableVideoQualities.size,
- channelVariantCount = currentChannel?.variants?.size ?: 0,
- isMuted = isMuted,
- onToggleMute = viewModel::toggleMute,
- onOpenSubtitleTracks = { modalState = modalState.open(PlayerModal.TrackSelection(TrackType.TEXT)) },
- onOpenAudioTracks = { modalState = modalState.open(PlayerModal.TrackSelection(TrackType.AUDIO)) },
- onOpenVideoTracks = { modalState = modalState.open(PlayerModal.TrackSelection(TrackType.VIDEO)) },
- onOpenVariants = { modalState = modalState.open(PlayerModal.VariantSelection) },
- onOpenAudioVideoSync = { modalState = modalState.open(PlayerModal.AudioVideoOffset) },
- audioVideoSyncEnabled = audioVideoSyncEnabled,
- onEnterPictureInPicture = enterPictureInPicture,
- isCastConnected = castConnectionState == CastConnectionState.CONNECTED,
- onCast = { viewModel.castCurrentMedia { mainActivity?.openCastRouteChooser() } },
- onStopCasting = viewModel::stopCasting,
- timeshiftUiState = timeshiftUiState,
- onTransientPanelVisibilityChanged = { channelInfoSubPanelOpen = it },
- resolutionLabel = videoFormat.resolutionLabel.takeIf { it.isNotBlank() && !videoFormat.isEmpty }
- )
- }
+ PlayerLiveOverlayHost(
+ viewModel = viewModel,
+ isRtl = isRtl,
+ sideOverlayWidth = sideOverlayWidth,
+ epgOverlayWidth = epgOverlayWidth,
+ showChannelListOverlay = showChannelListOverlay,
+ showCategoryListOverlay = showCategoryListOverlay,
+ showEpgOverlay = showEpgOverlay,
+ showChannelInfoOverlay = showChannelInfoOverlay,
+ currentChannel = currentChannel,
+ internalChannelId = internalChannelId,
+ displayChannelNumber = displayChannelNumber,
+ currentProgram = currentProgram,
+ nextProgram = nextProgram,
+ channelListFocusRequester = channelListFocusRequester,
+ categoryListFocusRequester = categoryListFocusRequester,
+ channelInfoFocusRequester = channelInfoFocusRequester,
+ isPlaying = isPlaying,
+ aspectRatioLabel = aspectRatio.modeName,
+ showDiagnostics = showDiagnostics,
+ videoFormat = videoFormat,
+ onOpenModal = { modal -> modalState = modalState.open(modal) },
+ onEnterPictureInPicture = enterPictureInPicture,
+ onRunRecordingAction = notificationPermissionGate::runRecordingAction,
+ onOpenCastRouteChooser = { mainActivity?.openCastRouteChooser() },
+ onTransientPanelVisibilityChanged = { channelInfoSubPanelOpen = it }
+ )
}
}
}
@@ -1213,20 +894,6 @@ private fun AspectRatio.toPlayerSurfaceResizeMode(): PlayerSurfaceResizeMode = w
AspectRatio.ZOOM -> PlayerSurfaceResizeMode.ZOOM
}
-private fun buildResolutionBadgeLabel(
- videoFormat: VideoFormat,
- videoTracks: List<PlayerTrack>,
- autoResolutionLabel: String
-): String? {
- if (videoFormat.isEmpty) return null
- val selectedTrack = videoTracks.firstOrNull(PlayerTrack::isSelected)
- return if (selectedTrack == null || selectedTrack.id == PLAYER_TRACK_AUTO_ID) {
- autoResolutionLabel
- } else {
- selectedTrack.name
- }
-}
-
private tailrec fun android.content.Context.findMainActivity(): MainActivity? = when (this) {
is MainActivity -> this
is android.content.ContextWrapper -> baseContext.findMainActivity()