Skip to content

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

feat: Implement chapter skip actions and autoplay for credits, including UI and tests

David Nashashde91791435f5
diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md
index cff9acd8..040d256d 100644
--- a/docs/CHANGELOG.md
+++ b/docs/CHANGELOG.md
@@ -8,6 +8,8 @@ All notable product changes are recorded in this document.
- Added an optional Live TV clock overlay with configurable corner placement, size, digital/clean/serif fonts, and System, 12-hour, or 24-hour time formatting.
- Added VOD chapter navigation with timeline markers, chapter selection, and previous/next chapter actions.
+- Added chapter skip actions for Intro, Opening, Recap, and Outro segments, with contextual labels and seek-to-end behavior.
+- Added chapter-aware series autoplay that presents the existing next-episode countdown when end credits begin, while preserving the end-of-video fallback for media without usable credit chapters.
- Added adaptive startup bitrate selection using network-class defaults and recent bandwidth measurements.
- Added selectable Classic blue, M3 purple, and Light app themes, with persistent settings and backup/restore support.
- Added persistent VOD audio and subtitle track choices: selections are saved per movie, shared across all episodes in the same series, and used as a global fallback for other VOD titles when a matching track is available; language and label matching survives provider track-ID changes, and explicit subtitle-off choices are preserved.
@@ -18,6 +20,8 @@ All notable product changes are recorded in this document.
### Fixed
+- Fixed an episode-completion `StackOverflowError` caused by playback history marking recursively invoking itself instead of the watched callback.
+- Fixed opening credits and post-credit scenes being treated as end credits, and tightened generic Credits detection to avoid triggering next-episode autoplay too early.
- Fixed VOD “More Like This” movie posters opening movie information instead of starting playback directly.
- Fixed native EPG resolution for large channel lineups by chunking program lookups to stay below SQLite bind-variable limits on older Android devices.
- Fixed EPG collisions for channels sharing an EPG identifier by keying resolved guide data by the provider stream ID when available, while preserving legacy EPG-ID fallback queries.
diff --git a/feature/playback/src/main/java/com/streamvault/feature/playback/player/CreditsChapterAutoplayPolicy.kt b/feature/playback/src/main/java/com/streamvault/feature/playback/player/CreditsChapterAutoplayPolicy.kt
new file mode 100644
index 00000000..30f0af53
--- /dev/null
+++ b/feature/playback/src/main/java/com/streamvault/feature/playback/player/CreditsChapterAutoplayPolicy.kt
@@ -0,0 +1,119 @@
+package com.streamvault.feature.playback.player
+
+import com.streamvault.domain.model.ContentType
+import com.streamvault.domain.model.Episode
+import com.streamvault.player.PlayerChapter
+
+private val CREDITS_TITLE_PATTERN = Regex("\\bcredits?\\b", RegexOption.IGNORE_CASE)
+private val EXPLICIT_END_CREDITS_TITLE_PATTERN = Regex(
+ "\\b(?:end|closing)\\s+credits?\\b|\\bcredit\\s+roll\\b",
+ RegexOption.IGNORE_CASE
+)
+private val OPENING_CREDITS_TITLE_PATTERN = Regex(
+ "\\bopening\\b.*\\bcredits?\\b",
+ RegexOption.IGNORE_CASE
+)
+private val POST_CREDITS_SCENE_TITLE_PATTERN = Regex(
+ "\\bpost\\s+credits?\\s+scene\\b",
+ RegexOption.IGNORE_CASE
+)
+private val INTRO_TITLE_PATTERN = Regex("\\bintro(?:duction)?\\b", RegexOption.IGNORE_CASE)
+private val OPENING_TITLE_PATTERN = Regex(
+ "\\b(?:opening|opening credits|title sequence|theme song?)\\b",
+ RegexOption.IGNORE_CASE
+)
+private val RECAP_TITLE_PATTERN = Regex("\\b(?:recap|previously on)\\b", RegexOption.IGNORE_CASE)
+private val OUTRO_TITLE_PATTERN = Regex("\\boutro\\b", RegexOption.IGNORE_CASE)
+
+enum class SkippableChapterType {
+ INTRO,
+ OPENING,
+ RECAP,
+ OUTRO
+}
+
+internal data class SkippableChapterAction(
+ val type: SkippableChapterType,
+ val targetPositionMs: Long
+)
+
+internal fun isCreditsChapterTitle(title: String): Boolean =
+ CREDITS_TITLE_PATTERN.containsMatchIn(title) &&
+ !OPENING_CREDITS_TITLE_PATTERN.containsMatchIn(title) &&
+ !POST_CREDITS_SCENE_TITLE_PATTERN.containsMatchIn(title)
+
+private fun isEndCreditsChapter(
+ chapter: PlayerChapter,
+ durationMs: Long
+): Boolean {
+ if (!isCreditsChapterTitle(chapter.title)) return false
+ if (EXPLICIT_END_CREDITS_TITLE_PATTERN.containsMatchIn(chapter.title)) return true
+ return durationMs > 0L && chapter.startTimeMs >= (durationMs * 0.6f).toLong()
+}
+
+internal fun skippableChapterType(title: String): SkippableChapterType? = when {
+ RECAP_TITLE_PATTERN.containsMatchIn(title) -> SkippableChapterType.RECAP
+ OUTRO_TITLE_PATTERN.containsMatchIn(title) -> SkippableChapterType.OUTRO
+ OPENING_TITLE_PATTERN.containsMatchIn(title) -> SkippableChapterType.OPENING
+ INTRO_TITLE_PATTERN.containsMatchIn(title) -> SkippableChapterType.INTRO
+ else -> null
+}
+
+internal fun PlayerChapter.isCreditsChapter(): Boolean =
+ isCreditsChapterTitle(title)
+
+internal fun ContentType.isSkippableChapterContent(): Boolean =
+ this == ContentType.VOD || this == ContentType.MOVIE || this == ContentType.SERIES_EPISODE
+
+internal data class PlayerChapterObservation(
+ val positionMs: Long,
+ val durationMs: Long,
+ val chapters: List<PlayerChapter>,
+ val nextEpisode: Episode?,
+ val autoPlayEnabled: Boolean
+)
+
+internal fun findCreditsChapter(
+ chapters: List<PlayerChapter>,
+ positionMs: Long,
+ durationMs: Long = 0L
+): PlayerChapter? = chapters
+ .asSequence()
+ .sortedBy(PlayerChapter::startTimeMs)
+ .firstOrNull { chapter ->
+ val endTimeMs = chapter.endTimeMs
+ isEndCreditsChapter(chapter, durationMs) &&
+ positionMs >= chapter.startTimeMs &&
+ (endTimeMs == null || positionMs < endTimeMs)
+ }
+
+internal fun findSkippableChapterAction(
+ chapters: List<PlayerChapter>,
+ positionMs: Long
+): SkippableChapterAction? = chapters
+ .asSequence()
+ .sortedBy(PlayerChapter::startTimeMs)
+ .firstNotNullOfOrNull { chapter ->
+ val endTimeMs = chapter.endTimeMs
+ val type = skippableChapterType(chapter.title)
+ if (type == null || endTimeMs == null || endTimeMs <= chapter.startTimeMs) {
+ null
+ } else if (positionMs >= chapter.startTimeMs && positionMs < endTimeMs) {
+ SkippableChapterAction(type = type, targetPositionMs = endTimeMs)
+ } else {
+ null
+ }
+ }
+
+internal fun shouldStartCreditsAutoPlay(
+ currentChapter: PlayerChapter?,
+ lastTriggeredChapterStartMs: Long?,
+ hasNextEpisode: Boolean,
+ autoPlayEnabled: Boolean,
+ contentType: ContentType
+): Boolean = currentChapter != null &&
+ currentChapter.isCreditsChapter() &&
+ currentChapter.startTimeMs != lastTriggeredChapterStartMs &&
+ hasNextEpisode &&
+ autoPlayEnabled &&
+ contentType == ContentType.SERIES_EPISODE
diff --git a/feature/playback/src/main/java/com/streamvault/feature/playback/player/PlayerAutoPlayActions.kt b/feature/playback/src/main/java/com/streamvault/feature/playback/player/PlayerAutoPlayActions.kt
index 6d8062dc..d8a0b552 100644
--- a/feature/playback/src/main/java/com/streamvault/feature/playback/player/PlayerAutoPlayActions.kt
+++ b/feature/playback/src/main/java/com/streamvault/feature/playback/player/PlayerAutoPlayActions.kt
@@ -35,7 +35,7 @@ internal fun PlayerViewModel.handlePlaybackEnded() {
val duration = playerEngine.duration.value
if (position > AUTO_PLAY_MIN_WATCHED_MS || duration > 0L) {
val next = nextEpisode.value ?: return@launch
- if (autoPlayNextEpisodeEnabled) {
+ if (autoPlayNextEpisodeEnabled && !creditsAutoPlayTriggeredForSession) {
startAutoPlayCountdown(next)
}
}
@@ -43,6 +43,37 @@ internal fun PlayerViewModel.handlePlaybackEnded() {
}
}
+internal fun PlayerViewModel.handleCreditsChapterObservation(
+ observation: PlayerChapterObservation
+) {
+ if (readySideEffectsRequestVersion != prepareRequestVersion) {
+ return
+ }
+ val currentChapter = findCreditsChapter(
+ chapters = observation.chapters,
+ positionMs = observation.positionMs,
+ durationMs = observation.durationMs
+ )
+ if (!shouldStartCreditsAutoPlay(
+ currentChapter = currentChapter,
+ lastTriggeredChapterStartMs = lastTriggeredCreditsChapterStartMs,
+ hasNextEpisode = observation.nextEpisode != null,
+ autoPlayEnabled = observation.autoPlayEnabled,
+ contentType = currentContentType
+ )
+ ) {
+ return
+ }
+
+ val nextEpisode = observation.nextEpisode ?: return
+ lastTriggeredCreditsChapterStartMs = currentChapter?.startTimeMs
+ creditsAutoPlayTriggeredForSession = true
+ playbackSessionScope()?.launch {
+ persistPlaybackCompletion()
+ }
+ startAutoPlayCountdown(nextEpisode)
+}
+
internal fun PlayerViewModel.startAutoPlayCountdown(episode: Episode) {
autoPlayCountdownJob?.cancel()
autoPlayCountdownJob = playbackSessionScope()?.launch {
diff --git a/feature/playback/src/main/java/com/streamvault/feature/playback/player/PlayerScreen.kt b/feature/playback/src/main/java/com/streamvault/feature/playback/player/PlayerScreen.kt
index aa8f3515..195f7b24 100644
--- a/feature/playback/src/main/java/com/streamvault/feature/playback/player/PlayerScreen.kt
+++ b/feature/playback/src/main/java/com/streamvault/feature/playback/player/PlayerScreen.kt
@@ -89,6 +89,7 @@ import com.streamvault.feature.playback.player.overlay.PlayerNumericInputOverlay
import com.streamvault.feature.playback.player.overlay.PlayerResolutionBadge
import com.streamvault.feature.playback.player.overlay.PlayerSleepTimerWarningOverlay
import com.streamvault.feature.playback.player.overlay.NextEpisodeCountdownOverlay
+import com.streamvault.feature.playback.player.overlay.SkipChapterOverlay
import com.streamvault.feature.playback.player.LiveClockOverlay
import com.streamvault.core.navigation.AppDestination
@@ -158,6 +159,7 @@ fun PlayerScreen(
val playbackResolutionUiState by viewModel.playbackResolutionUiState.collectAsStateWithLifecycle()
val currentChannel by viewModel.currentChannel.collectAsStateWithLifecycle()
val autoPlayCountdown by viewModel.autoPlayCountdown.collectAsStateWithLifecycle()
+ val skipChapter by viewModel.skipChapter.collectAsStateWithLifecycle()
val resumePrompt by viewModel.resumePrompt.collectAsStateWithLifecycle()
val playerPreferencesUiState by viewModel.playerPreferencesUiState.collectAsStateWithLifecycle()
@@ -841,6 +843,20 @@ fun PlayerScreen(
.padding(top = 88.dp)
)
+ val skipChapterState = skipChapter
+ if (!isInPictureInPictureMode && !resumePrompt.show && playbackState != PlaybackState.ERROR && skipChapterState != null) {
+ Box(
+ modifier = Modifier
+ .align(Alignment.BottomEnd)
+ .padding(end = 32.dp, bottom = 32.dp)
+ ) {
+ SkipChapterOverlay(
+ chapterType = skipChapterState.type,
+ onSkip = { viewModel.seekTo(skipChapterState.targetPositionMs) }
+ )
+ }
+ }
+
// Auto-Play Next Episode countdown overlay
val countdownState = autoPlayCountdown
if (!isInPictureInPictureMode && countdownState != null) {
diff --git a/feature/playback/src/main/java/com/streamvault/feature/playback/player/PlayerViewModel.kt b/feature/playback/src/main/java/com/streamvault/feature/playback/player/PlayerViewModel.kt
index 75e1342f..bf7f939f 100644
--- a/feature/playback/src/main/java/com/streamvault/feature/playback/player/PlayerViewModel.kt
+++ b/feature/playback/src/main/java/com/streamvault/feature/playback/player/PlayerViewModel.kt
@@ -122,6 +122,9 @@ class PlayerViewModel @Inject constructor(
internal val _autoPlayCountdown = MutableStateFlow<AutoPlayCountdownUiState?>(null)
val autoPlayCountdown: StateFlow<AutoPlayCountdownUiState?> = _autoPlayCountdown.asStateFlow()
+ internal val _skipChapter = MutableStateFlow<SkipChapterUiState?>(null)
+ val skipChapter: StateFlow<SkipChapterUiState?> = _skipChapter.asStateFlow()
+
internal val playbackTitleFlow = MutableStateFlow("")
val playbackTitle: StateFlow<String> = playbackTitleFlow.asStateFlow()
@@ -389,6 +392,8 @@ class PlayerViewModel @Inject constructor(
internal var aspectRatioJob: Job? = null
internal var zapBufferWatchdogJob: Job? = null
internal var autoPlayCountdownJob: Job? = null
+ internal var lastTriggeredCreditsChapterStartMs: Long? = null
+ internal var creditsAutoPlayTriggeredForSession: Boolean = false
internal var zapAutoRevertEnabled: Boolean = true
internal var autoPlayNextEpisodeEnabled: Boolean = true
internal var isAppInForeground: Boolean = true
@@ -535,6 +540,43 @@ class PlayerViewModel @Inject constructor(
}
}
}
+ viewModelScope.launch {
+ combine(
+ activePlayerEngineFlow.flatMapLatest { engine ->
+ combine(engine.currentPosition, engine.duration, engine.chapters) { positionMs, durationMs, chapters ->
+ Triple(positionMs, durationMs, chapters)
+ }
+ },
+ nextEpisode,
+ playerPreferencesCoordinator.autoPlayNextEpisode
+ ) { positionAndChapters, nextEpisode, autoPlayEnabled ->
+ PlayerChapterObservation(
+ positionMs = positionAndChapters.first,
+ durationMs = positionAndChapters.second,
+ chapters = positionAndChapters.third,
+ nextEpisode = nextEpisode,
+ autoPlayEnabled = autoPlayEnabled
+ )
+ }.collect { observation ->
+ _skipChapter.value = if (
+ readySideEffectsRequestVersion == prepareRequestVersion &&
+ currentContentType.isSkippableChapterContent()
+ ) {
+ findSkippableChapterAction(
+ chapters = observation.chapters,
+ positionMs = observation.positionMs
+ )?.let { action ->
+ SkipChapterUiState(
+ type = action.type,
+ targetPositionMs = action.targetPositionMs
+ )
+ }
+ } else {
+ null
+ }
+ handleCreditsChapterObservation(observation)
+ }
+ }
viewModelScope.launch {
activePlayerEngineFlow.flatMapLatest { it.retryStatus }.collect { status ->
status ?: return@collect
@@ -910,6 +952,9 @@ class PlayerViewModel @Inject constructor(
internal fun beginPlaybackSession(): Long {
val sessionId = playbackSessionCoordinator.begin().id
+ lastTriggeredCreditsChapterStartMs = null
+ creditsAutoPlayTriggeredForSession = false
+ _skipChapter.value = null
playerRecoveryCoordinator.beginSession(sessionId)
playerRecoveryExecutionCoordinator.cancel()
thumbnailPreloadJob?.cancel()
diff --git a/feature/playback/src/main/java/com/streamvault/feature/playback/player/PlayerViewModelModels.kt b/feature/playback/src/main/java/com/streamvault/feature/playback/player/PlayerViewModelModels.kt
index 63911999..e4602098 100644
--- a/feature/playback/src/main/java/com/streamvault/feature/playback/player/PlayerViewModelModels.kt
+++ b/feature/playback/src/main/java/com/streamvault/feature/playback/player/PlayerViewModelModels.kt
@@ -128,6 +128,11 @@ data class AutoPlayCountdownUiState(
val secondsRemaining: Int
)
+data class SkipChapterUiState(
+ val type: SkippableChapterType,
+ val targetPositionMs: Long
+)
+
data class PlayerPrepareIdentity(
val streamUrl: String,
val epgChannelId: String?,
diff --git a/feature/playback/src/main/java/com/streamvault/feature/playback/player/overlay/SkipChapterOverlay.kt b/feature/playback/src/main/java/com/streamvault/feature/playback/player/overlay/SkipChapterOverlay.kt
new file mode 100644
index 00000000..87e25c40
--- /dev/null
+++ b/feature/playback/src/main/java/com/streamvault/feature/playback/player/overlay/SkipChapterOverlay.kt
@@ -0,0 +1,67 @@
+package com.streamvault.feature.playback.player.overlay
+
+import androidx.compose.foundation.background
+import androidx.compose.foundation.layout.Box
+import androidx.compose.foundation.layout.padding
+import androidx.compose.foundation.layout.widthIn
+import androidx.compose.foundation.shape.RoundedCornerShape
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.LaunchedEffect
+import androidx.compose.runtime.remember
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.focus.FocusRequester
+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.tv.material3.ClickableSurfaceDefaults
+import androidx.tv.material3.Text
+import com.streamvault.core.ui.design.requestFocusSafely
+import com.streamvault.core.ui.interaction.TvClickableSurface
+import com.streamvault.feature.playback.R
+import com.streamvault.feature.playback.player.SkippableChapterType
+
+@Composable
+fun SkipChapterOverlay(
+ chapterType: SkippableChapterType,
+ onSkip: () -> Unit,
+ modifier: Modifier = Modifier
+) {
+ val focusRequester = remember { FocusRequester() }
+ val label = when (chapterType) {
+ SkippableChapterType.INTRO -> stringResource(R.string.player_skip_intro)
+ SkippableChapterType.OPENING -> stringResource(R.string.player_skip_opening)
+ SkippableChapterType.RECAP -> stringResource(R.string.player_skip_recap)
+ SkippableChapterType.OUTRO -> stringResource(R.string.player_skip_outro)
+ }
+
+ LaunchedEffect(chapterType) {
+ focusRequester.requestFocusSafely(
+ tag = "SkipChapterOverlay",
+ target = "Skip chapter button"
+ )
+ }
+
+ Box(
+ modifier = modifier
+ .widthIn(max = 280.dp)
+ .background(Color.Black.copy(alpha = 0.9f), RoundedCornerShape(12.dp))
+ .padding(10.dp)
+ ) {
+ TvClickableSurface(
+ onClick = onSkip,
+ shape = ClickableSurfaceDefaults.shape(RoundedCornerShape(8.dp)),
+ colors = ClickableSurfaceDefaults.colors(
+ containerColor = Color.White.copy(alpha = 0.12f),
+ focusedContainerColor = Color.White.copy(alpha = 0.24f)
+ ),
+ modifier = Modifier.focusRequester(focusRequester)
+ ) {
+ Text(
+ text = label,
+ color = Color.White,
+ modifier = Modifier.padding(horizontal = 20.dp, vertical = 10.dp)
+ )
+ }
+ }
+}
diff --git a/feature/playback/src/main/res/values/playback_player_strings.xml b/feature/playback/src/main/res/values/playback_player_strings.xml
index 50461885..3c0a2dea 100644
--- a/feature/playback/src/main/res/values/playback_player_strings.xml
+++ b/feature/playback/src/main/res/values/playback_player_strings.xml
@@ -187,6 +187,10 @@
<string name="player_schedule_weekly_recording">Schedule Weekly</string>
<string name="player_seek_back_10">-10s</string>
<string name="player_seek_forward_10">+10s</string>
+ <string name="player_skip_intro">Skip Intro</string>
+ <string name="player_skip_opening">Skip Opening</string>
+ <string name="player_skip_recap">Skip Recap</string>
+ <string name="player_skip_outro">Skip Outro</string>
<string name="player_selected">Selected</string>
<string name="player_stats">Stats</string>
<string name="player_stop_casting">Stop Casting</string>
diff --git a/feature/playback/src/test/java/com/streamvault/feature/playback/player/CreditsChapterAutoplayPolicyTest.kt b/feature/playback/src/test/java/com/streamvault/feature/playback/player/CreditsChapterAutoplayPolicyTest.kt
new file mode 100644
index 00000000..7e5336d8
--- /dev/null
+++ b/feature/playback/src/test/java/com/streamvault/feature/playback/player/CreditsChapterAutoplayPolicyTest.kt
@@ -0,0 +1,143 @@
+package com.streamvault.feature.playback.player
+
+import com.google.common.truth.Truth.assertThat
+import com.streamvault.domain.model.ContentType
+import com.streamvault.player.PlayerChapter
+import org.junit.Test
+
+class CreditsChapterAutoplayPolicyTest {
+
+ private val chapters = listOf(
+ PlayerChapter(index = 1, title = "Story", startTimeMs = 0L, endTimeMs = 100_000L),
+ PlayerChapter(index = 2, title = "End Credits", startTimeMs = 100_000L, endTimeMs = null)
+ )
+
+ @Test
+ fun `finds credits chapter only while position is inside its range`() {
+ assertThat(findCreditsChapter(chapters, positionMs = 100_000L)?.index).isEqualTo(2)
+ assertThat(findCreditsChapter(chapters, positionMs = 99_999L)).isNull()
+ }
+
+ @Test
+ fun `recognizes credit title variants without matching unrelated titles`() {
+ assertThat(isCreditsChapterTitle("Closing-Credits")).isTrue()
+ assertThat(isCreditsChapterTitle("Post credits scene")).isFalse()
+ assertThat(isCreditsChapterTitle("Credit sequence")).isTrue()
+ assertThat(isCreditsChapterTitle("Finale")).isFalse()
+ }
+
+ @Test
+ fun `starts credits autoplay only once for an enabled series with a next episode`() {
+ val creditsChapter = chapters.last()
+
+ assertThat(
+ shouldStartCreditsAutoPlay(
+ currentChapter = creditsChapter,
+ lastTriggeredChapterStartMs = null,
+ hasNextEpisode = true,
+ autoPlayEnabled = true,
+ contentType = ContentType.SERIES_EPISODE
+ )
+ ).isTrue()
+ assertThat(
+ shouldStartCreditsAutoPlay(
+ currentChapter = creditsChapter,
+ lastTriggeredChapterStartMs = creditsChapter.startTimeMs,
+ hasNextEpisode = true,
+ autoPlayEnabled = true,
+ contentType = ContentType.SERIES_EPISODE
+ )
+ ).isFalse()
+ assertThat(
+ shouldStartCreditsAutoPlay(
+ currentChapter = creditsChapter,
+ lastTriggeredChapterStartMs = null,
+ hasNextEpisode = false,
+ autoPlayEnabled = true,
+ contentType = ContentType.SERIES_EPISODE
+ )
+ ).isFalse()
+ assertThat(
+ shouldStartCreditsAutoPlay(
+ currentChapter = creditsChapter,
+ lastTriggeredChapterStartMs = null,
+ hasNextEpisode = true,
+ autoPlayEnabled = true,
+ contentType = ContentType.MOVIE
+ )
+ ).isFalse()
+ }
+
+ @Test
+ fun `classifies skippable chapter names using streaming segment conventions`() {
+ assertThat(skippableChapterType("Intro")).isEqualTo(SkippableChapterType.INTRO)
+ assertThat(skippableChapterType("Opening Credits")).isEqualTo(SkippableChapterType.OPENING)
+ assertThat(skippableChapterType("Previously On")).isEqualTo(SkippableChapterType.RECAP)
+ assertThat(skippableChapterType("Outro")).isEqualTo(SkippableChapterType.OUTRO)
+ assertThat(isCreditsChapterTitle("Opening Credits")).isFalse()
+ assertThat(isCreditsChapterTitle("Post Credits Scene")).isFalse()
+ assertThat(skippableChapterType("Story")).isNull()
+ }
+
+ @Test
+ fun `finds a skip action only while a named chapter has a valid end`() {
+ val action = findSkippableChapterAction(
+ chapters = listOf(
+ PlayerChapter(index = 1, title = "Intro", startTimeMs = 0L, endTimeMs = 90_000L),
+ PlayerChapter(index = 2, title = "Story", startTimeMs = 90_000L, endTimeMs = null)
+ ),
+ positionMs = 45_000L
+ )
+
+ assertThat(action?.type).isEqualTo(SkippableChapterType.INTRO)
+ assertThat(action?.targetPositionMs).isEqualTo(90_000L)
+ assertThat(
+ findSkippableChapterAction(
+ chapters = listOf(
+ PlayerChapter(index = 1, title = "Intro", startTimeMs = 0L, endTimeMs = 90_000L)
+ ),
+ positionMs = 90_000L
+ )
+ ).isNull()
+ assertThat(
+ findSkippableChapterAction(
+ chapters = listOf(
+ PlayerChapter(index = 1, title = "Intro", startTimeMs = 0L, endTimeMs = null)
+ ),
+ positionMs = 45_000L
+ )
+ ).isNull()
+ }
+
+ @Test
+ fun `allows skip chapters only for playable vod content`() {
+ assertThat(ContentType.VOD.isSkippableChapterContent()).isTrue()
+ assertThat(ContentType.MOVIE.isSkippableChapterContent()).isTrue()
+ assertThat(ContentType.SERIES_EPISODE.isSkippableChapterContent()).isTrue()
+ assertThat(ContentType.LIVE.isSkippableChapterContent()).isFalse()
+ }
+
+ @Test
+ fun `requires generic credits to begin near the end of the media`() {
+ val chapters = listOf(
+ PlayerChapter(index = 1, title = "Credits", startTimeMs = 100_000L, endTimeMs = 160_000L),
+ PlayerChapter(index = 2, title = "Story", startTimeMs = 160_000L, endTimeMs = null)
+ )
+
+ assertThat(
+ findCreditsChapter(chapters, positionMs = 150_000L, durationMs = 300_000L)
+ ).isNull()
+ assertThat(
+ findCreditsChapter(chapters, positionMs = 120_000L, durationMs = 160_000L)?.title
+ ).isEqualTo("Credits")
+ assertThat(
+ findCreditsChapter(
+ chapters = listOf(
+ PlayerChapter(index = 1, title = "End Credits", startTimeMs = 20_000L, endTimeMs = null)
+ ),
+ positionMs = 25_000L,
+ durationMs = 300_000L
+ )?.title
+ ).isEqualTo("End Credits")
+ }
+}