Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -1941,6 +1941,7 @@ fun TvPlayerScreen(
// playback seeks the MediaController directly.
transportEnabled = canSeekInRoom,
playPauseEnabled = canPlayPauseInRoom,
canToggleAfterCommit = roomController == null,
onSkipBack = {
if (canSeekInRoom) {
performRelativeSeek(
Expand Down Expand Up @@ -2285,10 +2286,29 @@ private fun TvPlayerIdleOverlay(
// play/pause (host_only policy) gets a no-op play/pause.
transportEnabled: Boolean = true,
playPauseEnabled: Boolean = true,
/**
* Whether Center may toggle playback after committing a scrub.
*
* False in a Watch Together room. There, the commit and the play/pause are
* two independently launched room requests, and the play/pause carries the
* live position rather than the committed one — so it can land after the
* seek and pull every participant back to where the scrub started. Solo
* playback applies both locally and in order, so it keeps the behaviour.
*/
canToggleAfterCommit: Boolean = true,
) {
val scrubberFocus = remember { FocusRequester() }
val playPauseFocus = remember { FocusRequester() }
var idleOverlayHasFocus by remember { mutableStateOf(false) }
// Observed per ROW, not for the overlay as a whole. `idleOverlayHasFocus` is
// hasFocus on the overlay's root, so it is already true whenever ANY control
// holds focus — including the scrubber. Using it as the arrival test made
// every request from inside the overlay a no-op: D-pad Down on the scrub bar
// asks for the transport, the retry loop sees "already focused" and never
// requests, and focus stays on the bar. That is why reaching the controls
// needed a Back (which hides the overlay, clearing the flag) before Down.
var scrubberHasFocus by remember { mutableStateOf(false) }
var transportHasFocus by remember { mutableStateOf(false) }
var currentRate by remember { mutableStateOf(0) }
LaunchedEffect(focusRequest.nonce) {
val overlayTarget = when (focusRequest.target) {
Expand All @@ -2299,7 +2319,12 @@ private fun TvPlayerIdleOverlay(
maxAttempts = TvContentInitialFocusMaxAttempts,
awaitAttempt = { withFrameNanos { } },
requestFocus = overlayTarget::requestFocus,
isFocused = { idleOverlayHasFocus },
isFocused = {
when (focusRequest.target) {
TvIdleOverlayFocusTarget.Scrubber -> scrubberHasFocus
TvIdleOverlayFocusTarget.Transport -> transportHasFocus
}
},
)
}

Expand Down Expand Up @@ -2369,6 +2394,7 @@ private fun TvPlayerIdleOverlay(
// Interactive scrubber — capsule track with chapter ticks, ±10s
// skip, hold-to-auto-seek, and Select to commit. tvOS spec §4.1.
TvPlayerScrubber(
modifier = Modifier.onFocusChanged { scrubberHasFocus = it.hasFocus },
positionSec = positionSec,
durationSec = durationSec,
bufferedAheadSec = bufferedAheadSec,
Expand All @@ -2391,6 +2417,8 @@ private fun TvPlayerIdleOverlay(
onCommitScrub = onCommitScrub,
onCancelScrub = onCancelScrub,
onRequestFocus = scrubberFocus,
onPlayPause = onPlayPause,
canToggleAfterCommit = canToggleAfterCommit,
onMoveDownToTransport = {
playPauseFocus.claimFocusOrReport(
target = "player_transport",
Expand All @@ -2404,6 +2432,7 @@ private fun TvPlayerIdleOverlay(
Spacer(modifier = Modifier.height(8.dp))

TvPlayerTransportCluster(
modifier = Modifier.onFocusChanged { transportHasFocus = it.hasFocus },
isPlaying = !isPaused,
onSkipBack = onSkipBack,
onPlayPause = onPlayPause,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,16 @@ fun TvPlayerScrubber(
onCommitScrub: () -> Unit,
onCancelScrub: () -> Unit,
onRequestFocus: FocusRequester,
/**
* Toggle play/pause. Center on the bar is bound to this, not to entering a
* scrub: the Google TV remote has no dedicated play/pause key, so Center
* with the overlay up is the only one-press pause a viewer has — and it is
* what every other TV player does. Scrubbing does not need it; Left/Right
* skip and long-press engages auto-seek.
*/
onPlayPause: () -> Unit,
/** See TvPlayerIdleOverlay.canToggleAfterCommit. */
canToggleAfterCommit: Boolean = true,
onMoveDownToTransport: () -> Unit,
onExitWhenIdle: () -> Unit,
onRateChanged: (Int) -> Unit = {},
Expand Down Expand Up @@ -347,13 +357,21 @@ fun TvPlayerScrubber(
Key.DirectionCenter, Key.Enter, Key.NumPadEnter -> {
if (isUp) {
stopAutoSeek()
if (isTimelineScrubbing || isScrubbing) {
// Center means "here": land any scrub in
// flight, then flip playback. Racing forward at
// 32x it stops on the frame you asked for;
// hunting a spot while paused it plays on from
// it. Entering a scrub MODE here — what this
// used to do — spent the viewer's only
// one-press pause on something Left/Right
// already do, and the Google TV remote has no
// dedicated play/pause key to fall back on.
val committed = isTimelineScrubbing || isScrubbing
if (committed) {
isTimelineScrubbing = false
onCommitScrub()
} else {
onBeginScrub()
isTimelineScrubbing = true
}
if (!committed || canToggleAfterCommit) onPlayPause()
true
} else if (isDown) true else false
}
Expand Down