use of com.google.android.exoplayer2.source.MediaPeriod.Callback 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.source.MediaPeriod.Callback in project ExoPlayer by google.
the class PlaybackStatsListenerTest method events_duringInitialIdleState_dontCreateNewPlaybackStats.
@Test
public void events_duringInitialIdleState_dontCreateNewPlaybackStats() throws Exception {
PlaybackStatsListener playbackStatsListener = new PlaybackStatsListener(/* keepHistory= */
true, /* callback= */
null);
player.addAnalyticsListener(playbackStatsListener);
player.seekTo(/* positionMs= */
1234);
runUntilPendingCommandsAreFullyHandled(player);
player.setPlaybackParameters(new PlaybackParameters(/* speed= */
2f));
runUntilPendingCommandsAreFullyHandled(player);
player.play();
runUntilPendingCommandsAreFullyHandled(player);
assertThat(playbackStatsListener.getPlaybackStats()).isNull();
}
use of com.google.android.exoplayer2.source.MediaPeriod.Callback in project ExoPlayer by google.
the class PlaybackStatsListenerTest method finishedSession_callsCallback.
@Test
public void finishedSession_callsCallback() throws Exception {
PlaybackStatsListener.Callback callback = mock(PlaybackStatsListener.Callback.class);
PlaybackStatsListener playbackStatsListener = new PlaybackStatsListener(/* keepHistory= */
true, callback);
player.addAnalyticsListener(playbackStatsListener);
// Create session with some events and finish it by removing it from the playlist.
player.setMediaSource(new FakeMediaSource(new FakeTimeline(/* windowCount= */
1)));
player.prepare();
runUntilPendingCommandsAreFullyHandled(player);
verify(callback, never()).onPlaybackStatsReady(any(), any());
player.clearMediaItems();
runUntilPendingCommandsAreFullyHandled(player);
verify(callback).onPlaybackStatsReady(any(), any());
}
use of com.google.android.exoplayer2.source.MediaPeriod.Callback in project ExoPlayer by google.
the class FakeClockTest method createHandler_sendEmptyMessage_triggersMessageAtCorrectTime.
@Test
public void createHandler_sendEmptyMessage_triggersMessageAtCorrectTime() {
HandlerThread handlerThread = new HandlerThread("FakeClockTest");
handlerThread.start();
FakeClock fakeClock = new FakeClock(/* initialTimeMs= */
0);
TestCallback callback = new TestCallback();
HandlerWrapper handler = fakeClock.createHandler(handlerThread.getLooper(), callback);
handler.sendEmptyMessage(/* what= */
1);
handler.sendEmptyMessageAtTime(/* what= */
2, /* uptimeMs= */
fakeClock.uptimeMillis() + 60);
handler.sendEmptyMessageDelayed(/* what= */
3, /* delayMs= */
50);
handler.sendEmptyMessage(/* what= */
4);
ShadowLooper.idleMainLooper();
shadowOf(handler.getLooper()).idle();
assertThat(callback.messages).containsExactly(new MessageData(/* what= */
1, /* arg1= */
0, /* arg2= */
0, /* obj=*/
null), new MessageData(/* what= */
4, /* arg1= */
0, /* arg2= */
0, /* obj=*/
null)).inOrder();
fakeClock.advanceTime(50);
shadowOf(handler.getLooper()).idle();
assertThat(callback.messages).hasSize(3);
assertThat(Iterables.getLast(callback.messages)).isEqualTo(new MessageData(/* what= */
3, /* arg1= */
0, /* arg2= */
0, /* obj=*/
null));
fakeClock.advanceTime(50);
shadowOf(handler.getLooper()).idle();
assertThat(callback.messages).hasSize(4);
assertThat(Iterables.getLast(callback.messages)).isEqualTo(new MessageData(/* what= */
2, /* arg1= */
0, /* arg2= */
0, /* obj=*/
null));
}
use of com.google.android.exoplayer2.source.MediaPeriod.Callback in project ExoPlayer by google.
the class FakeClockTest method createHandler_removeMessages_removesMessages.
@Test
public void createHandler_removeMessages_removesMessages() {
HandlerThread handlerThread = new HandlerThread("FakeClockTest");
handlerThread.start();
FakeClock fakeClock = new FakeClock(/* initialTimeMs= */
0);
TestCallback callback = new TestCallback();
HandlerWrapper handler = fakeClock.createHandler(handlerThread.getLooper(), callback);
TestCallback otherCallback = new TestCallback();
HandlerWrapper otherHandler = fakeClock.createHandler(handlerThread.getLooper(), otherCallback);
TestRunnable testRunnable1 = new TestRunnable();
TestRunnable testRunnable2 = new TestRunnable();
Object messageToken = new Object();
handler.obtainMessage(/* what= */
1, /* obj= */
messageToken).sendToTarget();
handler.sendEmptyMessageDelayed(/* what= */
2, /* delayMs= */
50);
handler.post(testRunnable1);
handler.postDelayed(testRunnable2, /* delayMs= */
25);
handler.sendEmptyMessage(/* what= */
3);
otherHandler.sendEmptyMessage(/* what= */
2);
handler.removeMessages(/* what= */
2);
handler.removeCallbacksAndMessages(messageToken);
fakeClock.advanceTime(50);
ShadowLooper.idleMainLooper();
shadowOf(handlerThread.getLooper()).idle();
assertThat(callback.messages).containsExactly(new MessageData(/* what= */
3, /* arg1= */
0, /* arg2= */
0, /* obj=*/
null));
assertThat(testRunnable1.hasRun).isTrue();
assertThat(testRunnable2.hasRun).isTrue();
// Assert that message with same "what" on other handler wasn't removed.
assertThat(otherCallback.messages).containsExactly(new MessageData(/* what= */
2, /* arg1= */
0, /* arg2= */
0, /* obj=*/
null));
}
Aggregations