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);
}
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);
}
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);
}
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);
}
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);
}
}
Aggregations