Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate TimeRanges are it is a sealed interface and we don't really … #524

Merged
merged 2 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ class SRGAssetLoader(
mediaComposition = result,
)
}.build(),
timeRanges = ChapterAdapter.getChapters(result) +
TimeIntervalAdapter.getCredits(result.mainChapter.timeIntervalList) +
SegmentAdapter.getBlockedTimeRanges(chapter.listSegment),
blockedTimeRanges = SegmentAdapter.getBlockedTimeRanges(chapter.listSegment),
chapters = ChapterAdapter.getChapters(result),
credits = TimeIntervalAdapter.getCredits(result.mainChapter.timeIntervalList),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class SRGAssetLoaderTest {
SRGMediaItemBuilder(DummyMediaCompositionProvider.URN_SEGMENT_BLOCK_REASON).build()
)
val expectedBlockTimeRanges = listOf(SegmentAdapter.getBlockedTimeRange(DummyMediaCompositionProvider.BLOCKED_SEGMENT))
assertEquals(expectedBlockTimeRanges, asset.timeRanges)
assertEquals(expectedBlockTimeRanges, asset.blockedTimeRanges)
}

@Test
Expand All @@ -160,7 +160,7 @@ class SRGAssetLoaderTest {
val expectedCredits = TimeIntervalAdapter.getCredits(
listOf(DummyMediaCompositionProvider.TIME_INTERVAL_1, DummyMediaCompositionProvider.TIME_INTERVAL_2)
)
assertEquals(expectedCredits, asset.timeRanges)
assertEquals(expectedCredits, asset.credits)
}

internal class DummyMediaCompositionProvider : MediaCompositionService {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ package ch.srgssr.pillarbox.player.asset

import androidx.media3.common.MediaMetadata
import androidx.media3.exoplayer.source.MediaSource
import ch.srgssr.pillarbox.player.asset.timeRange.TimeRange
import ch.srgssr.pillarbox.player.asset.timeRange.BlockedTimeRange
import ch.srgssr.pillarbox.player.asset.timeRange.Chapter
import ch.srgssr.pillarbox.player.asset.timeRange.Credit
import ch.srgssr.pillarbox.player.tracker.MediaItemTrackerData

/**
Expand All @@ -15,11 +17,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 timeRanges The [TimeRange] list to set to the [PillarboxData].
* @property blockedTimeRanges The [BlockedTimeRange] list.
* @property chapters The [Chapter] list.
* @property credits The [Credit] list.
*/
data class Asset(
val mediaSource: MediaSource,
val trackersData: MediaItemTrackerData = MediaItemTrackerData.EMPTY,
val mediaMetadata: MediaMetadata = MediaMetadata.EMPTY,
val timeRanges: List<TimeRange> = emptyList(),
val blockedTimeRanges: List<BlockedTimeRange> = emptyList(),
val chapters: List<Chapter> = emptyList(),
val credits: List<Credit> = emptyList(),
)
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ import androidx.media3.exoplayer.source.TimelineWithUpdatedMediaItem
import androidx.media3.exoplayer.upstream.Allocator
import ch.srgssr.pillarbox.player.asset.AssetLoader
import ch.srgssr.pillarbox.player.asset.PillarboxData
import ch.srgssr.pillarbox.player.asset.timeRange.BlockedTimeRange
import ch.srgssr.pillarbox.player.asset.timeRange.Chapter
import ch.srgssr.pillarbox.player.asset.timeRange.Credit
import ch.srgssr.pillarbox.player.utils.DebugLogger
import kotlinx.coroutines.runBlocking

Expand Down Expand Up @@ -53,9 +50,9 @@ class PillarboxMediaSource internal constructor(
.setTag(
PillarboxData(
trackersData = asset.trackersData,
blockedTimeRanges = asset.timeRanges.filterIsInstance<BlockedTimeRange>(),
chapters = asset.timeRanges.filterIsInstance<Chapter>(),
credits = asset.timeRanges.filterIsInstance<Credit>(),
blockedTimeRanges = asset.blockedTimeRanges,
chapters = asset.chapters,
credits = asset.credits,
)
)
.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ private class BlockedAssetLoader(context: Context) : AssetLoader(DefaultMediaSou

override suspend fun loadAsset(mediaItem: MediaItem): Asset {
val itemBuilder = mediaItem.buildUpon()
val timeRanges = when (mediaItem.mediaId) {
val listBlockedTimeRanges = when (mediaItem.mediaId) {
MEDIA_ONE_SEGMENT.mediaId -> {
listOf(SEGMENT)
}
Expand All @@ -121,7 +121,7 @@ private class BlockedAssetLoader(context: Context) : AssetLoader(DefaultMediaSou
return Asset(
mediaSource = mediaSourceFactory.createMediaSource(itemBuilder.build()),
mediaMetadata = mediaItem.mediaMetadata,
timeRanges = timeRanges,
blockedTimeRanges = listBlockedTimeRanges,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private class ChapterAssetLoader(context: Context) : AssetLoader(DefaultMediaSou
return Asset(
mediaSource = mediaSourceFactory.createMediaSource(itemBuilder.build()),
mediaMetadata = mediaItem.mediaMetadata,
timeRanges = listOf(CHAPTER_1, CHAPTER_2)
chapters = listOf(CHAPTER_1, CHAPTER_2)
)
}

Expand Down
Loading