use of com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition in project ExoPlayer by google.
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 com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition in project ExoPlayer by google.
the class ExoPlayerTest method seekToNext_liveWindowWithoutNextWindow_seeksToLiveEdge.
@Test
public void seekToNext_liveWindowWithoutNextWindow_seeksToLiveEdge() throws Exception {
ExoPlayer player = new TestExoPlayerBuilder(context).build();
Timeline timeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
0, /* isSeekable= */
true, /* isDynamic= */
true, /* isLive= */
true, /* isPlaceholder= */
false, /* durationUs= */
1_000_000, /* defaultPositionUs= */
500_000, TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US, AdPlaybackState.NONE));
MediaSource mediaSource = new FakeMediaSource(timeline);
player.setMediaSource(mediaSource);
player.prepare();
TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY);
player.seekTo(/* positionMs = */
0);
player.seekToNext();
assertThat(player.getCurrentMediaItemIndex()).isEqualTo(0);
assertThat(player.getCurrentPosition()).isEqualTo(500);
player.release();
}
use of com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition in project ExoPlayer by google.
the class ExoPlayerTest method timelineUpdateDropsPrebufferedPeriods.
@Test
public void timelineUpdateDropsPrebufferedPeriods() throws Exception {
Timeline timeline1 = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
1), new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
2));
final Timeline timeline2 = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
1), new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
3));
final FakeMediaSource mediaSource = new FakeMediaSource(timeline1, ExoPlayerTestRunner.VIDEO_FORMAT);
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().waitForPlaybackState(Player.STATE_READY).playUntilPosition(/* mediaItemIndex= */
0, /* positionMs= */
Util.usToMs(TimelineWindowDefinition.DEFAULT_WINDOW_DURATION_US)).executeRunnable(() -> mediaSource.setNewSourceInfo(timeline2)).waitForTimelineChanged(timeline2, /* expectedReason */
Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE).play().build();
ExoPlayerTestRunner testRunner = new ExoPlayerTestRunner.Builder(context).setMediaSources(mediaSource).setActionSchedule(actionSchedule).build().start().blockUntilEnded(TIMEOUT_MS);
testRunner.assertTimelineChangeReasonsEqual(Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE, Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE);
testRunner.assertPlayedPeriodIndices(0, 1);
// Assert that the second period was re-created from the new timeline.
assertThat(mediaSource.getCreatedMediaPeriods()).hasSize(3);
assertThat(mediaSource.getCreatedMediaPeriods().get(0).periodUid).isEqualTo(timeline1.getUidOfPeriod(/* periodIndex= */
0));
assertThat(mediaSource.getCreatedMediaPeriods().get(1).periodUid).isEqualTo(timeline1.getUidOfPeriod(/* periodIndex= */
1));
assertThat(mediaSource.getCreatedMediaPeriods().get(2).periodUid).isEqualTo(timeline2.getUidOfPeriod(/* periodIndex= */
1));
assertThat(mediaSource.getCreatedMediaPeriods().get(1).windowSequenceNumber).isGreaterThan(mediaSource.getCreatedMediaPeriods().get(0).windowSequenceNumber);
assertThat(mediaSource.getCreatedMediaPeriods().get(2).windowSequenceNumber).isGreaterThan(mediaSource.getCreatedMediaPeriods().get(1).windowSequenceNumber);
}
use of com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition in project ExoPlayer by google.
the class ExoPlayerTest method resetPlaylistWithPreviousPosition.
@Test
public void resetPlaylistWithPreviousPosition() throws Exception {
Object firstWindowId = new Object();
Timeline timeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
firstWindowId));
Timeline firstExpectedMaskingTimeline = new MaskingMediaSource.PlaceholderTimeline(FakeTimeline.FAKE_MEDIA_ITEM.buildUpon().setTag(firstWindowId).build());
Object secondWindowId = new Object();
Timeline secondTimeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
secondWindowId));
Timeline secondExpectedMaskingTimeline = new MaskingMediaSource.PlaceholderTimeline(FakeTimeline.FAKE_MEDIA_ITEM.buildUpon().setTag(secondWindowId).build());
MediaSource secondSource = new FakeMediaSource(secondTimeline);
AtomicLong positionAfterReprepare = new AtomicLong();
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().waitForPlaybackState(Player.STATE_READY).playUntilPosition(/* mediaItemIndex= */
0, /* positionMs= */
2000).setMediaSources(/* mediaItemIndex= */
0, /* positionMs= */
2000, secondSource).waitForTimelineChanged(secondTimeline, /* expectedReason */
Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE).executeRunnable(new PlayerRunnable() {
@Override
public void run(ExoPlayer player) {
positionAfterReprepare.set(player.getCurrentPosition());
}
}).play().build();
ExoPlayerTestRunner testRunner = new ExoPlayerTestRunner.Builder(context).setTimeline(timeline).setActionSchedule(actionSchedule).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
testRunner.assertTimelinesSame(firstExpectedMaskingTimeline, timeline, secondExpectedMaskingTimeline, secondTimeline);
testRunner.assertTimelineChangeReasonsEqual(Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE, Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE);
assertThat(positionAfterReprepare.get()).isAtLeast(2000L);
}
use of com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition in project ExoPlayer by google.
the class ExoPlayerTest method seekPastBufferingMidroll_playsAdAndThenContentFromSeekPosition.
@Test
public void seekPastBufferingMidroll_playsAdAndThenContentFromSeekPosition() throws Exception {
long adGroupWindowTimeMs = 1_000;
long seekPositionMs = 95_000;
long contentDurationMs = 100_000;
AdPlaybackState adPlaybackState = FakeTimeline.createAdPlaybackState(/* adsPerAdGroup= */
1, /* adGroupTimesUs...= */
TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US + Util.msToUs(adGroupWindowTimeMs));
Timeline timeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
0, /* isSeekable= */
true, /* isDynamic= */
false, /* durationUs= */
Util.msToUs(contentDurationMs), adPlaybackState));
AtomicBoolean hasCreatedAdMediaPeriod = new AtomicBoolean();
FakeMediaSource mediaSource = new FakeMediaSource(timeline) {
@Override
public MediaPeriod createPeriod(MediaPeriodId id, Allocator allocator, long startPositionUs) {
if (id.adGroupIndex == 0) {
hasCreatedAdMediaPeriod.set(true);
}
return super.createPeriod(id, allocator, startPositionUs);
}
};
ExoPlayer player = new TestExoPlayerBuilder(context).build();
player.setMediaSource(mediaSource);
// Throw on the playback thread if the player position reaches a value that is just less than
// seek position. This ensures that playback stops and the assertion on the player position
// below fails, even if a long time passes between detecting the discontinuity and asserting.
player.createMessage((messageType, payload) -> {
throw new IllegalStateException();
}).setPosition(seekPositionMs - 1).send();
player.pause();
player.prepare();
// Block until the midroll has started buffering, then seek after the midroll before playing.
runMainLooperUntil(hasCreatedAdMediaPeriod::get);
player.seekTo(seekPositionMs);
player.play();
// When the ad finishes, the player position should be at or after the requested seek position.
runUntilPositionDiscontinuity(player, Player.DISCONTINUITY_REASON_AUTO_TRANSITION);
assertThat(player.getCurrentPosition()).isAtLeast(seekPositionMs);
}
Aggregations