use of com.google.android.exoplayer2.testutil.FakeTimeline in project ExoPlayer by google.
the class DefaultPlaybackSessionManagerTest method timelineUpdate_withContent_doesNotFinishFuturePostrollAd.
@Test
public void timelineUpdate_withContent_doesNotFinishFuturePostrollAd() {
Timeline adTimeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
0, /* isSeekable= */
true, /* isDynamic= */
false, /* durationUs= */
10 * C.MICROS_PER_SECOND, new AdPlaybackState(/* adsId= */
new Object(), /* adGroupTimesUs=... */
C.TIME_END_OF_SOURCE).withAdCount(/* adGroupIndex= */
0, /* adCount= */
1)));
EventTime adEventTime = createEventTime(adTimeline, /* windowIndex= */
0, new MediaPeriodId(adTimeline.getUidOfPeriod(/* periodIndex= */
0), /* adGroupIndex= */
0, /* adIndexInAdGroup= */
0, /* windowSequenceNumber= */
0));
EventTime contentEventTime = createEventTime(adTimeline, /* windowIndex= */
0, new MediaPeriodId(adTimeline.getUidOfPeriod(/* periodIndex= */
0), /* windowSequenceNumber= */
0, /* nextAdGroupIndex= */
0));
sessionManager.updateSessions(contentEventTime);
sessionManager.updateSessions(adEventTime);
sessionManager.updateSessionsWithTimelineChange(contentEventTime);
verify(mockListener, never()).onSessionFinished(any(), anyString(), anyBoolean());
}
use of com.google.android.exoplayer2.testutil.FakeTimeline in project ExoPlayer by google.
the class DefaultPlaybackSessionManagerTest method updateSessions_withMediaPeriodId_ofOtherWindow_createsNewSession.
@Test
public void updateSessions_withMediaPeriodId_ofOtherWindow_createsNewSession() {
Timeline timeline = new FakeTimeline(/* windowCount= */
2);
MediaPeriodId mediaPeriodId1 = new MediaPeriodId(timeline.getUidOfPeriod(/* periodIndex= */
0), /* windowSequenceNumber= */
0);
MediaPeriodId mediaPeriodId2 = new MediaPeriodId(timeline.getUidOfPeriod(/* periodIndex= */
1), /* windowSequenceNumber= */
1);
EventTime eventTime1 = createEventTime(timeline, /* windowIndex= */
0, mediaPeriodId1);
EventTime eventTime2 = createEventTime(timeline, /* windowIndex= */
0, mediaPeriodId2);
sessionManager.updateSessions(eventTime1);
sessionManager.updateSessions(eventTime2);
ArgumentCaptor<String> sessionId1 = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> sessionId2 = ArgumentCaptor.forClass(String.class);
verify(mockListener).onSessionCreated(eq(eventTime1), sessionId1.capture());
verify(mockListener).onSessionCreated(eq(eventTime2), sessionId2.capture());
verify(mockListener).onSessionActive(eventTime1, sessionId1.getValue());
verifyNoMoreInteractions(mockListener);
assertThat(sessionId1).isNotEqualTo(sessionId2);
assertThat(sessionManager.getSessionForMediaPeriodId(timeline, mediaPeriodId1)).isEqualTo(sessionId1.getValue());
assertThat(sessionManager.getSessionForMediaPeriodId(timeline, mediaPeriodId2)).isEqualTo(sessionId2.getValue());
}
use of com.google.android.exoplayer2.testutil.FakeTimeline in project ExoPlayer by google.
the class DefaultPlaybackSessionManagerTest method positionDiscontinuity_fromAdToAd_finishesPastAds_andNotifiesAdPlaybackStated.
@Test
public void positionDiscontinuity_fromAdToAd_finishesPastAds_andNotifiesAdPlaybackStated() {
Timeline adTimeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
0, /* isSeekable= */
true, /* isDynamic= */
false, /* durationUs= */
10 * C.MICROS_PER_SECOND, new AdPlaybackState(/* adsId= */
new Object(), /* adGroupTimesUs=... */
0, 5 * C.MICROS_PER_SECOND).withAdCount(/* adGroupIndex= */
0, /* adCount= */
1).withAdCount(/* adGroupIndex= */
1, /* adCount= */
1)));
EventTime adEventTime1 = createEventTime(adTimeline, /* windowIndex= */
0, new MediaPeriodId(adTimeline.getUidOfPeriod(/* periodIndex= */
0), /* adGroupIndex= */
0, /* adIndexInAdGroup= */
0, /* windowSequenceNumber= */
0));
EventTime adEventTime2 = createEventTime(adTimeline, /* windowIndex= */
0, new MediaPeriodId(adTimeline.getUidOfPeriod(/* periodIndex= */
0), /* adGroupIndex= */
1, /* adIndexInAdGroup= */
0, /* windowSequenceNumber= */
0));
EventTime contentEventTime = createEventTime(adTimeline, /* windowIndex= */
0, new MediaPeriodId(adTimeline.getUidOfPeriod(/* periodIndex= */
0), /* windowSequenceNumber= */
0, /* nextAdGroupIndex= */
1));
sessionManager.updateSessionsWithTimelineChange(contentEventTime);
sessionManager.updateSessions(adEventTime1);
sessionManager.updateSessions(adEventTime2);
String contentSessionId = sessionManager.getSessionForMediaPeriodId(adTimeline, contentEventTime.mediaPeriodId);
String adSessionId1 = sessionManager.getSessionForMediaPeriodId(adTimeline, adEventTime1.mediaPeriodId);
String adSessionId2 = sessionManager.getSessionForMediaPeriodId(adTimeline, adEventTime2.mediaPeriodId);
sessionManager.updateSessionsWithDiscontinuity(adEventTime1, Player.DISCONTINUITY_REASON_AUTO_TRANSITION);
sessionManager.updateSessionsWithDiscontinuity(adEventTime2, Player.DISCONTINUITY_REASON_SEEK);
verify(mockListener).onSessionCreated(eq(contentEventTime), anyString());
verify(mockListener).onSessionActive(eq(contentEventTime), anyString());
verify(mockListener).onSessionCreated(adEventTime1, adSessionId1);
verify(mockListener).onSessionCreated(adEventTime2, adSessionId2);
verify(mockListener).onAdPlaybackStarted(adEventTime1, contentSessionId, adSessionId1);
verify(mockListener).onSessionActive(adEventTime1, adSessionId1);
verify(mockListener).onSessionFinished(adEventTime2, adSessionId1, /* automaticTransitionToNextPlayback= */
false);
verify(mockListener).onAdPlaybackStarted(adEventTime2, contentSessionId, adSessionId2);
verify(mockListener).onSessionActive(adEventTime2, adSessionId2);
verifyNoMoreInteractions(mockListener);
}
use of com.google.android.exoplayer2.testutil.FakeTimeline in project ExoPlayer by google.
the class ExoPlayerTest method seekToCurrentPosition_inEndedState_switchesToBufferingStateAndContinuesPlayback.
@Test
public void seekToCurrentPosition_inEndedState_switchesToBufferingStateAndContinuesPlayback() throws Exception {
MediaSource mediaSource = new FakeMediaSource(new FakeTimeline(/* windowCount = */
1));
AtomicInteger mediaItemIndexAfterFinalEndedState = new AtomicInteger();
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).waitForPlaybackState(Player.STATE_ENDED).addMediaSources(mediaSource).executeRunnable(new PlayerRunnable() {
@Override
public void run(ExoPlayer player) {
player.seekTo(player.getCurrentPosition());
}
}).waitForPlaybackState(Player.STATE_READY).waitForPlaybackState(Player.STATE_ENDED).executeRunnable(new PlayerRunnable() {
@Override
public void run(ExoPlayer player) {
mediaItemIndexAfterFinalEndedState.set(player.getCurrentMediaItemIndex());
}
}).build();
new ExoPlayerTestRunner.Builder(context).setMediaSources(mediaSource).setActionSchedule(actionSchedule).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
assertThat(mediaItemIndexAfterFinalEndedState.get()).isEqualTo(1);
}
use of com.google.android.exoplayer2.testutil.FakeTimeline 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);
}
Aggregations