use of com.google.android.exoplayer2.analytics.AnalyticsListener in project ExoPlayer by google.
the class ServerSideAdInsertionMediaSourceTest method playbackWithPredefinedAds_playsSuccessfulWithoutRendererResets.
@Test
public void playbackWithPredefinedAds_playsSuccessfulWithoutRendererResets() throws Exception {
Context context = ApplicationProvider.getApplicationContext();
CapturingRenderersFactory renderersFactory = new CapturingRenderersFactory(context);
ExoPlayer player = new ExoPlayer.Builder(context, renderersFactory).setClock(new FakeClock(/* isAutoAdvancing= */
true)).build();
player.setVideoSurface(new Surface(new SurfaceTexture(/* texName= */
1)));
PlaybackOutput playbackOutput = PlaybackOutput.register(player, renderersFactory);
AdPlaybackState adPlaybackState = new AdPlaybackState(/* adsId= */
new Object());
adPlaybackState = addAdGroupToAdPlaybackState(adPlaybackState, /* fromPositionUs= */
0, /* contentResumeOffsetUs= */
0, /* adDurationsUs...= */
200_000);
adPlaybackState = addAdGroupToAdPlaybackState(adPlaybackState, /* fromPositionUs= */
400_000, /* contentResumeOffsetUs= */
1_000_000, /* adDurationsUs...= */
300_000);
AdPlaybackState firstAdPlaybackState = addAdGroupToAdPlaybackState(adPlaybackState, /* fromPositionUs= */
900_000, /* contentResumeOffsetUs= */
0, /* adDurationsUs...= */
100_000);
AtomicReference<ServerSideAdInsertionMediaSource> mediaSourceRef = new AtomicReference<>();
mediaSourceRef.set(new ServerSideAdInsertionMediaSource(new DefaultMediaSourceFactory(context).createMediaSource(MediaItem.fromUri(TEST_ASSET)), contentTimeline -> {
Object periodUid = checkNotNull(contentTimeline.getPeriod(/* periodIndex= */
0, new Timeline.Period(), /* setIds= */
true).uid);
mediaSourceRef.get().setAdPlaybackStates(ImmutableMap.of(periodUid, firstAdPlaybackState));
return true;
}));
AnalyticsListener listener = mock(AnalyticsListener.class);
player.addAnalyticsListener(listener);
player.setMediaSource(mediaSourceRef.get());
player.prepare();
player.play();
runUntilPlaybackState(player, Player.STATE_ENDED);
player.release();
// Assert all samples have been played.
DumpFileAsserts.assertOutput(context, playbackOutput, TEST_ASSET_DUMP);
// Assert playback has been reported with ads: [ad0][content][ad1][content][ad2][content]
// 6*2(audio+video) format changes, 5 discontinuities between parts.
verify(listener, times(5)).onPositionDiscontinuity(any(), any(), any(), eq(Player.DISCONTINUITY_REASON_AUTO_TRANSITION));
verify(listener, times(12)).onDownstreamFormatChanged(any(), any());
// Assert renderers played through without reset (=decoders have been enabled only once).
verify(listener).onVideoEnabled(any(), any());
verify(listener).onAudioEnabled(any(), any());
// Assert playback progression was smooth (=no unexpected delays that cause audio to underrun)
verify(listener, never()).onAudioUnderrun(any(), anyInt(), anyLong(), anyLong());
}
use of com.google.android.exoplayer2.analytics.AnalyticsListener in project ExoPlayer by google.
the class ExoPlayerTest method playbackErrorAndReprepareWithPositionResetKeepsWindowSequenceNumber.
@Test
public void playbackErrorAndReprepareWithPositionResetKeepsWindowSequenceNumber() throws Exception {
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().waitForPlaybackState(Player.STATE_READY).throwPlaybackException(ExoPlaybackException.createForSource(new IOException(), PlaybackException.ERROR_CODE_IO_UNSPECIFIED)).waitForPlaybackState(Player.STATE_IDLE).seek(0, C.TIME_UNSET).prepare().waitForPlaybackState(Player.STATE_READY).play().build();
HashSet<Long> reportedWindowSequenceNumbers = new HashSet<>();
AnalyticsListener listener = new AnalyticsListener() {
@Override
public void onPlaybackStateChanged(EventTime eventTime, @Player.State int state) {
if (eventTime.mediaPeriodId != null) {
reportedWindowSequenceNumbers.add(eventTime.mediaPeriodId.windowSequenceNumber);
}
}
@Override
public void onPlayWhenReadyChanged(EventTime eventTime, boolean playWhenReady, @Player.PlayWhenReadyChangeReason int reason) {
if (eventTime.mediaPeriodId != null) {
reportedWindowSequenceNumbers.add(eventTime.mediaPeriodId.windowSequenceNumber);
}
}
};
ExoPlayerTestRunner testRunner = new ExoPlayerTestRunner.Builder(context).setActionSchedule(actionSchedule).setAnalyticsListener(listener).build();
try {
testRunner.start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
fail();
} catch (ExoPlaybackException e) {
// Expected exception.
}
assertThat(reportedWindowSequenceNumbers).hasSize(1);
}
use of com.google.android.exoplayer2.analytics.AnalyticsListener in project HybridMediaPlayer by mkaflowski.
the class ExoMediaPlayer method prepare.
@Override
public void prepare() {
exoPlayer.addAnalyticsListener(new AnalyticsListener() {
@Override
public void onAudioSessionIdChanged(EventTime eventTime, int audioSessionId) {
setEqualizer();
if (onAudioSessionIdSetListener != null)
onAudioSessionIdSetListener.onAudioSessionIdset(audioSessionId);
}
});
isPreparing = true;
exoPlayer.prepare(exoMediaSource);
shouldBeWindow = initialWindowNum;
currentWindow = initialWindowNum;
if (initialWindowNum != 0)
exoPlayer.seekTo(initialWindowNum, 0);
if (!isCasting)
init();
if (castPlayer != null && isCasting()) {
castPlayer.loadItems(mediaItems, initialWindowNum, 0, Player.REPEAT_MODE_OFF);
// castPlayer.setPlayWhenReady(true);
}
if (onTrackChangedListener != null)
onTrackChangedListener.onTrackChanged(false);
}
Aggregations