use of com.google.android.exoplayer2.Player.Listener in project ExoPlayer by google.
the class DefaultMediaClockTest method getPositionWithPlaybackSpeedChange_shouldTriggerCallback.
@Test
public void getPositionWithPlaybackSpeedChange_shouldTriggerCallback() throws ExoPlaybackException {
MediaClockRenderer mediaClockRenderer = new MediaClockRenderer(PlaybackParameters.DEFAULT, /* playbackParametersAreMutable= */
true);
mediaClock.onRendererEnabled(mediaClockRenderer);
// Silently change playback speed of renderer clock.
mediaClockRenderer.playbackParameters = TEST_PLAYBACK_PARAMETERS;
mediaClock.syncAndGetPositionUs(/* isReadingAhead= */
false);
verify(listener).onPlaybackParametersChanged(TEST_PLAYBACK_PARAMETERS);
}
use of com.google.android.exoplayer2.Player.Listener in project ExoPlayer by google.
the class DefaultMediaClockTest method initMediaClockWithFakeClock.
@Before
public void initMediaClockWithFakeClock() {
initMocks(this);
fakeClock = new FakeClock(0);
mediaClock = new DefaultMediaClock(listener, fakeClock);
}
use of com.google.android.exoplayer2.Player.Listener in project ExoPlayer by google.
the class AdsMediaSourceTest method setUp.
@Before
public void setUp() {
// Set up content and ad media sources, passing a null timeline so tests can simulate setting it
// later.
contentMediaSource = new FakeMediaSource(/* timeline= */
null);
prerollAdMediaSource = new FakeMediaSource(/* timeline= */
null);
MediaSource.Factory adMediaSourceFactory = mock(MediaSource.Factory.class);
when(adMediaSourceFactory.createMediaSource(any(MediaItem.class))).thenReturn(prerollAdMediaSource);
// Prepare the AdsMediaSource and capture its ads loader listener.
AdsLoader mockAdsLoader = mock(AdsLoader.class);
AdViewProvider mockAdViewProvider = mock(AdViewProvider.class);
ArgumentCaptor<EventListener> eventListenerArgumentCaptor = ArgumentCaptor.forClass(AdsLoader.EventListener.class);
adsMediaSource = new AdsMediaSource(contentMediaSource, TEST_ADS_DATA_SPEC, TEST_ADS_ID, adMediaSourceFactory, mockAdsLoader, mockAdViewProvider);
adsMediaSource.prepareSource(mockMediaSourceCaller, /* mediaTransferListener= */
null, PlayerId.UNSET);
shadowOf(Looper.getMainLooper()).idle();
verify(mockAdsLoader).start(eq(adsMediaSource), eq(TEST_ADS_DATA_SPEC), eq(TEST_ADS_ID), eq(mockAdViewProvider), eventListenerArgumentCaptor.capture());
// Simulate loading a preroll ad.
AdsLoader.EventListener adsLoaderEventListener = eventListenerArgumentCaptor.getValue();
adsLoaderEventListener.onAdPlaybackState(AD_PLAYBACK_STATE);
shadowOf(Looper.getMainLooper()).idle();
}
use of com.google.android.exoplayer2.Player.Listener in project ExoPlayer by google.
the class ServerSideAdInsertionMediaSourceTest method playbackWithNewlyInsertedAds_playsSuccessfulWithoutRendererResets.
@Test
public void playbackWithNewlyInsertedAds_playsSuccessfulWithoutRendererResets() throws Exception {
Context context = ApplicationProvider.getApplicationContext();
AtomicReference<Object> periodUid = new AtomicReference<>();
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 firstAdPlaybackState = addAdGroupToAdPlaybackState(new AdPlaybackState(/* adsId= */
new Object()), /* 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)), /* adPlaybackStateUpdater= */
contentTimeline -> {
periodUid.set(checkNotNull(contentTimeline.getPeriod(/* periodIndex= */
0, new Timeline.Period(), /* setIds= */
true).uid));
mediaSourceRef.get().setAdPlaybackStates(ImmutableMap.of(periodUid.get(), firstAdPlaybackState));
return true;
}));
AnalyticsListener listener = mock(AnalyticsListener.class);
player.addAnalyticsListener(listener);
player.setMediaSource(mediaSourceRef.get());
player.prepare();
// Add ad at the current playback position during playback.
runUntilPlaybackState(player, Player.STATE_READY);
AdPlaybackState secondAdPlaybackState = addAdGroupToAdPlaybackState(firstAdPlaybackState, /* fromPositionUs= */
0, /* contentResumeOffsetUs= */
0, /* adDurationsUs...= */
500_000);
mediaSourceRef.get().setAdPlaybackStates(ImmutableMap.of(periodUid.get(), secondAdPlaybackState));
runUntilPendingCommandsAreFullyHandled(player);
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: [content][ad0][content][ad1][content]
// 5*2(audio+video) format changes, 4 discontinuities between parts.
verify(listener, times(4)).onPositionDiscontinuity(any(), any(), any(), eq(Player.DISCONTINUITY_REASON_AUTO_TRANSITION));
verify(listener, times(10)).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.Player.Listener in project ExoPlayer by google.
the class ServerSideAdInsertionMediaSourceTest method playbackWithAdditionalAdsInAdGroup_playsSuccessfulWithoutRendererResets.
@Test
public void playbackWithAdditionalAdsInAdGroup_playsSuccessfulWithoutRendererResets() throws Exception {
Context context = ApplicationProvider.getApplicationContext();
AtomicReference<Object> periodUid = new AtomicReference<>();
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 firstAdPlaybackState = addAdGroupToAdPlaybackState(new AdPlaybackState(/* adsId= */
new Object()), /* fromPositionUs= */
0, /* contentResumeOffsetUs= */
0, /* adDurationsUs...= */
500_000);
AtomicReference<ServerSideAdInsertionMediaSource> mediaSourceRef = new AtomicReference<>();
mediaSourceRef.set(new ServerSideAdInsertionMediaSource(new DefaultMediaSourceFactory(context).createMediaSource(MediaItem.fromUri(TEST_ASSET)), /* adPlaybackStateUpdater= */
contentTimeline -> {
if (periodUid.get() == null) {
periodUid.set(checkNotNull(contentTimeline.getPeriod(/* periodIndex= */
0, new Timeline.Period(), /* setIds= */
true).uid));
mediaSourceRef.get().setAdPlaybackStates(ImmutableMap.of(periodUid.get(), firstAdPlaybackState));
}
return true;
}));
AnalyticsListener listener = mock(AnalyticsListener.class);
player.addAnalyticsListener(listener);
player.setMediaSource(mediaSourceRef.get());
player.prepare();
// Wait until playback is ready with first ad and then replace by 3 ads.
runUntilPlaybackState(player, Player.STATE_READY);
AdPlaybackState secondAdPlaybackState = firstAdPlaybackState.withAdCount(/* adGroupIndex= */
0, /* adCount= */
3).withAdDurationsUs(/* adGroupIndex= */
0, /* adDurationsUs...= */
50_000, 250_000, 200_000);
mediaSourceRef.get().setAdPlaybackStates(ImmutableMap.of(periodUid.get(), secondAdPlaybackState));
runUntilPendingCommandsAreFullyHandled(player);
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][ad1][ad2][content]
// 4*2(audio+video) format changes, 3 discontinuities between parts.
verify(listener, times(3)).onPositionDiscontinuity(any(), any(), any(), eq(Player.DISCONTINUITY_REASON_AUTO_TRANSITION));
verify(listener, times(8)).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());
}
Aggregations