use of androidx.media3.exoplayer.source.SinglePeriodTimeline in project media by androidx.
the class ClippingMediaSourceTest method clippingFromDefaultPosition.
@Test
public void clippingFromDefaultPosition() throws IOException {
Timeline timeline = new SinglePeriodTimeline(/* periodDurationUs= */
3 * 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 clippedTimeline = getClippedTimeline(timeline, /* durationUs= */
TEST_CLIP_AMOUNT_US);
assertThat(clippedTimeline.getWindow(0, window).getDurationUs()).isEqualTo(TEST_CLIP_AMOUNT_US);
assertThat(clippedTimeline.getWindow(0, window).getDefaultPositionUs()).isEqualTo(0);
assertThat(clippedTimeline.getWindow(0, window).getPositionInFirstPeriodUs()).isEqualTo(TEST_PERIOD_DURATION_US + TEST_CLIP_AMOUNT_US);
assertThat(clippedTimeline.getPeriod(0, period).getDurationUs()).isEqualTo(TEST_PERIOD_DURATION_US + 2 * TEST_CLIP_AMOUNT_US);
}
use of androidx.media3.exoplayer.source.SinglePeriodTimeline in project media by androidx.
the class ClippingMediaSourceTest method disallowDynamicUpdatesWithNonOverlappingLiveWindow.
@Test
public void disallowDynamicUpdatesWithNonOverlappingLiveWindow() 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= */
false, /* 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(0);
assertThat(clippedTimelines[1].getWindow(0, window).getDefaultPositionUs()).isEqualTo(0);
assertThat(clippedTimelines[1].getWindow(0, window).isDynamic).isFalse();
assertThat(clippedTimelines[1].getWindow(0, window).getPositionInFirstPeriodUs()).isEqualTo(3 * TEST_PERIOD_DURATION_US);
assertThat(clippedTimelines[1].getPeriod(0, period).getDurationUs()).isEqualTo(3 * TEST_PERIOD_DURATION_US);
}
use of androidx.media3.exoplayer.source.SinglePeriodTimeline in project media by androidx.
the class ClippingMediaSourceTest method disallowDynamicUpdatesWithOverlappingLiveWindow.
@Test
public void disallowDynamicUpdatesWithOverlappingLiveWindow() 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= */
3 * TEST_PERIOD_DURATION_US, /* windowDurationUs= */
TEST_PERIOD_DURATION_US, /* windowPositionInPeriodUs= */
2 * 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= */
false, /* 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_CLIP_AMOUNT_US);
assertThat(clippedTimelines[1].getWindow(0, window).getDefaultPositionUs()).isEqualTo(TEST_CLIP_AMOUNT_US);
assertThat(clippedTimelines[1].getWindow(0, window).isDynamic).isFalse();
assertThat(clippedTimelines[1].getWindow(0, window).getPositionInFirstPeriodUs()).isEqualTo(2 * TEST_PERIOD_DURATION_US);
assertThat(clippedTimelines[1].getPeriod(0, period).getDurationUs()).isEqualTo(2 * TEST_PERIOD_DURATION_US + TEST_CLIP_AMOUNT_US);
}
use of androidx.media3.exoplayer.source.SinglePeriodTimeline in project media by androidx.
the class ClippingMediaSourceTest method allowDynamicUpdatesWithOverlappingLiveWindow.
@Test
public void allowDynamicUpdatesWithOverlappingLiveWindow() 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= */
3 * TEST_PERIOD_DURATION_US, /* windowDurationUs= */
TEST_PERIOD_DURATION_US, /* windowPositionInPeriodUs= */
2 * 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(2 * TEST_PERIOD_DURATION_US + TEST_CLIP_AMOUNT_US);
assertThat(clippedTimelines[1].getPeriod(0, period).getDurationUs()).isEqualTo(3 * TEST_PERIOD_DURATION_US);
}
use of androidx.media3.exoplayer.source.SinglePeriodTimeline in project media by androidx.
the class SinglePeriodTimelineTest method getWindow_setsMediaItemAndTag.
// Tests backward compatibility.
@SuppressWarnings("deprecation")
@Test
public void getWindow_setsMediaItemAndTag() {
MediaItem mediaItem = new MediaItem.Builder().setUri(Uri.EMPTY).setTag(new Object()).build();
SinglePeriodTimeline timeline = new SinglePeriodTimeline(/* durationUs= */
C.TIME_UNSET, /* isSeekable= */
false, /* isDynamic= */
false, /* isLive= */
false, /* manifest= */
null, mediaItem);
Window window = timeline.getWindow(/* windowIndex= */
0, this.window);
assertThat(window.mediaItem).isEqualTo(mediaItem);
assertThat(window.tag).isEqualTo(mediaItem.localConfiguration.tag);
}
Aggregations