use of com.google.android.exoplayer2.testutil.FakeTimeline in project ExoPlayer by google.
the class ExoPlayerTest method adGroupWithLoadError_noFurtherAdGroup_isSkipped.
@Test
public void adGroupWithLoadError_noFurtherAdGroup_isSkipped() throws Exception {
AdPlaybackState initialAdPlaybackState = FakeTimeline.createAdPlaybackState(/* adsPerAdGroup= */
1, /* adGroupTimesUs...= */
TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US + 5 * 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();
// Content to content transition is ignored.
verify(mockListener, never()).onPositionDiscontinuity(any(), any(), anyInt());
}
use of com.google.android.exoplayer2.testutil.FakeTimeline in project ExoPlayer by google.
the class ExoPlayerTest method removeMediaItem.
@Test
public void removeMediaItem() throws Exception {
TimelineWindowDefinition firstWindowDefinition = new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
1, /* isSeekable= */
true, /* isDynamic= */
false, /* durationUs= */
Util.msToUs(10000));
TimelineWindowDefinition secondWindowDefinition = new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
2, /* isSeekable= */
true, /* isDynamic= */
false, /* durationUs= */
Util.msToUs(10000));
TimelineWindowDefinition thirdWindowDefinition = new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
3, /* isSeekable= */
true, /* isDynamic= */
false, /* durationUs= */
Util.msToUs(10000));
Timeline timeline1 = new FakeTimeline(firstWindowDefinition);
Timeline timeline2 = new FakeTimeline(secondWindowDefinition);
Timeline timeline3 = new FakeTimeline(thirdWindowDefinition);
MediaSource mediaSource1 = new FakeMediaSource(timeline1);
MediaSource mediaSource2 = new FakeMediaSource(timeline2);
MediaSource mediaSource3 = new FakeMediaSource(timeline3);
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).waitForPlaybackState(Player.STATE_READY).removeMediaItem(/* index= */
0).build();
ExoPlayerTestRunner exoPlayerTestRunner = new ExoPlayerTestRunner.Builder(context).setMediaSources(mediaSource1, mediaSource2, mediaSource3).setActionSchedule(actionSchedule).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
Timeline expectedPlaceholderTimeline = new FakeTimeline(TimelineWindowDefinition.createPlaceholder(/* tag= */
1), TimelineWindowDefinition.createPlaceholder(/* tag= */
2), TimelineWindowDefinition.createPlaceholder(/* tag= */
3));
Timeline expectedRealTimeline = new FakeTimeline(firstWindowDefinition, secondWindowDefinition, thirdWindowDefinition);
Timeline expectedRealTimelineAfterRemove = new FakeTimeline(secondWindowDefinition, thirdWindowDefinition);
exoPlayerTestRunner.assertTimelineChangeReasonsEqual(Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE, Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED);
exoPlayerTestRunner.assertTimelinesSame(expectedPlaceholderTimeline, expectedRealTimeline, expectedRealTimelineAfterRemove);
}
use of com.google.android.exoplayer2.testutil.FakeTimeline in project ExoPlayer by google.
the class ExoPlayerTest method release_triggersAllPendingEventsInAnalyticsListeners.
@Test
public void release_triggersAllPendingEventsInAnalyticsListeners() throws Exception {
ExoPlayer player = new TestExoPlayerBuilder(ApplicationProvider.getApplicationContext()).setRenderersFactory((handler, videoListener, audioListener, textOutput, metadataOutput) -> new Renderer[] { new FakeVideoRenderer(handler, videoListener) }).build();
AnalyticsListener listener = mock(AnalyticsListener.class);
player.addAnalyticsListener(listener);
// Do something that requires clean-up callbacks like decoder disabling.
player.setMediaSource(new FakeMediaSource(new FakeTimeline(), ExoPlayerTestRunner.VIDEO_FORMAT));
player.prepare();
player.play();
runUntilPlaybackState(player, Player.STATE_READY);
player.release();
ShadowLooper.runMainLooperToNextTask();
verify(listener).onVideoDisabled(any(), any());
verify(listener).onPlayerReleased(any());
}
use of com.google.android.exoplayer2.testutil.FakeTimeline in project ExoPlayer by google.
the class DefaultPlaybackSessionManagerTest method updateSessions_ofSameWindow_withAd_afterWithoutMediaPeriodId_createsNewSession.
@Test
public void updateSessions_ofSameWindow_withAd_afterWithoutMediaPeriodId_createsNewSession() {
Timeline timeline = new FakeTimeline();
MediaPeriodId mediaPeriodId = new MediaPeriodId(timeline.getUidOfPeriod(/* periodIndex= */
0), /* adGroupIndex= */
0, /* adIndexInAdGroup= */
0, /* windowSequenceNumber= */
0);
EventTime eventTime1 = createEventTime(timeline, /* windowIndex= */
0, /* mediaPeriodId= */
null);
EventTime eventTime2 = createEventTime(timeline, /* windowIndex= */
0, mediaPeriodId);
sessionManager.updateSessions(eventTime1);
sessionManager.updateSessions(eventTime2);
ArgumentCaptor<String> contentSessionId = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> adSessionId = ArgumentCaptor.forClass(String.class);
verify(mockListener).onSessionCreated(eq(eventTime1), contentSessionId.capture());
verify(mockListener).onSessionCreated(eq(eventTime2), adSessionId.capture());
verify(mockListener).onSessionActive(eventTime1, contentSessionId.getValue());
verifyNoMoreInteractions(mockListener);
assertThat(contentSessionId).isNotEqualTo(adSessionId);
assertThat(sessionManager.getSessionForMediaPeriodId(timeline, mediaPeriodId)).isEqualTo(adSessionId.getValue());
}
use of com.google.android.exoplayer2.testutil.FakeTimeline in project ExoPlayer by google.
the class DefaultPlaybackSessionManagerTest method updateSessions_ofOtherWindow_createsNewSession.
@Test
public void updateSessions_ofOtherWindow_createsNewSession() {
Timeline timeline = new FakeTimeline(/* windowCount= */
2);
EventTime eventTime1 = createEventTime(timeline, /* windowIndex= */
0, /* mediaPeriodId= */
null);
EventTime eventTime2 = createEventTime(timeline, /* windowIndex= */
1, /* mediaPeriodId= */
null);
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);
}
Aggregations