Skip to content

Commit

Permalink
Renaming to TimeRange
Browse files Browse the repository at this point in the history
  • Loading branch information
StaehliJ committed Apr 30, 2024
1 parent beadf46 commit dc9e248
Show file tree
Hide file tree
Showing 29 changed files with 135 additions and 136 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Segment>?): List<BlockedInterval> {
fun getBlockedIntervals(listSegment: List<Segment>?): List<BlockedTimeRange> {
return listSegment?.filter { it.blockReason != null }?.map {
getBlockedInterval(it)
} ?: emptyList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<TimeInterval>?): List<SkipableTimeInterval> {
internal fun getTimeIntervals(timeIntervals: List<TimeInterval>?): List<SkipableTimeRange> {
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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))
}

Expand Down Expand Up @@ -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))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
}
Expand All @@ -74,7 +74,7 @@ fun BlockedIntervalWarning(

@Composable
private fun BlockedSegmentInfo(
blockedInterval: BlockedInterval,
blockedInterval: BlockedTimeRange,
modifier: Modifier = Modifier
) {
Text(
Expand All @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -85,7 +85,7 @@ fun PlayerView(
autoHideEnabled = !isSliderDragged,
visible = controlsVisible
)
val timeInterval by player.getCurrentTimeIntervalAsState()
val timeInterval by player.getCurrentTimeRangeAsState()

ToggleableBox(
modifier = modifier,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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())
}
Expand Down Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand All @@ -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?) {}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -406,16 +406,16 @@ fun Player.getCurrentChapterAsFlow(): Flow<Chapter?> = 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<SkipableTimeInterval?> = callbackFlow {
fun Player.getCurrentSkipableTimeRangeAsFlow(): Flow<SkipableTimeRange?> = 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 <T> ProducerScope<T>.addPlayerListener(player: Player, listener: Listener) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<BlockedInterval> = emptyList(),
val blockedIntervals: List<BlockedTimeRange> = emptyList(),
val chapters: List<Chapter> = emptyList(),
val timeIntervals: List<SkipableTimeInterval> = emptyList(),
val timeIntervals: List<SkipableTimeRange> = emptyList(),
)
Loading

0 comments on commit dc9e248

Please sign in to comment.