From dc9e24847f8a553a3e7daca96ac9fb700e37fe07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joaquim=20Sta=CC=88hli?= Date: Tue, 30 Apr 2024 14:35:15 +0200 Subject: [PATCH] Renaming to TimeRange --- .../core/business/source/SegmentAdapter.kt | 8 +++--- .../business/source/TimeIntervalAdapter.kt | 8 +++--- .../core/business/SegmentAdapterTest.kt | 8 +++--- ...AdapterTest.kt => TimeRangeAdapterTest.kt} | 2 +- .../demo/tv/ui/player/compose/PlayerView.kt | 4 +-- .../demo/ui/player/BlockedIntervalWarning.kt | 10 +++---- .../pillarbox/demo/ui/player/PlayerView.kt | 4 +-- .../demo/ui/player/SimplePlayerViewModel.kt | 4 +-- .../demo/ui/player/controls/PlayerControls.kt | 4 +-- .../pillarbox/player/PillarboxExoPlayer.kt | 26 +++++++++---------- .../pillarbox/player/PillarboxPlayer.kt | 10 +++---- .../pillarbox/player/PlayerCallbackFlow.kt | 14 +++++----- .../ch/srgssr/pillarbox/player/asset/Asset.kt | 8 +++--- ...BlockedInterval.kt => BlockedTimeRange.kt} | 17 ++++++------ .../srgssr/pillarbox/player/asset/Chapter.kt | 2 +- .../pillarbox/player/asset/PillarboxData.kt | 8 +++--- ...leTimeInterval.kt => SkipableTimeRange.kt} | 18 ++++++------- ...tervalType.kt => SkipableTimeRangeType.kt} | 4 +-- .../asset/{TimeInterval.kt => TimeRange.kt} | 4 +-- .../pillarbox/player/extension/Player.kt | 16 ++++++------ .../session/PillarboxMediaController.kt | 8 +++--- .../player/session/PillarboxMediaSession.kt | 8 +++--- ...lTracker.kt => BlockedTimeRangeTracker.kt} | 12 ++++----- ...IntervalTracker.kt => TimeRangeTracker.kt} | 10 +++---- ...tervalTest.kt => SkipableTimeRangeTest.kt} | 14 +++++----- .../pillarbox/player/extension/PlayerTest.kt | 12 ++++----- ...Test.kt => BlockedTimeRangeTrackerTest.kt} | 12 ++++----- ...TrackerTest.kt => TimeRangeTrackerTest.kt} | 2 +- .../ui/extension/ComposablePlayer.kt | 14 +++++----- 29 files changed, 135 insertions(+), 136 deletions(-) rename pillarbox-core-business/src/test/java/ch/srgssr/pillarbox/core/business/source/{TimeIntervalAdapterTest.kt => TimeRangeAdapterTest.kt} (98%) rename pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/asset/{BlockedInterval.kt => BlockedTimeRange.kt} (70%) rename pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/asset/{SkipableTimeInterval.kt => SkipableTimeRange.kt} (73%) rename pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/asset/{SkipableTimeIntervalType.kt => SkipableTimeRangeType.kt} (72%) rename pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/asset/{TimeInterval.kt => TimeRange.kt} (94%) rename pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/tracker/{BlockedIntervalTracker.kt => BlockedTimeRangeTracker.kt} (85%) rename pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/tracker/{TimeIntervalTracker.kt => TimeRangeTracker.kt} (93%) rename pillarbox-player/src/test/java/ch/srgssr/pillarbox/player/asset/{SkipableTimeIntervalTest.kt => SkipableTimeRangeTest.kt} (71%) rename pillarbox-player/src/test/java/ch/srgssr/pillarbox/player/tracker/{BlockedIntervalTrackerTest.kt => BlockedTimeRangeTrackerTest.kt} (92%) rename pillarbox-player/src/test/java/ch/srgssr/pillarbox/player/tracker/{TimeIntervalTrackerTest.kt => TimeRangeTrackerTest.kt} (99%) diff --git a/pillarbox-core-business/src/main/java/ch/srgssr/pillarbox/core/business/source/SegmentAdapter.kt b/pillarbox-core-business/src/main/java/ch/srgssr/pillarbox/core/business/source/SegmentAdapter.kt index bc087c636..2dd770427 100644 --- a/pillarbox-core-business/src/main/java/ch/srgssr/pillarbox/core/business/source/SegmentAdapter.kt +++ b/pillarbox-core-business/src/main/java/ch/srgssr/pillarbox/core/business/source/SegmentAdapter.kt @@ -5,16 +5,16 @@ package ch.srgssr.pillarbox.core.business.source import ch.srgssr.pillarbox.core.business.integrationlayer.data.Segment -import ch.srgssr.pillarbox.player.asset.BlockedInterval +import ch.srgssr.pillarbox.player.asset.BlockedTimeRange internal object SegmentAdapter { - fun getBlockedInterval(segment: Segment): BlockedInterval { + fun getBlockedInterval(segment: Segment): BlockedTimeRange { requireNotNull(segment.blockReason) - return BlockedInterval(segment.urn, segment.markIn, segment.markOut, segment.blockReason.toString()) + return BlockedTimeRange(segment.urn, segment.markIn, segment.markOut, segment.blockReason.toString()) } - fun getBlockedIntervals(listSegment: List?): List { + fun getBlockedIntervals(listSegment: List?): List { return listSegment?.filter { it.blockReason != null }?.map { getBlockedInterval(it) } ?: emptyList() diff --git a/pillarbox-core-business/src/main/java/ch/srgssr/pillarbox/core/business/source/TimeIntervalAdapter.kt b/pillarbox-core-business/src/main/java/ch/srgssr/pillarbox/core/business/source/TimeIntervalAdapter.kt index 02960042a..ad3c8f13e 100644 --- a/pillarbox-core-business/src/main/java/ch/srgssr/pillarbox/core/business/source/TimeIntervalAdapter.kt +++ b/pillarbox-core-business/src/main/java/ch/srgssr/pillarbox/core/business/source/TimeIntervalAdapter.kt @@ -5,20 +5,20 @@ package ch.srgssr.pillarbox.core.business.source import ch.srgssr.pillarbox.core.business.integrationlayer.data.TimeInterval -import ch.srgssr.pillarbox.player.asset.SkipableTimeInterval +import ch.srgssr.pillarbox.player.asset.SkipableTimeRange internal object TimeIntervalAdapter { - internal fun getTimeIntervals(timeIntervals: List?): List { + internal fun getTimeIntervals(timeIntervals: List?): List { return timeIntervals .orEmpty() .mapNotNull { it.toSkipableTimeInterval() } } - internal fun TimeInterval.toSkipableTimeInterval(): SkipableTimeInterval? { + internal fun TimeInterval.toSkipableTimeInterval(): SkipableTimeRange? { return if (type == null || markIn == null || markOut == null) { null } else { - SkipableTimeInterval( + SkipableTimeRange( id = type.name, start = markIn, end = markOut, diff --git a/pillarbox-core-business/src/test/java/ch/srgssr/pillarbox/core/business/SegmentAdapterTest.kt b/pillarbox-core-business/src/test/java/ch/srgssr/pillarbox/core/business/SegmentAdapterTest.kt index f7380fc82..a141adbbf 100644 --- a/pillarbox-core-business/src/test/java/ch/srgssr/pillarbox/core/business/SegmentAdapterTest.kt +++ b/pillarbox-core-business/src/test/java/ch/srgssr/pillarbox/core/business/SegmentAdapterTest.kt @@ -7,7 +7,7 @@ package ch.srgssr.pillarbox.core.business import ch.srgssr.pillarbox.core.business.integrationlayer.data.BlockReason import ch.srgssr.pillarbox.core.business.integrationlayer.data.Segment import ch.srgssr.pillarbox.core.business.source.SegmentAdapter -import ch.srgssr.pillarbox.player.asset.BlockedInterval +import ch.srgssr.pillarbox.player.asset.BlockedTimeRange import kotlin.test.Test import kotlin.test.assertEquals @@ -21,7 +21,7 @@ class SegmentAdapterTest { @Test fun `getBlockedInterval of a blocked segment`() { val segmentIl = Segment(urn = "urn1", title = "title 1", markIn = 1, markOut = 2, blockReason = BlockReason.UNKNOWN) - val expected = BlockedInterval(id = "urn1", start = 1, end = 2, reason = "UNKNOWN") + val expected = BlockedTimeRange(id = "urn1", start = 1, end = 2, reason = "UNKNOWN") assertEquals(expected, SegmentAdapter.getBlockedInterval(segmentIl)) } @@ -49,8 +49,8 @@ class SegmentAdapterTest { Segment(urn = "urn3", title = "title 3", markIn = 5, markOut = 56, blockReason = BlockReason.UNKNOWN), ) val expected = listOf( - BlockedInterval(id = "urn1_blocked", start = 1, end = 4, reason = "LEGAL"), - BlockedInterval(id = "urn3", start = 5, end = 56, reason = "UNKNOWN"), + BlockedTimeRange(id = "urn1_blocked", start = 1, end = 4, reason = "LEGAL"), + BlockedTimeRange(id = "urn3", start = 5, end = 56, reason = "UNKNOWN"), ) assertEquals(expected, SegmentAdapter.getBlockedIntervals(listSegments)) } diff --git a/pillarbox-core-business/src/test/java/ch/srgssr/pillarbox/core/business/source/TimeIntervalAdapterTest.kt b/pillarbox-core-business/src/test/java/ch/srgssr/pillarbox/core/business/source/TimeRangeAdapterTest.kt similarity index 98% rename from pillarbox-core-business/src/test/java/ch/srgssr/pillarbox/core/business/source/TimeIntervalAdapterTest.kt rename to pillarbox-core-business/src/test/java/ch/srgssr/pillarbox/core/business/source/TimeRangeAdapterTest.kt index f51138e20..f46c79dec 100644 --- a/pillarbox-core-business/src/test/java/ch/srgssr/pillarbox/core/business/source/TimeIntervalAdapterTest.kt +++ b/pillarbox-core-business/src/test/java/ch/srgssr/pillarbox/core/business/source/TimeRangeAdapterTest.kt @@ -7,7 +7,7 @@ import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertTrue -class TimeIntervalAdapterTest { +class TimeRangeAdapterTest { @Test fun `get time intervals, source is null`() { val timeIntervals = TimeIntervalAdapter.getTimeIntervals(null) diff --git a/pillarbox-demo-tv/src/main/java/ch/srgssr/pillarbox/demo/tv/ui/player/compose/PlayerView.kt b/pillarbox-demo-tv/src/main/java/ch/srgssr/pillarbox/demo/tv/ui/player/compose/PlayerView.kt index 0735673c8..bb0dd77d9 100644 --- a/pillarbox-demo-tv/src/main/java/ch/srgssr/pillarbox/demo/tv/ui/player/compose/PlayerView.kt +++ b/pillarbox-demo-tv/src/main/java/ch/srgssr/pillarbox/demo/tv/ui/player/compose/PlayerView.kt @@ -42,7 +42,7 @@ import ch.srgssr.pillarbox.demo.tv.ui.player.compose.settings.PlaybackSettingsDr import ch.srgssr.pillarbox.demo.tv.ui.theme.paddings import ch.srgssr.pillarbox.ui.extension.currentMediaMetadataAsState import ch.srgssr.pillarbox.ui.extension.getCurrentChapterAsState -import ch.srgssr.pillarbox.ui.extension.getCurrentTimeIntervalAsState +import ch.srgssr.pillarbox.ui.extension.getCurrentTimeRangeAsState import ch.srgssr.pillarbox.ui.extension.playerErrorAsState import ch.srgssr.pillarbox.ui.widget.maintainVisibleOnFocus import ch.srgssr.pillarbox.ui.widget.player.PlayerSurface @@ -64,7 +64,7 @@ fun PlayerView( ) { val drawerState = rememberDrawerState(initialValue = DrawerValue.Closed) val visibilityState = rememberDelayedVisibilityState(player = player, visible = true) - val timeInterval by player.getCurrentTimeIntervalAsState() + val timeInterval by player.getCurrentTimeRangeAsState() LaunchedEffect(drawerState.currentValue) { when (drawerState.currentValue) { diff --git a/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/player/BlockedIntervalWarning.kt b/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/player/BlockedIntervalWarning.kt index e660db924..1e1f48285 100644 --- a/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/player/BlockedIntervalWarning.kt +++ b/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/player/BlockedIntervalWarning.kt @@ -24,7 +24,7 @@ import androidx.media3.common.Player import ch.srgssr.pillarbox.demo.ui.theme.PillarboxTheme import ch.srgssr.pillarbox.demo.ui.theme.paddings import ch.srgssr.pillarbox.player.PillarboxPlayer -import ch.srgssr.pillarbox.player.asset.BlockedInterval +import ch.srgssr.pillarbox.player.asset.BlockedTimeRange import kotlinx.coroutines.delay import kotlin.time.Duration import kotlin.time.Duration.Companion.seconds @@ -42,12 +42,12 @@ fun BlockedIntervalWarning( modifier: Modifier = Modifier, visibilityDelay: Duration = 5.seconds, ) { - var currentBlockedInterval: BlockedInterval? by remember(player) { + var currentBlockedInterval: BlockedTimeRange? by remember(player) { mutableStateOf(null) } DisposableEffect(player) { val listener = object : PillarboxPlayer.Listener { - override fun onBlockIntervalReached(blockedInterval: BlockedInterval) { + override fun onBlockIntervalReached(blockedInterval: BlockedTimeRange) { currentBlockedInterval = blockedInterval } } @@ -74,7 +74,7 @@ fun BlockedIntervalWarning( @Composable private fun BlockedSegmentInfo( - blockedInterval: BlockedInterval, + blockedInterval: BlockedTimeRange, modifier: Modifier = Modifier ) { Text( @@ -90,7 +90,7 @@ private fun BlockedSegmentInfo( @Preview(showBackground = true) @Composable private fun BlockedSegmentPreview() { - val blockedSection = BlockedInterval("", 0, 0, "GeoBlock") + val blockedSection = BlockedTimeRange("", 0, 0, "GeoBlock") PillarboxTheme { BlockedSegmentInfo( modifier = Modifier.fillMaxWidth(), diff --git a/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/player/PlayerView.kt b/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/player/PlayerView.kt index 5d73956b0..3702481cb 100644 --- a/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/player/PlayerView.kt +++ b/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/player/PlayerView.kt @@ -30,7 +30,7 @@ import ch.srgssr.pillarbox.demo.ui.theme.paddings import ch.srgssr.pillarbox.ui.ProgressTrackerState import ch.srgssr.pillarbox.ui.ScaleMode import ch.srgssr.pillarbox.ui.exoplayer.ExoPlayerSubtitleView -import ch.srgssr.pillarbox.ui.extension.getCurrentTimeIntervalAsState +import ch.srgssr.pillarbox.ui.extension.getCurrentTimeRangeAsState import ch.srgssr.pillarbox.ui.extension.hasMediaItemsAsState import ch.srgssr.pillarbox.ui.extension.playbackStateAsState import ch.srgssr.pillarbox.ui.extension.playerErrorAsState @@ -85,7 +85,7 @@ fun PlayerView( autoHideEnabled = !isSliderDragged, visible = controlsVisible ) - val timeInterval by player.getCurrentTimeIntervalAsState() + val timeInterval by player.getCurrentTimeRangeAsState() ToggleableBox( modifier = modifier, diff --git a/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/player/SimplePlayerViewModel.kt b/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/player/SimplePlayerViewModel.kt index 49cdcfc6b..025092dd5 100644 --- a/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/player/SimplePlayerViewModel.kt +++ b/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/player/SimplePlayerViewModel.kt @@ -21,7 +21,7 @@ import ch.srgssr.pillarbox.demo.shared.data.DemoItem import ch.srgssr.pillarbox.demo.shared.di.PlayerModule import ch.srgssr.pillarbox.player.PillarboxPlayer import ch.srgssr.pillarbox.player.asset.Chapter -import ch.srgssr.pillarbox.player.asset.SkipableTimeInterval +import ch.srgssr.pillarbox.player.asset.SkipableTimeRange import ch.srgssr.pillarbox.player.extension.setHandleAudioFocus import ch.srgssr.pillarbox.player.extension.toRational import kotlinx.coroutines.flow.MutableStateFlow @@ -154,7 +154,7 @@ class SimplePlayerViewModel( Log.i(TAG, "onCurrentChapterChanged $chapter") } - override fun onTimeIntervalChanged(timeInterval: SkipableTimeInterval?) { + override fun onTimeIntervalChanged(timeInterval: SkipableTimeRange?) { Log.i(TAG, "onTimeIntervalChanged $timeInterval") } diff --git a/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/player/controls/PlayerControls.kt b/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/player/controls/PlayerControls.kt index 9f49c2a01..4e531ba76 100644 --- a/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/player/controls/PlayerControls.kt +++ b/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/player/controls/PlayerControls.kt @@ -24,7 +24,7 @@ import androidx.compose.ui.graphics.Color import androidx.media3.common.Player import ch.srgssr.pillarbox.demo.ui.player.LiveIndicator import ch.srgssr.pillarbox.demo.ui.theme.paddings -import ch.srgssr.pillarbox.player.asset.SkipableTimeInterval +import ch.srgssr.pillarbox.player.asset.SkipableTimeRange import ch.srgssr.pillarbox.player.extension.canSeek import ch.srgssr.pillarbox.player.extension.getChapterAtPosition import ch.srgssr.pillarbox.player.extension.isAtLiveEdge @@ -55,7 +55,7 @@ fun PlayerControls( backgroundColor: Color = Color.Black.copy(0.5f), interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, progressTracker: ProgressTrackerState = rememberProgressTrackerState(player = player, smoothTracker = true), - timeInterval: SkipableTimeInterval? = null, + timeInterval: SkipableTimeRange? = null, content: @Composable ColumnScope.() -> Unit, ) { val currentMediaMetadata by player.currentMediaMetadataAsState() diff --git a/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/PillarboxExoPlayer.kt b/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/PillarboxExoPlayer.kt index 3a95cd6cd..090adec85 100644 --- a/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/PillarboxExoPlayer.kt +++ b/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/PillarboxExoPlayer.kt @@ -19,22 +19,22 @@ import androidx.media3.exoplayer.LoadControl import androidx.media3.exoplayer.trackselection.DefaultTrackSelector import androidx.media3.exoplayer.upstream.DefaultBandwidthMeter import androidx.media3.exoplayer.util.EventLogger -import ch.srgssr.pillarbox.player.asset.BlockedInterval +import ch.srgssr.pillarbox.player.asset.BlockedTimeRange import ch.srgssr.pillarbox.player.asset.Chapter import ch.srgssr.pillarbox.player.asset.PillarboxData -import ch.srgssr.pillarbox.player.asset.SkipableTimeInterval +import ch.srgssr.pillarbox.player.asset.SkipableTimeRange import ch.srgssr.pillarbox.player.extension.getChapterAtPosition import ch.srgssr.pillarbox.player.extension.getPlaybackSpeed -import ch.srgssr.pillarbox.player.extension.getTimeIntervalAtPosition +import ch.srgssr.pillarbox.player.extension.getSkipableTimeRangeAtPosition import ch.srgssr.pillarbox.player.extension.setPreferredAudioRoleFlagsToAccessibilityManagerSettings import ch.srgssr.pillarbox.player.extension.setSeekIncrements import ch.srgssr.pillarbox.player.source.PillarboxMediaSourceFactory import ch.srgssr.pillarbox.player.tracker.AnalyticsMediaItemTracker -import ch.srgssr.pillarbox.player.tracker.BlockedIntervalTracker +import ch.srgssr.pillarbox.player.tracker.BlockedTimeRangeTracker import ch.srgssr.pillarbox.player.tracker.CurrentMediaItemPillarboxDataTracker import ch.srgssr.pillarbox.player.tracker.MediaItemTrackerProvider import ch.srgssr.pillarbox.player.tracker.MediaItemTrackerRepository -import ch.srgssr.pillarbox.player.tracker.TimeIntervalTracker +import ch.srgssr.pillarbox.player.tracker.TimeRangeTracker /** * Pillarbox player @@ -84,26 +84,26 @@ class PillarboxExoPlayer internal constructor( } get() = analyticsTracker.enabled - private val blockedIntervalTracker = BlockedIntervalTracker(this) - private val chapterTracker = TimeIntervalTracker( + private val blockedTimeRangeTracker = BlockedTimeRangeTracker(this) + private val chapterTracker = TimeRangeTracker( player = this, getTimeIntervalAtPosition = Player::getChapterAtPosition, getAllTimeIntervals = PillarboxData::chapters, notifyTimeIntervalChanged = { notifyCurrentChapterChanged(it) }, ) - private val timeIntervalTracker = TimeIntervalTracker( + private val timeRangeTracker = TimeRangeTracker( player = this, - getTimeIntervalAtPosition = Player::getTimeIntervalAtPosition, + getTimeIntervalAtPosition = Player::getSkipableTimeRangeAtPosition, getAllTimeIntervals = PillarboxData::timeIntervals, notifyTimeIntervalChanged = { notifyTimeIntervalChanged(it) }, ) init { exoPlayer.addListener(ComponentListener()) - itemPillarboxDataTracker.addCallback(blockedIntervalTracker) + itemPillarboxDataTracker.addCallback(blockedTimeRangeTracker) itemPillarboxDataTracker.addCallback(analyticsTracker) itemPillarboxDataTracker.addCallback(chapterTracker) - itemPillarboxDataTracker.addCallback(timeIntervalTracker) + itemPillarboxDataTracker.addCallback(timeRangeTracker) if (BuildConfig.DEBUG) { addAnalyticsListener(EventLogger()) } @@ -178,13 +178,13 @@ class PillarboxExoPlayer internal constructor( } } - internal fun notifyBlockedIntervalReached(blockedInterval: BlockedInterval) { + internal fun notifyBlockedIntervalReached(blockedInterval: BlockedTimeRange) { HashSet(listeners).forEach { it.onBlockIntervalReached(blockedInterval) } } - internal fun notifyTimeIntervalChanged(timeInterval: SkipableTimeInterval?) { + internal fun notifyTimeIntervalChanged(timeInterval: SkipableTimeRange?) { HashSet(listeners).forEach { it.onTimeIntervalChanged(timeInterval) } diff --git a/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/PillarboxPlayer.kt b/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/PillarboxPlayer.kt index 596cb09b3..181699e68 100644 --- a/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/PillarboxPlayer.kt +++ b/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/PillarboxPlayer.kt @@ -7,9 +7,9 @@ package ch.srgssr.pillarbox.player import androidx.media3.common.Player import androidx.media3.exoplayer.ExoPlayer import androidx.media3.exoplayer.SeekParameters -import ch.srgssr.pillarbox.player.asset.BlockedInterval +import ch.srgssr.pillarbox.player.asset.BlockedTimeRange import ch.srgssr.pillarbox.player.asset.Chapter -import ch.srgssr.pillarbox.player.asset.SkipableTimeInterval +import ch.srgssr.pillarbox.player.asset.SkipableTimeRange /** * Pillarbox [Player] interface extension. @@ -46,9 +46,9 @@ interface PillarboxPlayer : Player { /** * On block interval reached * - * @param blockedInterval The [BlockedInterval] reached by the player. + * @param blockedInterval The [BlockedTimeRange] reached by the player. */ - fun onBlockIntervalReached(blockedInterval: BlockedInterval) {} + fun onBlockIntervalReached(blockedInterval: BlockedTimeRange) {} /** * `onTimeIntervalChanged` is called when either: @@ -58,7 +58,7 @@ interface PillarboxPlayer : Player { * * @param timeInterval `null` when the current position is not in a time interval. */ - fun onTimeIntervalChanged(timeInterval: SkipableTimeInterval?) {} + fun onTimeIntervalChanged(timeInterval: SkipableTimeRange?) {} } /** diff --git a/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/PlayerCallbackFlow.kt b/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/PlayerCallbackFlow.kt index ffbb2e472..4887e122a 100644 --- a/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/PlayerCallbackFlow.kt +++ b/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/PlayerCallbackFlow.kt @@ -16,12 +16,12 @@ import androidx.media3.common.TrackSelectionParameters import androidx.media3.common.Tracks import androidx.media3.common.VideoSize import ch.srgssr.pillarbox.player.asset.Chapter -import ch.srgssr.pillarbox.player.asset.SkipableTimeInterval +import ch.srgssr.pillarbox.player.asset.SkipableTimeRange import ch.srgssr.pillarbox.player.extension.computeAspectRatioOrNull import ch.srgssr.pillarbox.player.extension.getChapterAtPosition import ch.srgssr.pillarbox.player.extension.getCurrentMediaItems import ch.srgssr.pillarbox.player.extension.getPlaybackSpeed -import ch.srgssr.pillarbox.player.extension.getTimeIntervalAtPosition +import ch.srgssr.pillarbox.player.extension.getSkipableTimeRangeAtPosition import ch.srgssr.pillarbox.player.tracks.videoTracks import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.channels.ProducerScope @@ -406,16 +406,16 @@ fun Player.getCurrentChapterAsFlow(): Flow = callbackFlow { } /** - * @return Get the current time interval as flow, when the time interval changes. + * @return Get the current time range as flow, when the time interval changes. */ -fun Player.getCurrentTimeIntervalAsFlow(): Flow = callbackFlow { +fun Player.getCurrentSkipableTimeRangeAsFlow(): Flow = callbackFlow { val listener = object : PillarboxPlayer.Listener { - override fun onTimeIntervalChanged(timeInterval: SkipableTimeInterval?) { + override fun onTimeIntervalChanged(timeInterval: SkipableTimeRange?) { trySend(timeInterval) } } - trySend(getTimeIntervalAtPosition()) - addPlayerListener(this@getCurrentTimeIntervalAsFlow, listener) + trySend(getSkipableTimeRangeAtPosition()) + addPlayerListener(this@getCurrentSkipableTimeRangeAsFlow, listener) } private suspend fun ProducerScope.addPlayerListener(player: Player, listener: Listener) { diff --git a/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/asset/Asset.kt b/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/asset/Asset.kt index 94f6c9b40..d057c98ca 100644 --- a/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/asset/Asset.kt +++ b/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/asset/Asset.kt @@ -14,15 +14,15 @@ import ch.srgssr.pillarbox.player.tracker.MediaItemTrackerData * @property mediaSource The [MediaSource] used by the player to play something. * @property trackersData The [MediaItemTrackerData] to set to the [PillarboxData]. * @property mediaMetadata The [MediaMetadata] to set to the player media item. - * @property blockedIntervals The [BlockedInterval] list to set to the [PillarboxData]. + * @property blockedIntervals The [BlockedTimeRange] list to set to the [PillarboxData]. * @property chapters The [Chapter] list to set to the [PillarboxData]. - * @property timeIntervals The [SkipableTimeInterval] list to set to the [PillarboxData]. + * @property timeIntervals The [SkipableTimeRange] list to set to the [PillarboxData]. */ data class Asset( val mediaSource: MediaSource, val trackersData: MediaItemTrackerData = MediaItemTrackerData.EMPTY, val mediaMetadata: MediaMetadata = MediaMetadata.EMPTY, - val blockedIntervals: List = emptyList(), + val blockedIntervals: List = emptyList(), val chapters: List = emptyList(), - val timeIntervals: List = emptyList(), + val timeIntervals: List = emptyList(), ) diff --git a/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/asset/BlockedInterval.kt b/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/asset/BlockedTimeRange.kt similarity index 70% rename from pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/asset/BlockedInterval.kt rename to pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/asset/BlockedTimeRange.kt index 574fbf86f..f6946bf0b 100644 --- a/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/asset/BlockedInterval.kt +++ b/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/asset/BlockedTimeRange.kt @@ -8,20 +8,19 @@ import android.os.Parcel import android.os.Parcelable /** - * Blocked interval + * Blocked time range * * @property id The id of the chapter. * @property start The start position, in milliseconds. * @property end The end position, in milliseconds. * @property reason The block reason. - * @constructor Create empty Blocked interval */ -data class BlockedInterval( +data class BlockedTimeRange( override val id: String, override val start: Long, override val end: Long, val reason: String -) : TimeInterval, Parcelable { +) : TimeRange, Parcelable { constructor(parcel: Parcel) : this( parcel.readString()!!, parcel.readLong(), @@ -41,14 +40,14 @@ data class BlockedInterval( } /** - * Creator create a [BlockedInterval] + * Creator create a [BlockedTimeRange] */ - companion object CREATOR : Parcelable.Creator { - override fun createFromParcel(parcel: Parcel): BlockedInterval { - return BlockedInterval(parcel) + companion object CREATOR : Parcelable.Creator { + override fun createFromParcel(parcel: Parcel): BlockedTimeRange { + return BlockedTimeRange(parcel) } - override fun newArray(size: Int): Array { + override fun newArray(size: Int): Array { return arrayOfNulls(size) } } diff --git a/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/asset/Chapter.kt b/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/asset/Chapter.kt index 734dd82f6..52ff552ea 100644 --- a/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/asset/Chapter.kt +++ b/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/asset/Chapter.kt @@ -21,7 +21,7 @@ data class Chapter( override val start: Long, override val end: Long, val mediaMetadata: MediaMetadata -) : TimeInterval, Parcelable { +) : TimeRange, Parcelable { constructor(parcel: Parcel) : this( parcel.readString()!!, parcel.readLong(), diff --git a/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/asset/PillarboxData.kt b/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/asset/PillarboxData.kt index 30c5a04f3..5f7afe7be 100644 --- a/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/asset/PillarboxData.kt +++ b/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/asset/PillarboxData.kt @@ -10,15 +10,15 @@ import ch.srgssr.pillarbox.player.tracker.MediaItemTrackerData * Pillarbox data * * @property trackersData The [MediaItemTrackerData]. - * @property blockedIntervals The [BlockedInterval] list. + * @property blockedIntervals The [BlockedTimeRange] list. * @property chapters The [Chapter] list. - * @property timeIntervals The [SkipableTimeInterval] list. + * @property timeIntervals The [SkipableTimeRange] list. */ data class PillarboxData( val trackersData: MediaItemTrackerData = MediaItemTrackerData.EMPTY, - val blockedIntervals: List = emptyList(), + val blockedIntervals: List = emptyList(), val chapters: List = emptyList(), - val timeIntervals: List = emptyList(), + val timeIntervals: List = emptyList(), ) { companion object { /** diff --git a/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/asset/SkipableTimeInterval.kt b/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/asset/SkipableTimeRange.kt similarity index 73% rename from pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/asset/SkipableTimeInterval.kt rename to pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/asset/SkipableTimeRange.kt index ce2529028..358521180 100644 --- a/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/asset/SkipableTimeInterval.kt +++ b/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/asset/SkipableTimeRange.kt @@ -14,17 +14,17 @@ import android.os.Parcelable * @property start The start time, in milliseconds, of the time interval. * @property end The end time, in milliseconds, of the time interval. */ -data class SkipableTimeInterval( +data class SkipableTimeRange( override val id: String, override val start: Long, override val end: Long, -) : TimeInterval, Parcelable { +) : TimeRange, Parcelable { /** * The type of time interval. */ - val type: SkipableTimeIntervalType? + val type: SkipableTimeRangeType? get() = runCatching { - enumValueOf(id) + enumValueOf(id) }.getOrNull() constructor(parcel: Parcel) : this( @@ -44,14 +44,14 @@ data class SkipableTimeInterval( } /** - * Creator create a [SkipableTimeInterval] + * Creator create a [SkipableTimeRange] */ - companion object CREATOR : Parcelable.Creator { - override fun createFromParcel(source: Parcel): SkipableTimeInterval { - return SkipableTimeInterval(source) + companion object CREATOR : Parcelable.Creator { + override fun createFromParcel(source: Parcel): SkipableTimeRange { + return SkipableTimeRange(source) } - override fun newArray(size: Int): Array { + override fun newArray(size: Int): Array { return arrayOfNulls(size) } } diff --git a/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/asset/SkipableTimeIntervalType.kt b/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/asset/SkipableTimeRangeType.kt similarity index 72% rename from pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/asset/SkipableTimeIntervalType.kt rename to pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/asset/SkipableTimeRangeType.kt index 31d1376ed..4d4ca038d 100644 --- a/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/asset/SkipableTimeIntervalType.kt +++ b/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/asset/SkipableTimeRangeType.kt @@ -5,9 +5,9 @@ package ch.srgssr.pillarbox.player.asset /** - * The type of skipable time interval. + * The type of skipable time range. */ -enum class SkipableTimeIntervalType { +enum class SkipableTimeRangeType { CLOSING_CREDITS, OPENING_CREDITS, } diff --git a/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/asset/TimeInterval.kt b/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/asset/TimeRange.kt similarity index 94% rename from pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/asset/TimeInterval.kt rename to pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/asset/TimeRange.kt index 06860cd6d..5c3240b16 100644 --- a/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/asset/TimeInterval.kt +++ b/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/asset/TimeRange.kt @@ -9,7 +9,7 @@ import kotlin.math.abs /** * Time interval */ -interface TimeInterval { +interface TimeRange { /** * The id. */ @@ -34,7 +34,7 @@ interface TimeInterval { } /** - * Check if the provided [position][positionMs] is in this [interval][TimeInterval]. + * Check if the provided [position][positionMs] is in this [interval][TimeRange]. * * @param positionMs The position, in milliseconds. * @return `true` if [positionMs] is between [start] (included) and [end] (excluded). diff --git a/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/extension/Player.kt b/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/extension/Player.kt index f1c4f2706..ee9c109ee 100644 --- a/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/extension/Player.kt +++ b/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/extension/Player.kt @@ -10,9 +10,9 @@ import androidx.media3.common.Player import androidx.media3.common.Timeline.Window import androidx.media3.exoplayer.dash.manifest.DashManifest import androidx.media3.exoplayer.hls.HlsManifest -import ch.srgssr.pillarbox.player.asset.BlockedInterval +import ch.srgssr.pillarbox.player.asset.BlockedTimeRange import ch.srgssr.pillarbox.player.asset.Chapter -import ch.srgssr.pillarbox.player.asset.SkipableTimeInterval +import ch.srgssr.pillarbox.player.asset.SkipableTimeRange import kotlin.time.Duration.Companion.microseconds import kotlin.time.Duration.Companion.milliseconds @@ -67,7 +67,7 @@ fun Player.getCurrentChapters(): List { /** * @return The current media item time intervals or an empty list. */ -fun Player.getTimeIntervals(): List { +fun Player.getSkipableTimeRange(): List { return currentMediaItem?.pillarboxData?.timeIntervals.orEmpty() } @@ -88,11 +88,11 @@ fun Player.getChapterAtPosition(positionMs: Long = currentPosition): Chapter? { * @param positionMs The position, in milliseconds, to find the time interval from. * @return `null` if there is no time interval at [positionMs]. */ -fun Player.getTimeIntervalAtPosition(positionMs: Long = currentPosition): SkipableTimeInterval? { +fun Player.getSkipableTimeRangeAtPosition(positionMs: Long = currentPosition): SkipableTimeRange? { return if (positionMs == C.TIME_UNSET) { null } else { - getTimeIntervals().firstOrNull { positionMs in it } + getSkipableTimeRange().firstOrNull { positionMs in it } } } @@ -125,7 +125,7 @@ fun Player.isAtLiveEdge(positionMs: Long = currentPosition, window: Window = Win /** * @return The current media item blocked intervals or an empty list. */ -fun Player.getCurrentBlockedIntervals(): List { +fun Player.getCurrentBlockedIntervals(): List { return currentMediaItem?.pillarboxData?.blockedIntervals ?: emptyList() } @@ -133,9 +133,9 @@ fun Player.getCurrentBlockedIntervals(): List { * Get the blocked interval at [position][positionMs]. * * @param positionMs The position, in milliseconds, to find the block interval from. - * @return `null` if there is no [BlockedInterval] at [positionMs]. + * @return `null` if there is no [BlockedTimeRange] at [positionMs]. */ -fun Player.getBlockedIntervalAtPosition(positionMs: Long = currentPosition): BlockedInterval? { +fun Player.getBlockedIntervalAtPosition(positionMs: Long = currentPosition): BlockedTimeRange? { if (positionMs == C.TIME_UNSET) return null return getCurrentBlockedIntervals().firstOrNull { positionMs in it } } diff --git a/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/session/PillarboxMediaController.kt b/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/session/PillarboxMediaController.kt index 48d7a438b..09cc31f2e 100644 --- a/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/session/PillarboxMediaController.kt +++ b/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/session/PillarboxMediaController.kt @@ -39,9 +39,9 @@ import androidx.media3.session.SessionCommands import androidx.media3.session.SessionResult import androidx.media3.session.SessionToken import ch.srgssr.pillarbox.player.PillarboxPlayer -import ch.srgssr.pillarbox.player.asset.BlockedInterval +import ch.srgssr.pillarbox.player.asset.BlockedTimeRange import ch.srgssr.pillarbox.player.asset.Chapter -import ch.srgssr.pillarbox.player.asset.SkipableTimeInterval +import ch.srgssr.pillarbox.player.asset.SkipableTimeRange import ch.srgssr.pillarbox.player.utils.DebugLogger import com.google.common.collect.ImmutableList import com.google.common.util.concurrent.Futures @@ -260,7 +260,7 @@ open class PillarboxMediaController internal constructor() : PillarboxPlayer { } PillarboxSessionCommands.BLOCKED_INTERVAL_CHANGED -> { - val blockedInterval = BundleCompat.getParcelable(args, PillarboxSessionCommands.ARG_BLOCKED_INTERVAL, BlockedInterval::class.java) + val blockedInterval = BundleCompat.getParcelable(args, PillarboxSessionCommands.ARG_BLOCKED_INTERVAL, BlockedTimeRange::class.java) blockedInterval?.let { listeners.forEach { listener -> listener.onBlockIntervalReached(blockedInterval) @@ -269,7 +269,7 @@ open class PillarboxMediaController internal constructor() : PillarboxPlayer { } PillarboxSessionCommands.TIME_INTERVAL_CHANGED -> { - val timeInterval = BundleCompat.getParcelable(args, PillarboxSessionCommands.ARG_TIME_INTERVAL, SkipableTimeInterval::class.java) + val timeInterval = BundleCompat.getParcelable(args, PillarboxSessionCommands.ARG_TIME_INTERVAL, SkipableTimeRange::class.java) timeInterval?.let { listeners.forEach { listener -> listener.onTimeIntervalChanged(timeInterval) diff --git a/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/session/PillarboxMediaSession.kt b/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/session/PillarboxMediaSession.kt index 635ca7841..36b4715a1 100644 --- a/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/session/PillarboxMediaSession.kt +++ b/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/session/PillarboxMediaSession.kt @@ -18,9 +18,9 @@ import androidx.media3.session.SessionCommand import androidx.media3.session.SessionCommands import androidx.media3.session.SessionResult import ch.srgssr.pillarbox.player.PillarboxPlayer -import ch.srgssr.pillarbox.player.asset.BlockedInterval +import ch.srgssr.pillarbox.player.asset.BlockedTimeRange import ch.srgssr.pillarbox.player.asset.Chapter -import ch.srgssr.pillarbox.player.asset.SkipableTimeInterval +import ch.srgssr.pillarbox.player.asset.SkipableTimeRange import ch.srgssr.pillarbox.player.utils.DebugLogger import com.google.common.util.concurrent.Futures import com.google.common.util.concurrent.ListenableFuture @@ -208,7 +208,7 @@ open class PillarboxMediaSession internal constructor() { } } - override fun onBlockIntervalReached(blockedInterval: BlockedInterval) { + override fun onBlockIntervalReached(blockedInterval: BlockedTimeRange) { val commandArg = Bundle().apply { putParcelable(PillarboxSessionCommands.ARG_BLOCKED_INTERVAL, blockedInterval) } @@ -217,7 +217,7 @@ open class PillarboxMediaSession internal constructor() { } } - override fun onTimeIntervalChanged(timeInterval: SkipableTimeInterval?) { + override fun onTimeIntervalChanged(timeInterval: SkipableTimeRange?) { val commandArg = Bundle().apply { putParcelable(PillarboxSessionCommands.ARG_TIME_INTERVAL, timeInterval) } diff --git a/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/tracker/BlockedIntervalTracker.kt b/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/tracker/BlockedTimeRangeTracker.kt similarity index 85% rename from pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/tracker/BlockedIntervalTracker.kt rename to pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/tracker/BlockedTimeRangeTracker.kt index 819cd5768..61c998a6d 100644 --- a/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/tracker/BlockedIntervalTracker.kt +++ b/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/tracker/BlockedTimeRangeTracker.kt @@ -9,18 +9,18 @@ import androidx.media3.common.MediaItem import androidx.media3.common.Player import androidx.media3.exoplayer.PlayerMessage import ch.srgssr.pillarbox.player.PillarboxExoPlayer -import ch.srgssr.pillarbox.player.asset.BlockedInterval +import ch.srgssr.pillarbox.player.asset.BlockedTimeRange import ch.srgssr.pillarbox.player.asset.PillarboxData import ch.srgssr.pillarbox.player.extension.pillarboxData /** - * Blocked interval tracker that seeks to [BlockedInterval.end] when the player reaches the segment. + * Blocked range tracker that seeks to [BlockedTimeRange.end] when the player reaches the segment. */ -internal class BlockedIntervalTracker( +internal class BlockedTimeRangeTracker( private val pillarboxExoPlayer: PillarboxExoPlayer ) : CurrentMediaItemPillarboxDataTracker.Callback { private val listPlayerMessage = mutableListOf() - private var listBlockedIntervals = emptyList() + private var listBlockedIntervals = emptyList() private val listener = Listener() override fun onPillarboxDataChanged(mediaItem: MediaItem?, data: PillarboxData?) { @@ -32,7 +32,7 @@ internal class BlockedIntervalTracker( createMessages() } - private fun notifyBlockedSegment(blockedSection: BlockedInterval) { + private fun notifyBlockedSegment(blockedSection: BlockedTimeRange) { Log.i(TAG, "Blocked segment reached $blockedSection") pillarboxExoPlayer.notifyBlockedIntervalReached(blockedSection) pillarboxExoPlayer.seekToWithoutSmoothSeeking(blockedSection.end + 1) @@ -41,7 +41,7 @@ internal class BlockedIntervalTracker( private fun createMessages() { listBlockedIntervals.forEach { val message = pillarboxExoPlayer.createMessage { _, message -> - val segment = message as BlockedInterval + val segment = message as BlockedTimeRange notifyBlockedSegment(segment) }.apply { deleteAfterDelivery = false diff --git a/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/tracker/TimeIntervalTracker.kt b/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/tracker/TimeRangeTracker.kt similarity index 93% rename from pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/tracker/TimeIntervalTracker.kt rename to pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/tracker/TimeRangeTracker.kt index ff2d41ad0..88b44774f 100644 --- a/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/tracker/TimeIntervalTracker.kt +++ b/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/tracker/TimeRangeTracker.kt @@ -10,17 +10,17 @@ import androidx.media3.common.Player.DiscontinuityReason import androidx.media3.exoplayer.PlayerMessage import ch.srgssr.pillarbox.player.PillarboxExoPlayer import ch.srgssr.pillarbox.player.asset.PillarboxData -import ch.srgssr.pillarbox.player.asset.TimeInterval +import ch.srgssr.pillarbox.player.asset.TimeRange import ch.srgssr.pillarbox.player.extension.pillarboxData -internal class TimeIntervalTracker( +internal class TimeRangeTracker( private val player: PillarboxExoPlayer, private val getTimeIntervalAtPosition: PillarboxExoPlayer.(position: Long) -> T?, private val getAllTimeIntervals: PillarboxData.() -> List, private val notifyTimeIntervalChanged: PillarboxExoPlayer.(timeInterval: T?) -> Unit, ) : CurrentMediaItemPillarboxDataTracker.Callback { private val playerMessages = mutableListOf() - private var timeIntervals = emptyList() + private var timeRanges = emptyList() private val listener = Listener() private var lastTimeInterval: T? = player.getTimeIntervalAtPosition(player.currentPosition) @@ -39,7 +39,7 @@ internal class TimeIntervalTracker( return } - timeIntervals = mediaItem.pillarboxData.getAllTimeIntervals() + timeRanges = mediaItem.pillarboxData.getAllTimeIntervals() player.addListener(listener) createPlayerMessages() } @@ -60,7 +60,7 @@ internal class TimeIntervalTracker( } } - timeIntervals.forEach { timeInterval -> + timeRanges.forEach { timeInterval -> val messageEnter = player.createMessage(messageHandler).apply { deleteAfterDelivery = false looper = player.applicationLooper diff --git a/pillarbox-player/src/test/java/ch/srgssr/pillarbox/player/asset/SkipableTimeIntervalTest.kt b/pillarbox-player/src/test/java/ch/srgssr/pillarbox/player/asset/SkipableTimeRangeTest.kt similarity index 71% rename from pillarbox-player/src/test/java/ch/srgssr/pillarbox/player/asset/SkipableTimeIntervalTest.kt rename to pillarbox-player/src/test/java/ch/srgssr/pillarbox/player/asset/SkipableTimeRangeTest.kt index 7fcb2c86c..23eb92d60 100644 --- a/pillarbox-player/src/test/java/ch/srgssr/pillarbox/player/asset/SkipableTimeIntervalTest.kt +++ b/pillarbox-player/src/test/java/ch/srgssr/pillarbox/player/asset/SkipableTimeRangeTest.kt @@ -8,10 +8,10 @@ import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertNull -class SkipableTimeIntervalTest { +class SkipableTimeRangeTest { @Test fun `SkipableTimeInterval#type with empty id`() { - val timeInterval = SkipableTimeInterval( + val timeInterval = SkipableTimeRange( id = "", start = 0L, end = 10L, @@ -22,7 +22,7 @@ class SkipableTimeIntervalTest { @Test fun `SkipableTimeInterval#type with unknown id`() { - val timeInterval = SkipableTimeInterval( + val timeInterval = SkipableTimeRange( id = "CLOSING", start = 0L, end = 10L, @@ -33,23 +33,23 @@ class SkipableTimeIntervalTest { @Test fun `SkipableTimeInterval#type with id=CLOSING_CREDITS`() { - val timeInterval = SkipableTimeInterval( + val timeInterval = SkipableTimeRange( id = "CLOSING_CREDITS", start = 0L, end = 10L, ) - assertEquals(SkipableTimeIntervalType.CLOSING_CREDITS, timeInterval.type) + assertEquals(SkipableTimeRangeType.CLOSING_CREDITS, timeInterval.type) } @Test fun `SkipableTimeInterval#type with id=OPENING_CREDITS`() { - val timeInterval = SkipableTimeInterval( + val timeInterval = SkipableTimeRange( id = "OPENING_CREDITS", start = 0L, end = 10L, ) - assertEquals(SkipableTimeIntervalType.OPENING_CREDITS, timeInterval.type) + assertEquals(SkipableTimeRangeType.OPENING_CREDITS, timeInterval.type) } } diff --git a/pillarbox-player/src/test/java/ch/srgssr/pillarbox/player/extension/PlayerTest.kt b/pillarbox-player/src/test/java/ch/srgssr/pillarbox/player/extension/PlayerTest.kt index eef34c47b..606b81e25 100644 --- a/pillarbox-player/src/test/java/ch/srgssr/pillarbox/player/extension/PlayerTest.kt +++ b/pillarbox-player/src/test/java/ch/srgssr/pillarbox/player/extension/PlayerTest.kt @@ -9,7 +9,7 @@ import androidx.media3.common.PlaybackParameters import androidx.media3.common.Player import androidx.test.ext.junit.runners.AndroidJUnit4 import ch.srgssr.pillarbox.player.asset.PillarboxData -import ch.srgssr.pillarbox.player.asset.SkipableTimeInterval +import ch.srgssr.pillarbox.player.asset.SkipableTimeRange import io.mockk.every import io.mockk.mockk import org.junit.runner.RunWith @@ -94,7 +94,7 @@ class PlayerTest { every { currentMediaItem } returns null } - assertEquals(emptyList(), player.getTimeIntervals()) + assertEquals(emptyList(), player.getSkipableTimeRange()) } @Test @@ -103,7 +103,7 @@ class PlayerTest { every { currentMediaItem } returns MediaItem.Builder().build() } - assertEquals(emptyList(), player.getTimeIntervals()) + assertEquals(emptyList(), player.getSkipableTimeRange()) } @Test @@ -115,12 +115,12 @@ class PlayerTest { .build() } - assertEquals(emptyList(), player.getTimeIntervals()) + assertEquals(emptyList(), player.getSkipableTimeRange()) } @Test fun `getTimeIntervals, with MediaItem, with PillarboxData, with time intervals`() { - val timeIntervals = listOf(mockk()) + val timeIntervals = listOf(mockk()) val player = mockk { every { currentMediaItem } returns MediaItem.Builder() .setUri("https://example.com/") @@ -128,6 +128,6 @@ class PlayerTest { .build() } - assertEquals(timeIntervals, player.getTimeIntervals()) + assertEquals(timeIntervals, player.getSkipableTimeRange()) } } diff --git a/pillarbox-player/src/test/java/ch/srgssr/pillarbox/player/tracker/BlockedIntervalTrackerTest.kt b/pillarbox-player/src/test/java/ch/srgssr/pillarbox/player/tracker/BlockedTimeRangeTrackerTest.kt similarity index 92% rename from pillarbox-player/src/test/java/ch/srgssr/pillarbox/player/tracker/BlockedIntervalTrackerTest.kt rename to pillarbox-player/src/test/java/ch/srgssr/pillarbox/player/tracker/BlockedTimeRangeTrackerTest.kt index 2fcbe02c2..6305f182d 100644 --- a/pillarbox-player/src/test/java/ch/srgssr/pillarbox/player/tracker/BlockedIntervalTrackerTest.kt +++ b/pillarbox-player/src/test/java/ch/srgssr/pillarbox/player/tracker/BlockedTimeRangeTrackerTest.kt @@ -18,7 +18,7 @@ import ch.srgssr.pillarbox.player.PillarboxPlayer import ch.srgssr.pillarbox.player.SeekIncrement import ch.srgssr.pillarbox.player.asset.Asset import ch.srgssr.pillarbox.player.asset.AssetLoader -import ch.srgssr.pillarbox.player.asset.BlockedInterval +import ch.srgssr.pillarbox.player.asset.BlockedTimeRange import ch.srgssr.pillarbox.player.source.PillarboxMediaSourceFactory import io.mockk.clearAllMocks import io.mockk.spyk @@ -31,7 +31,7 @@ import kotlin.test.Test import kotlin.test.assertEquals @RunWith(AndroidJUnit4::class) -class BlockedIntervalTrackerTest { +class BlockedTimeRangeTrackerTest { private lateinit var player: PillarboxExoPlayer private lateinit var fakeClock: FakeClock @@ -70,7 +70,7 @@ class BlockedIntervalTrackerTest { TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_ENDED) - val receivedBlockedIntervals = mutableListOf() + val receivedBlockedIntervals = mutableListOf() verifyOrder { listener.onBlockIntervalReached(capture(receivedBlockedIntervals)) listener.onBlockIntervalReached(capture(receivedBlockedIntervals)) @@ -89,7 +89,7 @@ class BlockedIntervalTrackerTest { TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY) - val receivedBlockedIntervals = mutableListOf() + val receivedBlockedIntervals = mutableListOf() verify { listener.onBlockIntervalReached(capture(receivedBlockedIntervals)) } @@ -132,8 +132,8 @@ private class BlockedAssetLoader(context: Context) : AssetLoader(DefaultMediaSou private const val URL = "https://rts-vod-amd.akamaized.net/ww/13317145/f1d49f18-f302-37ce-866c-1c1c9b76a824/master.m3u8" const val NEAR_END_POSITION_MS = 15_000L // the video has 17 sec duration - val START_SEGMENT = BlockedInterval("id:1", start = 0, end = 5, reason = "reason") - val SEGMENT = BlockedInterval("id:2", start = 10, end = 13, reason = "reason") + val START_SEGMENT = BlockedTimeRange("id:1", start = 0, end = 5, reason = "reason") + val SEGMENT = BlockedTimeRange("id:2", start = 10, end = 13, reason = "reason") private fun createMediaItem(mediaId: String) = MediaItem.Builder() .setUri(URL) diff --git a/pillarbox-player/src/test/java/ch/srgssr/pillarbox/player/tracker/TimeIntervalTrackerTest.kt b/pillarbox-player/src/test/java/ch/srgssr/pillarbox/player/tracker/TimeRangeTrackerTest.kt similarity index 99% rename from pillarbox-player/src/test/java/ch/srgssr/pillarbox/player/tracker/TimeIntervalTrackerTest.kt rename to pillarbox-player/src/test/java/ch/srgssr/pillarbox/player/tracker/TimeRangeTrackerTest.kt index d2c5b6938..7eb19027c 100644 --- a/pillarbox-player/src/test/java/ch/srgssr/pillarbox/player/tracker/TimeIntervalTrackerTest.kt +++ b/pillarbox-player/src/test/java/ch/srgssr/pillarbox/player/tracker/TimeRangeTrackerTest.kt @@ -31,7 +31,7 @@ import kotlin.test.Test import kotlin.test.assertEquals @RunWith(AndroidJUnit4::class) -class TimeIntervalTrackerTest { +class TimeRangeTrackerTest { private lateinit var player: PillarboxExoPlayer private lateinit var fakeClock: FakeClock private lateinit var listener: PillarboxPlayer.Listener diff --git a/pillarbox-ui/src/main/java/ch/srgssr/pillarbox/ui/extension/ComposablePlayer.kt b/pillarbox-ui/src/main/java/ch/srgssr/pillarbox/ui/extension/ComposablePlayer.kt index d69c95a35..b7bb2e997 100644 --- a/pillarbox-ui/src/main/java/ch/srgssr/pillarbox/ui/extension/ComposablePlayer.kt +++ b/pillarbox-ui/src/main/java/ch/srgssr/pillarbox/ui/extension/ComposablePlayer.kt @@ -24,7 +24,7 @@ import androidx.media3.common.Player.Commands import androidx.media3.common.VideoSize import ch.srgssr.pillarbox.player.DefaultUpdateInterval import ch.srgssr.pillarbox.player.asset.Chapter -import ch.srgssr.pillarbox.player.asset.SkipableTimeInterval +import ch.srgssr.pillarbox.player.asset.SkipableTimeRange import ch.srgssr.pillarbox.player.availableCommandsAsFlow import ch.srgssr.pillarbox.player.currentBufferedPercentageAsFlow import ch.srgssr.pillarbox.player.currentMediaMetadataAsFlow @@ -33,12 +33,12 @@ import ch.srgssr.pillarbox.player.durationAsFlow import ch.srgssr.pillarbox.player.extension.getChapterAtPosition import ch.srgssr.pillarbox.player.extension.getCurrentMediaItems import ch.srgssr.pillarbox.player.extension.getPlaybackSpeed -import ch.srgssr.pillarbox.player.extension.getTimeIntervalAtPosition +import ch.srgssr.pillarbox.player.extension.getSkipableTimeRangeAtPosition import ch.srgssr.pillarbox.player.getAspectRatioAsFlow import ch.srgssr.pillarbox.player.getCurrentChapterAsFlow import ch.srgssr.pillarbox.player.getCurrentMediaItemIndexAsFlow import ch.srgssr.pillarbox.player.getCurrentMediaItemsAsFlow -import ch.srgssr.pillarbox.player.getCurrentTimeIntervalAsFlow +import ch.srgssr.pillarbox.player.getCurrentSkipableTimeRangeAsFlow import ch.srgssr.pillarbox.player.getPlaybackSpeedAsFlow import ch.srgssr.pillarbox.player.isCurrentMediaItemLiveAsFlow import ch.srgssr.pillarbox.player.isPlayingAsFlow @@ -267,12 +267,12 @@ fun Player.getCurrentChapterAsState(): State { } /** - * @return Get the current time interval as state, when the time interval changes. + * @return Get the current time range as state, when the time interval changes. */ @Composable -fun Player.getCurrentTimeIntervalAsState(): State { +fun Player.getCurrentTimeRangeAsState(): State { val flow = remember(this) { - getCurrentTimeIntervalAsFlow() + getCurrentSkipableTimeRangeAsFlow() } - return flow.collectAsState(initial = getTimeIntervalAtPosition()) + return flow.collectAsState(initial = getSkipableTimeRangeAtPosition()) }