use of androidx.media3.common.Timeline.Window in project media by androidx.
the class ProgressiveMediaSource method notifySourceInfoRefreshed.
// Internal methods.
private void notifySourceInfoRefreshed() {
// TODO: Split up isDynamic into multiple fields to indicate which values may change. Then
// indicate that the duration may change until it's known. See [internal: b/69703223].
Timeline timeline = new SinglePeriodTimeline(timelineDurationUs, timelineIsSeekable, /* isDynamic= */
false, /* useLiveConfiguration= */
timelineIsLive, /* manifest= */
null, mediaItem);
if (timelineIsPlaceholder) {
// TODO: Actually prepare the extractors during preparation so that we don't need a
// placeholder. See https://github.com/google/ExoPlayer/issues/4727.
timeline = new ForwardingTimeline(timeline) {
@Override
public Window getWindow(int windowIndex, Window window, long defaultPositionProjectionUs) {
super.getWindow(windowIndex, window, defaultPositionProjectionUs);
window.isPlaceholder = true;
return window;
}
@Override
public Period getPeriod(int periodIndex, Period period, boolean setIds) {
super.getPeriod(periodIndex, period, setIds);
period.isPlaceholder = true;
return period;
}
};
}
refreshSourceInfo(timeline);
}
use of androidx.media3.common.Timeline.Window in project media by androidx.
the class ExoPlayerTest method targetLiveOffsetInMedia_afterSeekToSpecificPositionInOtherStream_adjustsLiveOffsetToSeekPosition.
@Test
public void targetLiveOffsetInMedia_afterSeekToSpecificPositionInOtherStream_adjustsLiveOffsetToSeekPosition() throws Exception {
long windowStartUnixTimeMs = 987_654_321_000L;
long nowUnixTimeMs = windowStartUnixTimeMs + 20_000;
ExoPlayer player = new TestExoPlayerBuilder(context).setClock(new FakeClock(/* initialTimeMs= */
nowUnixTimeMs, /* isAutoAdvancing= */
true)).build();
Timeline liveTimeline1 = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
0, /* isSeekable= */
true, /* isDynamic= */
true, /* isLive= */
true, /* isPlaceholder= */
false, /* durationUs= */
1000 * C.MICROS_PER_SECOND, /* defaultPositionUs= */
8 * C.MICROS_PER_SECOND, /* windowOffsetInFirstPeriodUs= */
Util.msToUs(windowStartUnixTimeMs), ImmutableList.of(AdPlaybackState.NONE), new MediaItem.Builder().setUri(Uri.EMPTY).setLiveConfiguration(new MediaItem.LiveConfiguration.Builder().setTargetOffsetMs(9_000).build()).build()));
Timeline liveTimeline2 = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
0, /* isSeekable= */
true, /* isDynamic= */
true, /* isLive= */
true, /* isPlaceholder= */
false, /* durationUs= */
1000 * C.MICROS_PER_SECOND, /* defaultPositionUs= */
8 * C.MICROS_PER_SECOND, /* windowOffsetInFirstPeriodUs= */
Util.msToUs(windowStartUnixTimeMs), ImmutableList.of(AdPlaybackState.NONE), new MediaItem.Builder().setUri(Uri.EMPTY).setLiveConfiguration(new MediaItem.LiveConfiguration.Builder().setTargetOffsetMs(4_000).build()).build()));
player.pause();
player.addMediaSource(new FakeMediaSource(liveTimeline1));
player.addMediaSource(new FakeMediaSource(liveTimeline2));
// Ensure we override the target live offset to a seek position in the first live stream.
player.seekTo(10_000);
player.prepare();
TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY);
// Seek to specific position in second stream (at 2 seconds live offset).
player.seekTo(/* mediaItemIndex= */
1, /* positionMs= */
18_000);
// Play until close to the end of the available live window.
TestPlayerRunHelper.playUntilPosition(player, /* mediaItemIndex= */
1, /* positionMs= */
999_000);
long liveOffsetAtEnd = player.getCurrentLiveOffset();
player.release();
// Assert that player adjusted live offset to the seek.
assertThat(liveOffsetAtEnd).isIn(Range.closed(1_900L, 2_100L));
}
use of androidx.media3.common.Timeline.Window in project media by androidx.
the class ExoPlayerTest method invalidSeekFallsBackToSubsequentPeriodOfTheRemovedPeriod.
@Test
public void invalidSeekFallsBackToSubsequentPeriodOfTheRemovedPeriod() throws Exception {
Timeline timeline = new FakeTimeline();
CountDownLatch sourceReleasedCountDownLatch = new CountDownLatch(/* count= */
1);
MediaSource mediaSourceToRemove = new FakeMediaSource(timeline) {
@Override
protected void releaseSourceInternal() {
super.releaseSourceInternal();
sourceReleasedCountDownLatch.countDown();
}
};
ConcatenatingMediaSource mediaSource = new ConcatenatingMediaSource(mediaSourceToRemove, new FakeMediaSource(timeline));
final int[] windowCount = { C.INDEX_UNSET };
final long[] position = { C.TIME_UNSET };
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().waitForPlaybackState(Player.STATE_READY).executeRunnable(new PlayerRunnable() {
@Override
public void run(ExoPlayer player) {
mediaSource.removeMediaSource(/* index= */
0);
try {
// Wait until the source to be removed is released on the playback thread. So
// the timeline in EPII has one window only, but the update here in EPI is
// stuck until we finished our executable here. So when seeking below, we will
// seek in the timeline which still has two windows in EPI, but when the seek
// arrives in EPII the actual timeline has one window only. Hence it tries to
// find the subsequent period of the removed period and finds it.
player.getClock().onThreadBlocked();
sourceReleasedCountDownLatch.await();
} catch (InterruptedException e) {
throw new IllegalStateException(e);
}
player.seekTo(/* mediaItemIndex= */
0, /* positionMs= */
1000L);
}
}).waitForPendingPlayerCommands().executeRunnable(new PlayerRunnable() {
@Override
public void run(ExoPlayer player) {
windowCount[0] = player.getCurrentTimeline().getWindowCount();
position[0] = player.getCurrentPosition();
}
}).play().build();
new ExoPlayerTestRunner.Builder(context).setMediaSources(mediaSource).setActionSchedule(actionSchedule).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
// Expect the first window to be the current.
assertThat(windowCount[0]).isEqualTo(1);
// Expect the position to be in the default position.
assertThat(position[0]).isEqualTo(0L);
}
use of androidx.media3.common.Timeline.Window in project media by androidx.
the class ExoPlayerTest method adGroupWithLoadError_withFurtherAdGroup_isSkipped.
@Test
public void adGroupWithLoadError_withFurtherAdGroup_isSkipped() throws Exception {
AdPlaybackState initialAdPlaybackState = FakeTimeline.createAdPlaybackState(/* adsPerAdGroup= */
1, /* adGroupTimesUs...= */
TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US + 5 * C.MICROS_PER_SECOND, TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US + 8 * C.MICROS_PER_SECOND);
Timeline fakeTimeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
0, /* isSeekable= */
true, /* isDynamic= */
false, /* isLive= */
false, /* isPlaceholder= */
false, /* durationUs= */
10 * C.MICROS_PER_SECOND, /* defaultPositionUs= */
0, TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US, initialAdPlaybackState));
AdPlaybackState errorAdPlaybackState = initialAdPlaybackState.withAdLoadError(/* adGroupIndex= */
0, /* adIndexInAdGroup= */
0);
final Timeline adErrorTimeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
0, /* isSeekable= */
true, /* isDynamic= */
false, /* isLive= */
false, /* isPlaceholder= */
false, /* durationUs= */
10 * C.MICROS_PER_SECOND, /* defaultPositionUs= */
0, TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US, errorAdPlaybackState));
final FakeMediaSource fakeMediaSource = new FakeMediaSource(fakeTimeline, ExoPlayerTestRunner.VIDEO_FORMAT);
ExoPlayer player = new TestExoPlayerBuilder(context).build();
Player.Listener mockListener = mock(Player.Listener.class);
player.addListener(mockListener);
player.setMediaSource(fakeMediaSource);
player.prepare();
runUntilPlaybackState(player, Player.STATE_READY);
fakeMediaSource.setNewSourceInfo(adErrorTimeline);
player.play();
runUntilPlaybackState(player, Player.STATE_ENDED);
Timeline.Window window = player.getCurrentTimeline().getWindow(/* windowIndex= */
0, new Timeline.Window());
Timeline.Period period = player.getCurrentTimeline().getPeriod(/* periodIndex= */
0, new Timeline.Period(), /* setIds= */
true);
player.release();
// There content to content discontinuity after the failed ad is suppressed.
PositionInfo positionInfoContentAtSuccessfulAd = new PositionInfo(window.uid, /* mediaItemIndex= */
0, window.mediaItem, period.uid, /* periodIndex= */
0, /* positionMs= */
8_000, /* contentPositionMs= */
8_000, /* adGroupIndex= */
C.INDEX_UNSET, /* adIndexInAdGroup= */
C.INDEX_UNSET);
PositionInfo positionInfoSuccessfulAdStart = new PositionInfo(window.uid, /* mediaItemIndex= */
0, window.mediaItem, period.uid, /* periodIndex= */
0, /* positionMs= */
0, /* contentPositionMs= */
8_000, /* adGroupIndex= */
1, /* adIndexInAdGroup= */
0);
PositionInfo positionInfoSuccessfulAdEnd = new PositionInfo(window.uid, /* mediaItemIndex= */
0, window.mediaItem, period.uid, /* periodIndex= */
0, /* positionMs= */
Util.usToMs(period.getAdDurationUs(/* adGroupIndex= */
1, /* adIndexInAdGroup= */
0)), /* contentPositionMs= */
8_000, /* adGroupIndex= */
1, /* adIndexInAdGroup= */
0);
verify(mockListener).onPositionDiscontinuity(positionInfoContentAtSuccessfulAd, positionInfoSuccessfulAdStart, Player.DISCONTINUITY_REASON_AUTO_TRANSITION);
verify(mockListener).onPositionDiscontinuity(positionInfoSuccessfulAdEnd, positionInfoContentAtSuccessfulAd, Player.DISCONTINUITY_REASON_AUTO_TRANSITION);
}
use of androidx.media3.common.Timeline.Window in project media by androidx.
the class ExoPlayerTest method targetLiveOffsetInMedia_adjustsLiveOffsetToTargetOffset.
@Test
public void targetLiveOffsetInMedia_adjustsLiveOffsetToTargetOffset() throws Exception {
long windowStartUnixTimeMs = 987_654_321_000L;
long nowUnixTimeMs = windowStartUnixTimeMs + 20_000;
ExoPlayer player = new TestExoPlayerBuilder(context).setClock(new FakeClock(/* initialTimeMs= */
nowUnixTimeMs, /* isAutoAdvancing= */
true)).build();
Timeline timeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
0, /* isSeekable= */
true, /* isDynamic= */
true, /* isLive= */
true, /* isPlaceholder= */
false, /* durationUs= */
1000 * C.MICROS_PER_SECOND, /* defaultPositionUs= */
8 * C.MICROS_PER_SECOND, /* windowOffsetInFirstPeriodUs= */
Util.msToUs(windowStartUnixTimeMs), ImmutableList.of(AdPlaybackState.NONE), new MediaItem.Builder().setUri(Uri.EMPTY).setLiveConfiguration(new MediaItem.LiveConfiguration.Builder().setTargetOffsetMs(9_000).build()).build()));
Player.Listener mockListener = mock(Player.Listener.class);
player.addListener(mockListener);
player.pause();
player.setMediaSource(new FakeMediaSource(timeline));
player.prepare();
TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY);
long liveOffsetAtStart = player.getCurrentLiveOffset();
// Verify test setup (now = 20 seconds in live window, default start position = 8 seconds).
assertThat(liveOffsetAtStart).isIn(Range.closed(11_900L, 12_100L));
// Play until close to the end of the available live window.
TestPlayerRunHelper.playUntilPosition(player, /* mediaItemIndex= */
0, /* positionMs= */
999_000);
long liveOffsetAtEnd = player.getCurrentLiveOffset();
player.release();
// Assert that player adjusted live offset to the media value.
assertThat(liveOffsetAtEnd).isIn(Range.closed(8_900L, 9_100L));
// Assert that none of these playback speed changes were reported.
verify(mockListener, never()).onPlaybackParametersChanged(any());
}
Aggregations