From 6ad4de4a4ba7ff1a54e29eeca2da85c23f5af799 Mon Sep 17 00:00:00 2001 From: Rhainland Date: Wed, 18 Nov 2026 11:04:01 +0100 Subject: [PATCH 1/2] fix(player): time Up Next from the end of the file, not the credits marker The Show Next Up setting offers "At end" and "N seconds before end", but on an episode with a credits marker both apps opened the card at the credits start whatever was chosen. The TV player never read the setting at all. Both players now open Up Next when playback crosses the chosen number of seconds before the end of the file, and only when the stream ends for "At end", as the iOS and tvOS player already does. Credits markers still drive Skip Credits; skipping credits that run to the end ends the stream, which opens the card. The TV settings screen now assumes the same 30-second default as the settings store and the server. Fixes #910 --- .../ui/screens/player/PlayerViewModel.kt | 38 ++++++++----------- ...erViewModelLoadOwnershipIntegrationTest.kt | 30 +++++++++++++++ .../tv/ui/screens/player/TvPlayerViewModel.kt | 32 +++++++++------- .../screens/settings/TvSettingsViewModel.kt | 2 +- .../silo/domain/player/MarkerTimeline.kt | 15 -------- .../silo/domain/player/NextUpPrompt.kt | 25 ++++++++++++ .../silo/domain/player/MarkerTimelineTest.kt | 12 ------ .../silo/domain/player/NextUpPromptTest.kt | 26 +++++++++++++ 8 files changed, 117 insertions(+), 63 deletions(-) create mode 100644 shared/src/commonMain/kotlin/org/siloserver/silo/domain/player/NextUpPrompt.kt create mode 100644 shared/src/commonTest/kotlin/org/siloserver/silo/domain/player/NextUpPromptTest.kt diff --git a/androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/screens/player/PlayerViewModel.kt b/androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/screens/player/PlayerViewModel.kt index 1c4aa77d21..2b3a174bd4 100644 --- a/androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/screens/player/PlayerViewModel.kt +++ b/androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/screens/player/PlayerViewModel.kt @@ -94,6 +94,7 @@ import org.siloserver.silo.model.catalog.FileVersion import org.siloserver.silo.model.catalog.VersionChapter import org.siloserver.silo.domain.player.MarkerKind import org.siloserver.silo.domain.player.MarkerTimeline +import org.siloserver.silo.domain.player.NextUpPrompt import org.siloserver.silo.model.catalog.MarkerSegment import org.siloserver.silo.model.catalog.TimeRange import org.siloserver.silo.model.settings.SubtitleAppearance @@ -1036,8 +1037,7 @@ class PlayerViewModel( .stateIn(viewModelScope, SharingStarted.Eagerly, IntroSkipMode.Default) val autoPlayNextEnabled: StateFlow = playerSettingsStore.autoPlayNextFlow .stateIn(viewModelScope, SharingStarted.Eagerly, true) - // Seconds before end to surface the Up Next card when no credits marker - // exists (0 = only at end). Credits marker wins when present. + // Seconds before the end of the file to surface Up Next (0 = only at end). private val nextUpPromptSeconds: StateFlow = playerSettingsStore.nextUpPromptSecondsFlow .stateIn(viewModelScope, SharingStarted.Eagerly, 30) @@ -3304,22 +3304,16 @@ class PlayerViewModel( ) } - // F2: surface the Up Next card when playback CROSSES the credits point - // (only on the before->after transition, so resuming inside the credits - // doesn't instantly trigger it). Without a credits marker, fall back to - // crossing (duration - nextUpPromptSeconds); 0 = only at end (iOS parity). - if (!seekWasActive) { - val creditsStart = _uiState.value.markerTimeline.upNextCreditsStart() - if (creditsStart != null) { - if (previousPosition < creditsStart && positionSec >= creditsStart) onApproachingEnd() - } else { - val promptSeconds = nextUpPromptSeconds.value - val duration = _uiState.value.duration - if (promptSeconds > 0 && duration > 0) { - val promptStart = duration - promptSeconds - if (previousPosition < promptStart && positionSec >= promptStart) onApproachingEnd() - } - } + // Surface Up Next when playback crosses the chosen point before the end + // of the file. Only the crossing counts, so resuming or seeking past it + // doesn't open the card; the stream ending still does. + if ( + !seekWasActive && + NextUpPrompt.crossesPromptPoint( + previousPosition, positionSec, _uiState.value.duration, nextUpPromptSeconds.value, + ) + ) { + onApproachingEnd() } // Forward to the lifecycle so its 10s reporter has a fresh sample. @@ -6174,12 +6168,12 @@ class PlayerViewModel( } /** - * Credits reached (primary) or stream ended (fallback) — surface the Up Next - * card. When auto-play is on and the consecutive-auto-advance streak is + * The Next Up point before the end was crossed, or the stream ended — + * surface the Up Next card. When auto-play is on and the consecutive-auto-advance streak is * below the pass-out threshold, the card runs a countdown that plays the * next episode at zero. Once the streak hits the threshold (or auto-play is * off), the card shows WITHOUT a countdown so the user must explicitly - * choose (the pass-out gate). The credits prompt is once per episode; + * choose (the pass-out gate). The before-end prompt is once per episode; * a dismissed card reopens when playback ends. * * [videoEnded] is true on STATE_ENDED — the card reads "Playing Next"; a @@ -6262,7 +6256,7 @@ class PlayerViewModel( // Two anchors (iOS parity — silo-apple's PlayerViewModel derives the // countdown from movieTime and only auto-plays once playback truly // ends): - // - Card committed BEFORE the end (credits / prompt crossing): the + // - Card committed BEFORE the end (before-end crossing): the // countdown mirrors the remaining playback time, so it freezes on // pause, grows on a backward seek, and the advance fires only when // the player reports STATE_ENDED — never truncating the tail of an diff --git a/androidApp/src/androidUnitTest/kotlin/org/siloserver/silo/android/ui/screens/player/PlayerViewModelLoadOwnershipIntegrationTest.kt b/androidApp/src/androidUnitTest/kotlin/org/siloserver/silo/android/ui/screens/player/PlayerViewModelLoadOwnershipIntegrationTest.kt index b32a921c2e..f733fadb67 100644 --- a/androidApp/src/androidUnitTest/kotlin/org/siloserver/silo/android/ui/screens/player/PlayerViewModelLoadOwnershipIntegrationTest.kt +++ b/androidApp/src/androidUnitTest/kotlin/org/siloserver/silo/android/ui/screens/player/PlayerViewModelLoadOwnershipIntegrationTest.kt @@ -456,6 +456,36 @@ class PlayerViewModelLoadOwnershipIntegrationTest { } } + @Test + fun nextUpOpensAtThePromptSecondsBeforeTheFileEndNotAtTheCreditsMarker() = runTest(dispatcher) { + val starter = DeferredNonCooperativeStarter() + val fixture = playerViewModel(starter, backgroundScope) + val store = ViewModelStore().also { it.put("player", fixture.viewModel) } + try { + val viewModel = fixture.viewModel + viewModel.loadContent("episode-a", preferredFileId = 1) + starter.awaitRequestCount(1) + starter.complete(0, ready(starter.request(0), "session-a")) + viewModel.awaitState { it.sessionId == "session-a" && !it.isLoading } + viewModel.onMediaMountApplied(viewModel.uiState.value.mediaMountGeneration) + viewModel.offerNextEpisode() + viewModel.mutableUiState().update { + it.copy(credits = org.siloserver.silo.model.catalog.TimeRange(1000.0, 1200.0)) + } + + // The fake settings store chooses 30 seconds before the end. + viewModel.onPositionChanged(999_000L, 1_200_000L) + viewModel.onPositionChanged(1_001_000L, 1_200_000L) + assertFalse(viewModel.uiState.value.showUpNext) + viewModel.onPositionChanged(1_169_500L, 1_200_000L) + assertFalse(viewModel.uiState.value.showUpNext) + viewModel.onPositionChanged(1_170_500L, 1_200_000L) + assertTrue(viewModel.uiState.value.showUpNext) + } finally { + store.clear() + } + } + @Test fun keepWatchingSuppressesCreditsPromptButReopensNextUpAtPlaybackEnd() = runTest(dispatcher) { val starter = DeferredNonCooperativeStarter() diff --git a/androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/player/TvPlayerViewModel.kt b/androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/player/TvPlayerViewModel.kt index 5847428ae1..358b46aac2 100644 --- a/androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/player/TvPlayerViewModel.kt +++ b/androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/player/TvPlayerViewModel.kt @@ -109,6 +109,7 @@ import org.siloserver.silo.model.catalog.AudioTrack import org.siloserver.silo.model.catalog.FileVersion import org.siloserver.silo.domain.player.MarkerKind import org.siloserver.silo.domain.player.MarkerTimeline +import org.siloserver.silo.domain.player.NextUpPrompt import org.siloserver.silo.model.catalog.MarkerSegment import org.siloserver.silo.model.catalog.TimeRange import org.siloserver.silo.model.catalog.VersionChapter @@ -2008,6 +2009,9 @@ class TvPlayerViewModel( // Per-profile "Still watching?" threshold (default 3; 0 = off). val passOutThreshold: StateFlow = playerSettingsStore.passOutThresholdFlow .stateIn(viewModelScope, SharingStarted.Eagerly, 3) + // Seconds before the end of the file to surface Up Next (0 = only at end). + private val nextUpPromptSeconds: StateFlow = playerSettingsStore.nextUpPromptSecondsFlow + .stateIn(viewModelScope, SharingStarted.Eagerly, 30) val hdrEnabled: StateFlow = playerSettingsStore.hdrEnabledFlow .stateIn(viewModelScope, SharingStarted.Eagerly, true) val dolbyVisionEnabled: StateFlow = playerSettingsStore.dolbyVisionEnabledFlow @@ -3880,14 +3884,16 @@ class TvPlayerViewModel( if (positionSec > 0 && transientNetworkRetries > 0) { transientNetworkRetries = 0 } - // F2: auto-advance / prompt when playback CROSSES the credits point — - // only on the transition from before to after, so resuming an episode - // whose saved position is already inside the credits doesn't instantly - // skip to the next one (a seek into credits also won't trigger it). - if (!seekWasActive) { - _uiState.value.markerTimeline.upNextCreditsStart()?.let { creditsStart -> - if (previousPosition < creditsStart && positionSec >= creditsStart) onApproachingEnd() - } + // Surface Up Next when playback crosses the chosen point before the end + // of the file. Only the crossing counts, so resuming or seeking past it + // doesn't open the card; the stream ending still does. + if ( + !seekWasActive && + NextUpPrompt.crossesPromptPoint( + previousPosition, positionSec, _uiState.value.duration, nextUpPromptSeconds.value, + ) + ) { + onApproachingEnd() } // Forward to the lifecycle so its 10s reporter has a fresh sample. sessionLifecycle.reportPosition( @@ -5367,12 +5373,12 @@ class TvPlayerViewModel( * pass-out threshold, the overlay starts a countdown ring that plays the * next episode at zero. Once the streak hits the pass-out threshold (or * auto-play is off), the overlay shows with NO countdown so the user must - * explicitly choose Play Now / Keep Watching (the pass-out gate). The credits + * explicitly choose Play Now / Keep Watching (the pass-out gate). The before-end * prompt is once per episode; a dismissed card reopens when playback ends. * * [videoEnded] true when the stream has actually ended (STATE_ENDED) — the * panel reads "End of playback" / "Playing Next" and hides Keep Watching; - * false at the credits-crossing while video is still rolling. + * false at the before-end crossing while video is still rolling. */ fun onApproachingEnd(videoEnded: Boolean = false) { if (nextUpTransitionGate.isActive) return @@ -5451,7 +5457,7 @@ class TvPlayerViewModel( } /** - * Surface Up Next on demand, ahead of the credits trigger. + * Surface Up Next on demand, ahead of the before-end trigger. * * Routed through the same commit the automatic timing uses so the overlay, * the countdown gating and the auto-advance accounting behave identically — @@ -5509,7 +5515,7 @@ class TvPlayerViewModel( nextUpCountdownJob?.cancel() nextUpCountdownJob = viewModelScope.launch { // Two anchors, matching phone and tvOS: - // - Card committed BEFORE the end (credits crossing): the countdown + // - Card committed BEFORE the end (before-end crossing): the countdown // mirrors the remaining playback time, so it freezes on pause, // grows on a backward seek, and the advance fires only once the // player reports the stream ended. A fixed wall clock here cut off @@ -6614,7 +6620,7 @@ class TvPlayerViewModel( */ fun onSelectIntroPrompt(): Double? { val target = introAutoSkipController.select() ?: return null - // Pre-write the resolved source position so the credits crossing check + // Pre-write the resolved source position so the Next Up crossing check // treats this as a deliberate jump. The caller routes the actual seek // through either the room controller or seekImmediate; the latter owns // the pending-position guard for solo playback. diff --git a/androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/settings/TvSettingsViewModel.kt b/androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/settings/TvSettingsViewModel.kt index 15af51d852..7989b93d9b 100644 --- a/androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/settings/TvSettingsViewModel.kt +++ b/androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/settings/TvSettingsViewModel.kt @@ -168,7 +168,7 @@ class TvSettingsViewModel( val passOutThreshold: Int = 3, // Seconds before the end of an episode to surface the Up-Next prompt // (0 = at the very end). Mirrors tvOS `nextUpPromptSeconds`. - val nextUpPromptSeconds: Int = 10, + val nextUpPromptSeconds: Int = 30, /** * Keys this device holds its own value for. A profile-layered control * whose key is absent shows "Use profile setting" as its choice. diff --git a/shared/src/commonMain/kotlin/org/siloserver/silo/domain/player/MarkerTimeline.kt b/shared/src/commonMain/kotlin/org/siloserver/silo/domain/player/MarkerTimeline.kt index c1b7ffa5d3..d12e0f626d 100644 --- a/shared/src/commonMain/kotlin/org/siloserver/silo/domain/player/MarkerTimeline.kt +++ b/shared/src/commonMain/kotlin/org/siloserver/silo/domain/player/MarkerTimeline.kt @@ -53,21 +53,6 @@ class MarkerTimeline private constructor(private val regions: List= start - 1) start = minOf(start, range.start) - } - return start - } - companion object { val EMPTY = MarkerTimeline(emptyList()) diff --git a/shared/src/commonMain/kotlin/org/siloserver/silo/domain/player/NextUpPrompt.kt b/shared/src/commonMain/kotlin/org/siloserver/silo/domain/player/NextUpPrompt.kt new file mode 100644 index 0000000000..b5597323b6 --- /dev/null +++ b/shared/src/commonMain/kotlin/org/siloserver/silo/domain/player/NextUpPrompt.kt @@ -0,0 +1,25 @@ +package org.siloserver.silo.domain.player + +/** + * When the Up Next card opens before an episode ends: `playback.next_up_prompt_seconds` + * before the end of the file, matching iOS/tvOS (`PlayerNextUpCompletionPolicy`) and the + * web. Credits markers drive Skip Credits only; they do not move this point. + */ +object NextUpPrompt { + /** + * True when playback moves from [previousPosition] to [position] across the point + * [promptSeconds] before [duration]. Only the crossing counts, so resuming or seeking + * past that point doesn't open the card. [promptSeconds] 0 ("At end") or an unknown + * duration never opens it early; the card then waits for the stream to end. + */ + fun crossesPromptPoint( + previousPosition: Double, + position: Double, + duration: Double, + promptSeconds: Int, + ): Boolean { + if (promptSeconds <= 0 || duration <= 0) return false + val promptStart = duration - promptSeconds + return previousPosition < promptStart && position >= promptStart + } +} diff --git a/shared/src/commonTest/kotlin/org/siloserver/silo/domain/player/MarkerTimelineTest.kt b/shared/src/commonTest/kotlin/org/siloserver/silo/domain/player/MarkerTimelineTest.kt index 1c09aca187..7349fc41b5 100644 --- a/shared/src/commonTest/kotlin/org/siloserver/silo/domain/player/MarkerTimelineTest.kt +++ b/shared/src/commonTest/kotlin/org/siloserver/silo/domain/player/MarkerTimelineTest.kt @@ -87,16 +87,4 @@ class MarkerTimelineTest { assertEquals(TimeRange(30.0, 90.0), twoIntros.occurrenceAt(MarkerKind.Intro, 300.0)) assertEquals(TimeRange(600.0, 660.0), twoIntros.occurrenceAt(MarkerKind.Intro, 600.0)) } - - @Test fun upNextWaitsForTheLastCreditsRangeSoAMidCreditsScenePlays() { - assertEquals(3189.0, timeline.upNextCreditsStart()) - val touching = MarkerTimeline.resolve( - segments = listOf(MarkerSegment("credits", 1200.0, 1250.0), MarkerSegment("credits", 1250.5, 1300.0)), - intro = null, credits = null, recap = null, preview = null, - ) - assertEquals(1200.0, touching.upNextCreditsStart()) - val single = MarkerTimeline.resolve(null, intro = null, credits = TimeRange(1200.0, 1260.0), recap = null, preview = null) - assertEquals(1200.0, single.upNextCreditsStart()) - assertNull(MarkerTimeline.EMPTY.upNextCreditsStart()) - } } diff --git a/shared/src/commonTest/kotlin/org/siloserver/silo/domain/player/NextUpPromptTest.kt b/shared/src/commonTest/kotlin/org/siloserver/silo/domain/player/NextUpPromptTest.kt new file mode 100644 index 0000000000..c72ef76efb --- /dev/null +++ b/shared/src/commonTest/kotlin/org/siloserver/silo/domain/player/NextUpPromptTest.kt @@ -0,0 +1,26 @@ +package org.siloserver.silo.domain.player + +import kotlin.test.Test +import kotlin.test.assertFalse +import kotlin.test.assertTrue + +class NextUpPromptTest { + // A 48:12 episode whose credits marker starts at 46:31: the marker must + // not move the prompt (silo-android#910). + private val duration = 2892.0 + + @Test fun promptOpensWhenPlaybackCrossesTheChosenSecondsBeforeTheEnd() { + assertTrue(NextUpPrompt.crossesPromptPoint(2861.6, 2862.1, duration, promptSeconds = 30)) + assertTrue(NextUpPrompt.crossesPromptPoint(2881.5, 2882.0, duration, promptSeconds = 10)) + assertFalse(NextUpPrompt.crossesPromptPoint(2791.0, 2792.0, duration, promptSeconds = 30)) + } + + @Test fun playbackAlreadyPastThePointDoesNotReopenThePrompt() { + assertFalse(NextUpPrompt.crossesPromptPoint(2870.0, 2870.5, duration, promptSeconds = 30)) + } + + @Test fun atEndAndUnknownDurationNeverOpenBeforeTheStreamEnds() { + assertFalse(NextUpPrompt.crossesPromptPoint(2891.0, 2892.0, duration, promptSeconds = 0)) + assertFalse(NextUpPrompt.crossesPromptPoint(10.0, 11.0, 0.0, promptSeconds = 30)) + } +} From 445ca87c190423029e17cbcae34ef20ba02d9ea0 Mon Sep 17 00:00:00 2001 From: Rhainland Date: Wed, 18 Nov 2026 11:14:50 +0100 Subject: [PATCH 2/2] fix(tv): keep returning the series page to the next episode from the credits Moving Up Next to the end of the file also moved the point at which the TV player treats an episode as finished for the series page. Leaving during the closing credits then opened the series on the episode just watched, and leaving after an early prompt during the final scene opened it on the next one. Record the closing-credits crossing on its own again, and count the Up Next prompt only when the stream has ended. Update the comments that still described the credits-based trigger. --- .../ui/screens/player/PlayerViewModel.kt | 14 ++++++------- .../tv/ui/screens/player/TvPlayerScreen.kt | 4 ++-- .../tv/ui/screens/player/TvPlayerViewModel.kt | 21 +++++++++++++------ .../silo/domain/player/MarkerTimeline.kt | 15 +++++++++++++ .../silo/domain/player/NextUpPrompt.kt | 4 ++-- .../silo/domain/player/MarkerTimelineTest.kt | 12 +++++++++++ 6 files changed, 53 insertions(+), 17 deletions(-) diff --git a/androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/screens/player/PlayerViewModel.kt b/androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/screens/player/PlayerViewModel.kt index 2b3a174bd4..ccff3c7b9a 100644 --- a/androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/screens/player/PlayerViewModel.kt +++ b/androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/screens/player/PlayerViewModel.kt @@ -702,7 +702,7 @@ class PlayerViewModel( val awaitingFirstFrame: Boolean get() = startedContentId != contentId - /** The marker occurrences the skip controls and Up Next read. */ + /** The marker occurrences the skip controls read. */ val markerTimeline: MarkerTimeline by lazy { MarkerTimeline.resolve(markerSegments, intro = intro, credits = credits, recap = recap, preview = preview) } @@ -1071,7 +1071,7 @@ class PlayerViewModel( // same VM persists across episodes and the guard accumulates the streak. // The guard reads the threshold lazily so a settings change applies live. private val autoPlayGuard = AutoPlayGuard(threshold = { passOutThreshold.value }) - // Once-per-episode guard for the credits/ended trigger; reset on each load. + // Once-per-episode guard for the before-end/ended trigger; reset on each load. private var autoAdvanceHandled = false // End point fired before the next episode resolved — remember it (and the // strongest videoEnded flag seen) so resolveNextEpisode can commit the card. @@ -4822,8 +4822,8 @@ class PlayerViewModel( /** * Adopt the playing file's marker ranges (a `markers_updated` event or a - * reconcile read). The intro auto-skip observer and the credits-based F2 - * trigger read these from UiState, so updating them takes effect + * reconcile read). The intro auto-skip observer and the skip controls + * read these from UiState, so updating them takes effect * immediately. Passing `null` clears a marker the server says no longer * applies. */ @@ -6156,7 +6156,7 @@ class PlayerViewModel( it.copy(nextEpisode = info) } if (_uiState.value.contentId != forContentId) return@launch - // If the credits/end point already fired while we were still + // If the before-end/end point already fired while we were still // resolving, the card couldn't arm — commit it now with the // strongest video-ended flag observed. if (!autoAdvanceHandled) { @@ -6196,7 +6196,7 @@ class PlayerViewModel( } if (autoAdvanceHandled) { if (videoEnded) { - // Keep Watching dismisses the credits prompt, but finishing the + // Keep Watching dismisses the before-end prompt, but finishing the // episode must still offer Play Now without restarting its timer. _uiState.update { it.copy(showUpNext = true, upNextVideoEnded = true) } } @@ -6302,7 +6302,7 @@ class PlayerViewModel( /** * Up Next dismiss — cancel the countdown and stay on the current playback. - * Suppress further credits prompts; playback end still reopens the card. + * Suppress further before-end prompts; playback end still reopens the card. */ fun dismissUpNext() { if (nextUpTransitionGate.isActive) return diff --git a/androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/player/TvPlayerScreen.kt b/androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/player/TvPlayerScreen.kt index 237e656540..089fb0ba09 100644 --- a/androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/player/TvPlayerScreen.kt +++ b/androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/player/TvPlayerScreen.kt @@ -2483,7 +2483,7 @@ fun TvPlayerScreen( } else { // seekImmediate pre-writes position so a scrub // committed into the credits region isn't mistaken - // for natural playback crossing the credits point. + // for natural playback crossing the Up Next point. viewModel.seekImmediate(targetSec) } viewModel.setControlsVisible(true) @@ -2623,7 +2623,7 @@ fun TvPlayerScreen( } else { // Solo: seekImmediate pre-writes position so a // chapter jump into credits isn't mistaken for - // natural playback crossing the credits point. + // natural playback crossing the Up Next point. viewModel.seekImmediate(sec) } } diff --git a/androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/player/TvPlayerViewModel.kt b/androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/player/TvPlayerViewModel.kt index 358b46aac2..8077933766 100644 --- a/androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/player/TvPlayerViewModel.kt +++ b/androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/player/TvPlayerViewModel.kt @@ -1862,8 +1862,8 @@ class TvPlayerViewModel( // ---- Next-episode auto-advance (F2) ---- private var autoAdvanceCount: Int = launchArgs.autoAdvanceCount private var autoAdvanceHandled = false // once-per-item guard - // The credits or the end of this item was reached. Unlike autoAdvanceHandled, - // opening Up Next by hand or Keep Watching never sets it. + // Playback reached the closing credits or the end of this item. Unlike + // autoAdvanceHandled, opening Up Next by hand or Keep Watching never sets it. private var reachedCreditsOrEnd = false // The identity generation this player was launched under. private val launchIdentityGeneration: Long? = identityTransitions?.generation?.value @@ -3895,6 +3895,13 @@ class TvPlayerViewModel( ) { onApproachingEnd() } + // Playing into the closing credits counts as finishing the episode for + // the series page, though Up Next waits for the prompt point. + if (!seekWasActive && roomId == null) { + _uiState.value.markerTimeline.finalCreditsStart()?.let { creditsStart -> + if (previousPosition < creditsStart && positionSec >= creditsStart) reachedCreditsOrEnd = true + } + } // Forward to the lifecycle so its 10s reporter has a fresh sample. sessionLifecycle.reportPosition( positionSec = positionSec, @@ -5240,7 +5247,7 @@ class TvPlayerViewModel( /** * Adopt the playing file's marker ranges (a `markers_updated` event or a - * reconcile read). Skip-intro and the credits-based F2 trigger read these + * reconcile read). Skip-intro and the skip controls read these * from UiState, so the update takes effect immediately; `null` clears a * marker the server dropped. */ @@ -5364,7 +5371,7 @@ class TvPlayerViewModel( } /** - * Called by the screen when the credits point is reached (primary) or the + * Called when playback crosses the Up Next point before the end or the * stream ends (fallback). Surfaces the Up-Next overlay — a 16:9 mini-player * beside the next-episode panel — as the end-of-playback surface (mirrors * tvOS PlayerNextUpScreen), replacing the old "Still watching?" dialog. @@ -5387,8 +5394,10 @@ class TvPlayerViewModel( // transport gate. if (roomId != null) return // Recorded before the once-per-item guard below, which Keep Watching on - // a hand-opened Up Next also sets. - reachedCreditsOrEnd = true + // a hand-opened Up Next also sets. The before-end prompt can open while + // the story is still playing, so only the end counts here; the closing + // credits are recorded where playback crosses them. + if (videoEnded) reachedCreditsOrEnd = true if (shufflePlayback != null) { // A multi-part pick plays its later parts before the shuffle moves on. shuffleNextPartFileId?.let { fileId -> diff --git a/shared/src/commonMain/kotlin/org/siloserver/silo/domain/player/MarkerTimeline.kt b/shared/src/commonMain/kotlin/org/siloserver/silo/domain/player/MarkerTimeline.kt index d12e0f626d..6a906a425a 100644 --- a/shared/src/commonMain/kotlin/org/siloserver/silo/domain/player/MarkerTimeline.kt +++ b/shared/src/commonMain/kotlin/org/siloserver/silo/domain/player/MarkerTimeline.kt @@ -53,6 +53,21 @@ class MarkerTimeline private constructor(private val regions: List= start - 1) start = minOf(start, range.start) + } + return start + } + companion object { val EMPTY = MarkerTimeline(emptyList()) diff --git a/shared/src/commonMain/kotlin/org/siloserver/silo/domain/player/NextUpPrompt.kt b/shared/src/commonMain/kotlin/org/siloserver/silo/domain/player/NextUpPrompt.kt index b5597323b6..70f4df3e0c 100644 --- a/shared/src/commonMain/kotlin/org/siloserver/silo/domain/player/NextUpPrompt.kt +++ b/shared/src/commonMain/kotlin/org/siloserver/silo/domain/player/NextUpPrompt.kt @@ -2,8 +2,8 @@ package org.siloserver.silo.domain.player /** * When the Up Next card opens before an episode ends: `playback.next_up_prompt_seconds` - * before the end of the file, matching iOS/tvOS (`PlayerNextUpCompletionPolicy`) and the - * web. Credits markers drive Skip Credits only; they do not move this point. + * before the end of the file, as on iOS/tvOS (`PlayerNextUpCompletionPolicy`). Credits + * markers drive Skip Credits; they do not move this point. */ object NextUpPrompt { /** diff --git a/shared/src/commonTest/kotlin/org/siloserver/silo/domain/player/MarkerTimelineTest.kt b/shared/src/commonTest/kotlin/org/siloserver/silo/domain/player/MarkerTimelineTest.kt index 7349fc41b5..77ab2ef89e 100644 --- a/shared/src/commonTest/kotlin/org/siloserver/silo/domain/player/MarkerTimelineTest.kt +++ b/shared/src/commonTest/kotlin/org/siloserver/silo/domain/player/MarkerTimelineTest.kt @@ -87,4 +87,16 @@ class MarkerTimelineTest { assertEquals(TimeRange(30.0, 90.0), twoIntros.occurrenceAt(MarkerKind.Intro, 300.0)) assertEquals(TimeRange(600.0, 660.0), twoIntros.occurrenceAt(MarkerKind.Intro, 600.0)) } + + @Test fun finalCreditsStartSkipsAMidCreditsScene() { + assertEquals(3189.0, timeline.finalCreditsStart()) + val touching = MarkerTimeline.resolve( + segments = listOf(MarkerSegment("credits", 1200.0, 1250.0), MarkerSegment("credits", 1250.5, 1300.0)), + intro = null, credits = null, recap = null, preview = null, + ) + assertEquals(1200.0, touching.finalCreditsStart()) + val single = MarkerTimeline.resolve(null, intro = null, credits = TimeRange(1200.0, 1260.0), recap = null, preview = null) + assertEquals(1200.0, single.finalCreditsStart()) + assertNull(MarkerTimeline.EMPTY.finalCreditsStart()) + } }