use of androidx.test.filters.LargeTest in project ExoPlayer by google.
the class SessionPlayerConnectorTest method setMediaItem_withAudioResource_notifiesOnPlaybackCompleted.
@Test
@LargeTest
public void setMediaItem_withAudioResource_notifiesOnPlaybackCompleted() throws Exception {
TestUtils.loadResource(R.raw.audio, sessionPlayerConnector);
CountDownLatch onPlaybackCompletedLatch = new CountDownLatch(1);
sessionPlayerConnector.registerPlayerCallback(executor, new SessionPlayer.PlayerCallback() {
@Override
public void onPlaybackCompleted(SessionPlayer player) {
onPlaybackCompletedLatch.countDown();
}
});
sessionPlayerConnector.prepare();
sessionPlayerConnector.play();
// waiting to complete
assertThat(onPlaybackCompletedLatch.await(PLAYBACK_COMPLETED_WAIT_TIME_MS, MILLISECONDS)).isTrue();
assertThat(sessionPlayerConnector.getPlayerState()).isEqualTo(SessionPlayer.PLAYER_STATE_PAUSED);
}
use of androidx.test.filters.LargeTest in project ExoPlayer by google.
the class SessionPlayerConnectorTest method prepare_notifiesBufferingCompletedOnce.
@Test
@LargeTest
public void prepare_notifiesBufferingCompletedOnce() throws Throwable {
TestUtils.loadResource(R.raw.video_big_buck_bunny, sessionPlayerConnector);
CountDownLatch onBufferingCompletedLatch = new CountDownLatch(2);
CopyOnWriteArrayList<Integer> bufferingStateChanges = new CopyOnWriteArrayList<>();
SessionPlayer.PlayerCallback callback = new SessionPlayer.PlayerCallback() {
@Override
public void onBufferingStateChanged(SessionPlayer player, @Nullable MediaItem item, int buffState) {
bufferingStateChanges.add(buffState);
if (buffState == SessionPlayer.BUFFERING_STATE_COMPLETE) {
onBufferingCompletedLatch.countDown();
}
}
};
sessionPlayerConnector.registerPlayerCallback(executor, callback);
assertPlayerResultSuccess(sessionPlayerConnector.prepare());
assertWithMessage("Expected BUFFERING_STATE_COMPLETE only once. Full changes are %s", bufferingStateChanges).that(onBufferingCompletedLatch.await(PLAYER_STATE_CHANGE_WAIT_TIME_MS, MILLISECONDS)).isFalse();
assertThat(bufferingStateChanges).isNotEmpty();
int lastIndex = bufferingStateChanges.size() - 1;
assertWithMessage("Didn't end with BUFFERING_STATE_COMPLETE. Full changes are %s", bufferingStateChanges).that(bufferingStateChanges.get(lastIndex)).isEqualTo(SessionPlayer.BUFFERING_STATE_COMPLETE);
}
use of androidx.test.filters.LargeTest in project ExoPlayer by google.
the class SessionPlayerConnectorTest method seekTo_skipsUnnecessarySeek.
@Test
@LargeTest
public void seekTo_skipsUnnecessarySeek() throws Exception {
CountDownLatch readAllowedLatch = new CountDownLatch(1);
playerTestRule.setDataSourceInstrumentation(dataSpec -> {
try {
assertThat(readAllowedLatch.await(PLAYBACK_COMPLETED_WAIT_TIME_MS, MILLISECONDS)).isTrue();
} catch (Exception e) {
assertWithMessage("Unexpected exception %s", e).fail();
}
});
sessionPlayerConnector.setMediaItem(TestUtils.createMediaItem(R.raw.video_big_buck_bunny));
// prepare() will be pending until readAllowed is countDowned.
sessionPlayerConnector.prepare();
CopyOnWriteArrayList<Long> positionChanges = new CopyOnWriteArrayList<>();
long testIntermediateSeekToPosition1 = 3000;
long testIntermediateSeekToPosition2 = 2000;
long testFinalSeekToPosition = 1000;
CountDownLatch onSeekCompletedLatch = new CountDownLatch(1);
sessionPlayerConnector.registerPlayerCallback(executor, new SessionPlayer.PlayerCallback() {
@Override
public void onSeekCompleted(SessionPlayer player, long position) {
// Do not assert here, because onSeekCompleted() can be called after the player is
// closed.
positionChanges.add(position);
if (position == testFinalSeekToPosition) {
onSeekCompletedLatch.countDown();
}
}
});
ListenableFuture<PlayerResult> seekFuture1 = sessionPlayerConnector.seekTo(testIntermediateSeekToPosition1);
ListenableFuture<PlayerResult> seekFuture2 = sessionPlayerConnector.seekTo(testIntermediateSeekToPosition2);
ListenableFuture<PlayerResult> seekFuture3 = sessionPlayerConnector.seekTo(testFinalSeekToPosition);
readAllowedLatch.countDown();
assertThat(seekFuture1.get().getResultCode()).isEqualTo(RESULT_INFO_SKIPPED);
assertThat(seekFuture2.get().getResultCode()).isEqualTo(RESULT_INFO_SKIPPED);
assertThat(seekFuture3.get().getResultCode()).isEqualTo(RESULT_SUCCESS);
assertThat(onSeekCompletedLatch.await(PLAYBACK_COMPLETED_WAIT_TIME_MS, MILLISECONDS)).isTrue();
assertThat(positionChanges).containsNoneOf(testIntermediateSeekToPosition1, testIntermediateSeekToPosition2);
assertThat(positionChanges).contains(testFinalSeekToPosition);
}
use of androidx.test.filters.LargeTest in project ExoPlayer by google.
the class SessionPlayerConnectorTest method seekTo_whenUnderlyingPlayerAlsoSeeks_throwsNoException.
@Test
@LargeTest
public void seekTo_whenUnderlyingPlayerAlsoSeeks_throwsNoException() throws Exception {
TestUtils.loadResource(R.raw.video_big_buck_bunny, sessionPlayerConnector);
assertPlayerResultSuccess(sessionPlayerConnector.prepare());
ExoPlayer exoPlayer = playerTestRule.getExoPlayer();
List<ListenableFuture<PlayerResult>> futures = new ArrayList<>();
for (int i = 0; i < 10; i++) {
futures.add(sessionPlayerConnector.seekTo(4123));
InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> exoPlayer.seekTo(1243));
}
for (ListenableFuture<PlayerResult> future : futures) {
assertThat(future.get().getResultCode()).isAnyOf(PlayerResult.RESULT_INFO_SKIPPED, PlayerResult.RESULT_SUCCESS);
}
}
use of androidx.test.filters.LargeTest in project ExoPlayer by google.
the class SessionPlayerConnectorTest method setPlaybackSpeed_whenPrepared_notifiesOnPlaybackSpeedChanged.
@Test
@LargeTest
public void setPlaybackSpeed_whenPrepared_notifiesOnPlaybackSpeedChanged() throws Throwable {
TestUtils.loadResource(R.raw.video_big_buck_bunny, sessionPlayerConnector);
assertPlayerResultSuccess(sessionPlayerConnector.prepare());
CountDownLatch onPlaybackSpeedChangedLatch = new CountDownLatch(1);
SessionPlayer.PlayerCallback callback = new SessionPlayer.PlayerCallback() {
@Override
public void onPlaybackSpeedChanged(SessionPlayer player, float speed) {
assertThat(speed).isWithin(FLOAT_TOLERANCE).of(0.5f);
onPlaybackSpeedChangedLatch.countDown();
}
};
sessionPlayerConnector.registerPlayerCallback(executor, callback);
sessionPlayerConnector.setPlaybackSpeed(0.5f);
assertThat(onPlaybackSpeedChangedLatch.await(PLAYER_STATE_CHANGE_WAIT_TIME_MS, MILLISECONDS)).isTrue();
}
Aggregations