Search in sources :

Example 11 with SinglePeriodTimeline

use of androidx.media3.exoplayer.source.SinglePeriodTimeline in project media by androidx.

the class ClippingMediaSourceTest method allowDynamicUpdatesWithNonOverlappingLiveWindow.

@Test
public void allowDynamicUpdatesWithNonOverlappingLiveWindow() throws IOException {
    Timeline timeline1 = new SinglePeriodTimeline(/* periodDurationUs= */
    2 * TEST_PERIOD_DURATION_US, /* windowDurationUs= */
    TEST_PERIOD_DURATION_US, /* windowPositionInPeriodUs= */
    TEST_PERIOD_DURATION_US, /* windowDefaultStartPositionUs= */
    TEST_CLIP_AMOUNT_US, /* isSeekable= */
    true, /* isDynamic= */
    true, /* useLiveConfiguration= */
    true, /* manifest= */
    null, MediaItem.fromUri(Uri.EMPTY));
    Timeline timeline2 = new SinglePeriodTimeline(/* periodDurationUs= */
    4 * TEST_PERIOD_DURATION_US, /* windowDurationUs= */
    TEST_PERIOD_DURATION_US, /* windowPositionInPeriodUs= */
    3 * TEST_PERIOD_DURATION_US, /* windowDefaultStartPositionUs= */
    TEST_CLIP_AMOUNT_US, /* isSeekable= */
    true, /* isDynamic= */
    true, /* useLiveConfiguration= */
    true, /* manifest= */
    null, MediaItem.fromUri(Uri.EMPTY));
    Timeline[] clippedTimelines = getClippedTimelines(/* startUs= */
    0, /* endUs= */
    TEST_PERIOD_DURATION_US, /* allowDynamicUpdates= */
    true, /* fromDefaultPosition= */
    true, timeline1, timeline2);
    assertThat(clippedTimelines[0].getWindow(0, window).getDurationUs()).isEqualTo(TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US);
    assertThat(clippedTimelines[0].getWindow(0, window).getDefaultPositionUs()).isEqualTo(0);
    assertThat(clippedTimelines[0].getWindow(0, window).isDynamic).isTrue();
    assertThat(clippedTimelines[0].getWindow(0, window).getPositionInFirstPeriodUs()).isEqualTo(TEST_PERIOD_DURATION_US + TEST_CLIP_AMOUNT_US);
    assertThat(clippedTimelines[0].getPeriod(0, period).getDurationUs()).isEqualTo(2 * TEST_PERIOD_DURATION_US);
    assertThat(clippedTimelines[1].getWindow(0, window).getDurationUs()).isEqualTo(TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US);
    assertThat(clippedTimelines[1].getWindow(0, window).getDefaultPositionUs()).isEqualTo(0);
    assertThat(clippedTimelines[1].getWindow(0, window).isDynamic).isTrue();
    assertThat(clippedTimelines[1].getWindow(0, window).getPositionInFirstPeriodUs()).isEqualTo(3 * TEST_PERIOD_DURATION_US + TEST_CLIP_AMOUNT_US);
    assertThat(clippedTimelines[1].getPeriod(0, period).getDurationUs()).isEqualTo(4 * TEST_PERIOD_DURATION_US);
}
Also used : FakeTimeline(androidx.media3.test.utils.FakeTimeline) PlaceholderTimeline(androidx.media3.exoplayer.source.MaskingMediaSource.PlaceholderTimeline) Timeline(androidx.media3.common.Timeline) Test(org.junit.Test)

Example 12 with SinglePeriodTimeline

use of androidx.media3.exoplayer.source.SinglePeriodTimeline in project media by androidx.

the class ClippingMediaSourceTest method clippingStart.

@Test
public void clippingStart() throws IOException {
    Timeline timeline = new SinglePeriodTimeline(TEST_PERIOD_DURATION_US, /* isSeekable= */
    true, /* isDynamic= */
    false, /* useLiveConfiguration= */
    false, /* manifest= */
    null, MediaItem.fromUri(Uri.EMPTY));
    Timeline clippedTimeline = getClippedTimeline(timeline, TEST_CLIP_AMOUNT_US, TEST_PERIOD_DURATION_US);
    assertThat(clippedTimeline.getWindow(0, window).getDurationUs()).isEqualTo(TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US);
    assertThat(clippedTimeline.getPeriod(0, period).getDurationUs()).isEqualTo(TEST_PERIOD_DURATION_US);
}
Also used : FakeTimeline(androidx.media3.test.utils.FakeTimeline) PlaceholderTimeline(androidx.media3.exoplayer.source.MaskingMediaSource.PlaceholderTimeline) Timeline(androidx.media3.common.Timeline) Test(org.junit.Test)

Example 13 with SinglePeriodTimeline

use of androidx.media3.exoplayer.source.SinglePeriodTimeline in project media by androidx.

the class ClippingMediaSourceTest method clippingStartAndEnd.

@Test
public void clippingStartAndEnd() throws IOException {
    Timeline timeline = new SinglePeriodTimeline(TEST_PERIOD_DURATION_US, /* isSeekable= */
    true, /* isDynamic= */
    false, /* useLiveConfiguration= */
    false, /* manifest= */
    null, MediaItem.fromUri(Uri.EMPTY));
    Timeline clippedTimeline = getClippedTimeline(timeline, TEST_CLIP_AMOUNT_US, TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US * 2);
    assertThat(clippedTimeline.getWindow(0, window).getDurationUs()).isEqualTo(TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US * 3);
    assertThat(clippedTimeline.getPeriod(0, period).getDurationUs()).isEqualTo(TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US * 2);
}
Also used : FakeTimeline(androidx.media3.test.utils.FakeTimeline) PlaceholderTimeline(androidx.media3.exoplayer.source.MaskingMediaSource.PlaceholderTimeline) Timeline(androidx.media3.common.Timeline) Test(org.junit.Test)

Example 14 with SinglePeriodTimeline

use of androidx.media3.exoplayer.source.SinglePeriodTimeline in project media by androidx.

the class ClippingMediaSourceTest method clippingToEndOfSourceWithUnsetDurationDoesNotSetDuration.

@Test
public void clippingToEndOfSourceWithUnsetDurationDoesNotSetDuration() throws IOException {
    // Create a child timeline that has an unknown duration.
    Timeline timeline = new SinglePeriodTimeline(/* durationUs= */
    C.TIME_UNSET, /* isSeekable= */
    true, /* isDynamic= */
    false, /* useLiveConfiguration= */
    false, /* manifest= */
    null, MediaItem.fromUri(Uri.EMPTY));
    // When clipping to the end, the clipped timeline should also have an unset duration.
    Timeline clippedTimeline = getClippedTimeline(timeline, TEST_CLIP_AMOUNT_US, C.TIME_END_OF_SOURCE);
    assertThat(clippedTimeline.getWindow(/* windowIndex= */
    0, window).getDurationUs()).isEqualTo(C.TIME_UNSET);
}
Also used : FakeTimeline(androidx.media3.test.utils.FakeTimeline) PlaceholderTimeline(androidx.media3.exoplayer.source.MaskingMediaSource.PlaceholderTimeline) Timeline(androidx.media3.common.Timeline) Test(org.junit.Test)

Example 15 with SinglePeriodTimeline

use of androidx.media3.exoplayer.source.SinglePeriodTimeline in project media by androidx.

the class ClippingMediaSourceTest method clippingUnseekableWindowWithUnknownDurationThrows.

@Test
public void clippingUnseekableWindowWithUnknownDurationThrows() throws IOException {
    Timeline timeline = new SinglePeriodTimeline(/* durationUs= */
    C.TIME_UNSET, /* isSeekable= */
    false, /* isDynamic= */
    false, /* useLiveConfiguration= */
    false, /* manifest= */
    null, MediaItem.fromUri(Uri.EMPTY));
    // If the unseekable window isn't clipped, clipping succeeds.
    getClippedTimeline(timeline, /* startUs= */
    0, TEST_PERIOD_DURATION_US);
    try {
        // If the unseekable window is clipped, clipping fails.
        getClippedTimeline(timeline, /* startUs= */
        1, TEST_PERIOD_DURATION_US);
        fail("Expected clipping to fail.");
    } catch (IllegalClippingException e) {
        assertThat(e.reason).isEqualTo(IllegalClippingException.REASON_NOT_SEEKABLE_TO_START);
    }
}
Also used : FakeTimeline(androidx.media3.test.utils.FakeTimeline) PlaceholderTimeline(androidx.media3.exoplayer.source.MaskingMediaSource.PlaceholderTimeline) Timeline(androidx.media3.common.Timeline) IllegalClippingException(androidx.media3.exoplayer.source.ClippingMediaSource.IllegalClippingException) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)18 Timeline (androidx.media3.common.Timeline)17 FakeTimeline (androidx.media3.test.utils.FakeTimeline)17 PlaceholderTimeline (androidx.media3.exoplayer.source.MaskingMediaSource.PlaceholderTimeline)13 SinglePeriodTimeline (androidx.media3.exoplayer.source.SinglePeriodTimeline)4 AdPlaybackState (androidx.media3.common.AdPlaybackState)2 MediaItem (androidx.media3.common.MediaItem)2 IllegalClippingException (androidx.media3.exoplayer.source.ClippingMediaSource.IllegalClippingException)2 Pair (android.util.Pair)1 Window (androidx.media3.common.Timeline.Window)1 StreamElement (androidx.media3.exoplayer.smoothstreaming.manifest.SsManifest.StreamElement)1 ForwardingTimeline (androidx.media3.exoplayer.source.ForwardingTimeline)1 MediaPeriod (androidx.media3.exoplayer.source.MediaPeriod)1 FakeClock (androidx.media3.test.utils.FakeClock)1 FakeMediaSource (androidx.media3.test.utils.FakeMediaSource)1 TimelineWindowDefinition (androidx.media3.test.utils.FakeTimeline.TimelineWindowDefinition)1 NoUidTimeline (androidx.media3.test.utils.NoUidTimeline)1 TestExoPlayerBuilder (androidx.media3.test.utils.TestExoPlayerBuilder)1 TestPlayerRunHelper.playUntilStartOfMediaItem (androidx.media3.test.utils.robolectric.TestPlayerRunHelper.playUntilStartOfMediaItem)1