use of com.google.android.exoplayer2.testutil.FakeTimeline in project ExoPlayer by google.
the class DefaultAnalyticsCollectorTest method onPlayerError_thrownDuringRenderAtPeriodTransition_isReportedForNewPeriod.
@Test
public void onPlayerError_thrownDuringRenderAtPeriodTransition_isReportedForNewPeriod() throws Exception {
FakeMediaSource source0 = new FakeMediaSource(new FakeTimeline(), ExoPlayerTestRunner.VIDEO_FORMAT);
FakeMediaSource source1 = new FakeMediaSource(new FakeTimeline(), ExoPlayerTestRunner.AUDIO_FORMAT);
RenderersFactory renderersFactory = (eventHandler, videoListener, audioListener, textOutput, metadataOutput) -> new Renderer[] { new FakeRenderer(C.TRACK_TYPE_VIDEO), new FakeRenderer(C.TRACK_TYPE_AUDIO) {
@Override
public void render(long positionUs, long realtimeUs) throws ExoPlaybackException {
// transition.
throw createRendererException(new IllegalStateException(), ExoPlayerTestRunner.AUDIO_FORMAT, PlaybackException.ERROR_CODE_UNSPECIFIED);
}
} };
TestAnalyticsListener listener = runAnalyticsTest(new ConcatenatingMediaSource(source0, source1), /* actionSchedule= */
null, renderersFactory);
populateEventIds(listener.lastReportedTimeline);
assertThat(listener.getEvents(EVENT_PLAYER_ERROR)).containsExactly(period1);
}
use of com.google.android.exoplayer2.testutil.FakeTimeline in project ExoPlayer by google.
the class DefaultAnalyticsCollectorTest method release_withCallbacksArrivingAfterRelease_onPlayerReleasedForwardedLast.
@Test
public void release_withCallbacksArrivingAfterRelease_onPlayerReleasedForwardedLast() throws Exception {
FakeClock fakeClock = new FakeClock(/* initialTimeMs= */
0, /* isAutoAdvancing= */
true);
ExoPlayer exoPlayer = new TestExoPlayerBuilder(ApplicationProvider.getApplicationContext()).setClock(fakeClock).build();
AnalyticsListener analyticsListener = spy(new AnalyticsListener() {
@Override
public void onVideoDisabled(EventTime eventTime, DecoderCounters decoderCounters) {
// Add delay in callback to test whether event timestamp and release timestamp are
// in the correct order.
fakeClock.advanceTime(1);
}
});
exoPlayer.addAnalyticsListener(analyticsListener);
// Prepare with media to ensure video renderer is enabled.
exoPlayer.setMediaSource(new FakeMediaSource(new FakeTimeline(), ExoPlayerTestRunner.VIDEO_FORMAT));
exoPlayer.prepare();
TestPlayerRunHelper.runUntilPlaybackState(exoPlayer, Player.STATE_READY);
// Release and add delay on releasing thread to verify timestamps of events.
exoPlayer.release();
long releaseTimeMs = fakeClock.currentTimeMillis();
fakeClock.advanceTime(1);
ShadowLooper.idleMainLooper();
// Verify video disable events and release events arrived in order.
ArgumentCaptor<AnalyticsListener.EventTime> videoDisabledEventTime = ArgumentCaptor.forClass(AnalyticsListener.EventTime.class);
ArgumentCaptor<AnalyticsListener.EventTime> releasedEventTime = ArgumentCaptor.forClass(AnalyticsListener.EventTime.class);
InOrder inOrder = inOrder(analyticsListener);
inOrder.verify(analyticsListener).onVideoDisabled(videoDisabledEventTime.capture(), any());
inOrder.verify(analyticsListener).onEvents(same(exoPlayer), argThat(events -> events.contains(EVENT_VIDEO_DISABLED)));
inOrder.verify(analyticsListener).onPlayerReleased(releasedEventTime.capture());
inOrder.verify(analyticsListener).onEvents(same(exoPlayer), argThat(events -> events.contains(EVENT_PLAYER_RELEASED)));
// Verify order of timestamps of these events.
// This verification is needed as a regression test against [internal ref: b/195396384]. The
// root cause of the regression was an onPlayerReleased timestamp that was less than the
// previously reported timestamps for other events triggered as part of the release.
long videoDisableTimeMs = videoDisabledEventTime.getValue().realtimeMs;
assertThat(videoDisableTimeMs).isGreaterThan(releaseTimeMs);
assertThat(releasedEventTime.getValue().realtimeMs).isGreaterThan(videoDisableTimeMs);
}
use of com.google.android.exoplayer2.testutil.FakeTimeline in project ExoPlayer by google.
the class ExoPlayerTest method play_withPreMidAndPostRollAd_callsOnDiscontinuityCorrectly.
@Test
public void play_withPreMidAndPostRollAd_callsOnDiscontinuityCorrectly() throws Exception {
ExoPlayer player = new TestExoPlayerBuilder(context).build();
Player.Listener listener = mock(Player.Listener.class);
player.addListener(listener);
AdPlaybackState adPlaybackState = FakeTimeline.createAdPlaybackState(/* adsPerAdGroup= */
2, /* adGroupTimesUs...= */
0, 7 * C.MICROS_PER_SECOND, C.TIME_END_OF_SOURCE);
TimelineWindowDefinition adTimeline = new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
0, /* isSeekable= */
true, /* isDynamic= */
false, /* isLive= */
false, /* isPlaceholder= */
false, /* durationUs= */
10 * C.MICROS_PER_SECOND, /* defaultPositionUs= */
0, /* windowOffsetInFirstPeriodUs= */
0, adPlaybackState);
player.setMediaSource(new FakeMediaSource(new FakeTimeline(adTimeline)));
player.prepare();
player.play();
TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_ENDED);
ArgumentCaptor<Player.PositionInfo> oldPosition = ArgumentCaptor.forClass(Player.PositionInfo.class);
ArgumentCaptor<Player.PositionInfo> newPosition = ArgumentCaptor.forClass(Player.PositionInfo.class);
verify(listener, never()).onPositionDiscontinuity(any(), any(), not(eq(Player.DISCONTINUITY_REASON_AUTO_TRANSITION)));
verify(listener, times(8)).onPositionDiscontinuity(oldPosition.capture(), newPosition.capture(), eq(Player.DISCONTINUITY_REASON_AUTO_TRANSITION));
// first ad group (pre-roll)
// starts with ad to ad transition
List<Player.PositionInfo> oldPositions = oldPosition.getAllValues();
List<Player.PositionInfo> newPositions = newPosition.getAllValues();
assertThat(oldPositions.get(0).mediaItemIndex).isEqualTo(0);
assertThat(oldPositions.get(0).positionMs).isEqualTo(5000);
assertThat(oldPositions.get(0).contentPositionMs).isEqualTo(0);
assertThat(oldPositions.get(0).adGroupIndex).isEqualTo(0);
assertThat(oldPositions.get(0).adIndexInAdGroup).isEqualTo(0);
assertThat(newPositions.get(0).mediaItemIndex).isEqualTo(0);
assertThat(newPositions.get(0).positionMs).isEqualTo(0);
assertThat(newPositions.get(0).contentPositionMs).isEqualTo(0);
assertThat(newPositions.get(0).adGroupIndex).isEqualTo(0);
assertThat(newPositions.get(0).adIndexInAdGroup).isEqualTo(1);
// ad to content transition
assertThat(oldPositions.get(1).mediaItemIndex).isEqualTo(0);
assertThat(oldPositions.get(1).positionMs).isEqualTo(5000);
assertThat(oldPositions.get(1).contentPositionMs).isEqualTo(0);
assertThat(oldPositions.get(1).adGroupIndex).isEqualTo(0);
assertThat(oldPositions.get(1).adIndexInAdGroup).isEqualTo(1);
assertThat(newPositions.get(1).mediaItemIndex).isEqualTo(0);
assertThat(newPositions.get(1).positionMs).isEqualTo(0);
assertThat(newPositions.get(1).contentPositionMs).isEqualTo(0);
assertThat(newPositions.get(1).adGroupIndex).isEqualTo(-1);
assertThat(newPositions.get(1).adIndexInAdGroup).isEqualTo(-1);
// second add group (mid-roll)
assertThat(oldPositions.get(2).mediaItemIndex).isEqualTo(0);
assertThat(oldPositions.get(2).positionMs).isEqualTo(7000);
assertThat(oldPositions.get(2).contentPositionMs).isEqualTo(7000);
assertThat(oldPositions.get(2).adGroupIndex).isEqualTo(-1);
assertThat(oldPositions.get(2).adIndexInAdGroup).isEqualTo(-1);
assertThat(newPositions.get(2).mediaItemIndex).isEqualTo(0);
assertThat(newPositions.get(2).positionMs).isEqualTo(0);
assertThat(newPositions.get(2).contentPositionMs).isEqualTo(7000);
assertThat(newPositions.get(2).adGroupIndex).isEqualTo(1);
assertThat(newPositions.get(2).adIndexInAdGroup).isEqualTo(0);
// ad to ad transition
assertThat(oldPositions.get(3).mediaItemIndex).isEqualTo(0);
assertThat(oldPositions.get(3).positionMs).isEqualTo(5000);
assertThat(oldPositions.get(3).contentPositionMs).isEqualTo(7000);
assertThat(oldPositions.get(3).adGroupIndex).isEqualTo(1);
assertThat(oldPositions.get(3).adIndexInAdGroup).isEqualTo(0);
assertThat(newPositions.get(3).mediaItemIndex).isEqualTo(0);
assertThat(newPositions.get(3).positionMs).isEqualTo(0);
assertThat(newPositions.get(3).contentPositionMs).isEqualTo(7000);
assertThat(newPositions.get(3).adGroupIndex).isEqualTo(1);
assertThat(newPositions.get(3).adIndexInAdGroup).isEqualTo(1);
// ad to content transition
assertThat(oldPositions.get(4).mediaItemIndex).isEqualTo(0);
assertThat(oldPositions.get(4).positionMs).isEqualTo(5000);
assertThat(oldPositions.get(4).contentPositionMs).isEqualTo(7000);
assertThat(oldPositions.get(4).adGroupIndex).isEqualTo(1);
assertThat(oldPositions.get(4).adIndexInAdGroup).isEqualTo(1);
assertThat(newPositions.get(4).mediaItemIndex).isEqualTo(0);
assertThat(newPositions.get(4).positionMs).isEqualTo(7000);
assertThat(newPositions.get(4).contentPositionMs).isEqualTo(7000);
assertThat(newPositions.get(4).adGroupIndex).isEqualTo(-1);
assertThat(newPositions.get(4).adIndexInAdGroup).isEqualTo(-1);
// third add group (post-roll)
assertThat(oldPositions.get(5).mediaItemIndex).isEqualTo(0);
assertThat(oldPositions.get(5).positionMs).isEqualTo(10000);
assertThat(oldPositions.get(5).contentPositionMs).isEqualTo(10000);
assertThat(oldPositions.get(5).adGroupIndex).isEqualTo(-1);
assertThat(oldPositions.get(5).adIndexInAdGroup).isEqualTo(-1);
assertThat(newPositions.get(5).mediaItemIndex).isEqualTo(0);
assertThat(newPositions.get(5).positionMs).isEqualTo(0);
assertThat(newPositions.get(5).contentPositionMs).isEqualTo(10000);
assertThat(newPositions.get(5).adGroupIndex).isEqualTo(2);
assertThat(newPositions.get(5).adIndexInAdGroup).isEqualTo(0);
// ad to ad transition
assertThat(oldPositions.get(6).mediaItemIndex).isEqualTo(0);
assertThat(oldPositions.get(6).positionMs).isEqualTo(5000);
assertThat(oldPositions.get(6).contentPositionMs).isEqualTo(10000);
assertThat(oldPositions.get(6).adGroupIndex).isEqualTo(2);
assertThat(oldPositions.get(6).adIndexInAdGroup).isEqualTo(0);
assertThat(newPositions.get(6).mediaItemIndex).isEqualTo(0);
assertThat(newPositions.get(6).positionMs).isEqualTo(0);
assertThat(newPositions.get(6).contentPositionMs).isEqualTo(10000);
assertThat(newPositions.get(6).adGroupIndex).isEqualTo(2);
assertThat(newPositions.get(6).adIndexInAdGroup).isEqualTo(1);
// post roll ad to end of content transition
assertThat(oldPositions.get(7).mediaItemIndex).isEqualTo(0);
assertThat(oldPositions.get(7).positionMs).isEqualTo(5000);
assertThat(oldPositions.get(7).contentPositionMs).isEqualTo(10000);
assertThat(oldPositions.get(7).adGroupIndex).isEqualTo(2);
assertThat(oldPositions.get(7).adIndexInAdGroup).isEqualTo(1);
assertThat(newPositions.get(7).mediaItemIndex).isEqualTo(0);
assertThat(newPositions.get(7).positionMs).isEqualTo(9999);
assertThat(newPositions.get(7).contentPositionMs).isEqualTo(9999);
assertThat(newPositions.get(7).adGroupIndex).isEqualTo(-1);
assertThat(newPositions.get(7).adIndexInAdGroup).isEqualTo(-1);
player.release();
}
use of com.google.android.exoplayer2.testutil.FakeTimeline in project ExoPlayer by google.
the class ExoPlayerTest method stopAndSeekAfterStopDoesNotResetTimeline.
@Test
public void stopAndSeekAfterStopDoesNotResetTimeline() throws Exception {
Timeline timeline = new FakeTimeline();
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).waitForPlaybackState(Player.STATE_READY).stop(false).stop(false).waitForPendingPlayerCommands().build();
ExoPlayerTestRunner testRunner = new ExoPlayerTestRunner.Builder(context).setTimeline(timeline).setActionSchedule(actionSchedule).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
testRunner.assertTimelinesSame(placeholderTimeline, timeline);
testRunner.assertTimelineChangeReasonsEqual(Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE);
}
use of com.google.android.exoplayer2.testutil.FakeTimeline in project ExoPlayer by google.
the class ExoPlayerTest method sendMessagesNonLinearPeriodOrder.
@Test
public void sendMessagesNonLinearPeriodOrder() throws Exception {
Timeline fakeTimeline = new FakeTimeline();
MediaSource[] fakeMediaSources = { new FakeMediaSource(fakeTimeline, ExoPlayerTestRunner.VIDEO_FORMAT), new FakeMediaSource(fakeTimeline, ExoPlayerTestRunner.VIDEO_FORMAT), new FakeMediaSource(fakeTimeline, ExoPlayerTestRunner.VIDEO_FORMAT) };
ConcatenatingMediaSource mediaSource = new ConcatenatingMediaSource(false, new FakeShuffleOrder(3), fakeMediaSources);
PositionGrabbingMessageTarget target1 = new PositionGrabbingMessageTarget();
PositionGrabbingMessageTarget target2 = new PositionGrabbingMessageTarget();
PositionGrabbingMessageTarget target3 = new PositionGrabbingMessageTarget();
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().waitForPlaybackState(Player.STATE_READY).sendMessage(target1, /* mediaItemIndex = */
0, /* positionMs= */
50).sendMessage(target2, /* mediaItemIndex = */
1, /* positionMs= */
50).sendMessage(target3, /* mediaItemIndex = */
2, /* positionMs= */
50).setShuffleModeEnabled(true).seek(/* mediaItemIndex= */
2, /* positionMs= */
0).play().build();
new ExoPlayerTestRunner.Builder(context).setMediaSources(mediaSource).setActionSchedule(actionSchedule).build().start().blockUntilEnded(TIMEOUT_MS);
assertThat(target1.mediaItemIndex).isEqualTo(0);
assertThat(target2.mediaItemIndex).isEqualTo(1);
assertThat(target3.mediaItemIndex).isEqualTo(2);
}
Aggregations