use of androidx.test.filters.LargeTest in project ExoPlayer by google.
the class SessionPlayerConnectorTest method getPlaylist_returnsPlaylistInUnderlyingPlayer.
@Test
@LargeTest
public void getPlaylist_returnsPlaylistInUnderlyingPlayer() {
List<MediaItem> playlistToExoPlayer = TestUtils.createPlaylist(4);
DefaultMediaItemConverter converter = new DefaultMediaItemConverter();
List<com.google.android.exoplayer2.MediaItem> exoMediaItems = new ArrayList<>();
for (MediaItem mediaItem : playlistToExoPlayer) {
exoMediaItems.add(converter.convertToExoPlayerMediaItem(mediaItem));
}
AtomicReference<List<MediaItem>> playlistFromSessionPlayer = new AtomicReference<>();
InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> {
ExoPlayer exoPlayer = playerTestRule.getExoPlayer();
exoPlayer.setMediaItems(exoMediaItems);
try (SessionPlayerConnector sessionPlayer = new SessionPlayerConnector(exoPlayer)) {
List<MediaItem> playlist = sessionPlayer.getPlaylist();
playlistFromSessionPlayer.set(playlist);
}
});
assertThat(playlistFromSessionPlayer.get()).isEqualTo(playlistToExoPlayer);
}
use of androidx.test.filters.LargeTest in project ExoPlayer by google.
the class SessionPlayerConnectorTest method play_onceWithAudioResource_changesPlayerStateToPlaying.
@Test
@LargeTest
public void play_onceWithAudioResource_changesPlayerStateToPlaying() throws Exception {
TestUtils.loadResource(R.raw.audio, sessionPlayerConnector);
AudioAttributesCompat attributes = new AudioAttributesCompat.Builder().setLegacyStreamType(AudioManager.STREAM_MUSIC).build();
sessionPlayerConnector.setAudioAttributes(attributes);
CountDownLatch onPlayingLatch = new CountDownLatch(1);
sessionPlayerConnector.registerPlayerCallback(executor, new SessionPlayer.PlayerCallback() {
@Override
public void onPlayerStateChanged(SessionPlayer player, int playerState) {
if (playerState == PLAYER_STATE_PLAYING) {
onPlayingLatch.countDown();
}
}
});
sessionPlayerConnector.prepare();
sessionPlayerConnector.play();
assertThat(onPlayingLatch.await(PLAYER_STATE_CHANGE_WAIT_TIME_MS, MILLISECONDS)).isTrue();
}
use of androidx.test.filters.LargeTest in project ExoPlayer by google.
the class SessionPlayerConnectorTest method play_withForwardingPlayer_isSkipped.
@Test
@LargeTest
public void play_withForwardingPlayer_isSkipped() throws Exception {
if (Looper.myLooper() == null) {
Looper.prepare();
}
Player forwardingPlayer = null;
SessionPlayerConnector playerConnector = null;
try {
Player exoPlayer = new ExoPlayer.Builder(context).setLooper(Looper.myLooper()).build();
forwardingPlayer = new ForwardingPlayer(exoPlayer) {
@Override
public boolean isCommandAvailable(int command) {
if (command == COMMAND_PLAY_PAUSE) {
return false;
}
return super.isCommandAvailable(command);
}
@Override
public Commands getAvailableCommands() {
return super.getAvailableCommands().buildUpon().remove(COMMAND_PLAY_PAUSE).build();
}
};
playerConnector = new SessionPlayerConnector(forwardingPlayer);
assertPlayerResult(playerConnector.play(), RESULT_INFO_SKIPPED);
} finally {
if (playerConnector != null) {
playerConnector.close();
}
if (forwardingPlayer != null) {
forwardingPlayer.release();
}
}
}
use of androidx.test.filters.LargeTest in project ExoPlayer by google.
the class SessionPlayerConnectorTest method setPlaybackSpeed_afterPlayback_remainsSame.
@Test
@LargeTest
public void setPlaybackSpeed_afterPlayback_remainsSame() throws Exception {
int resId1 = R.raw.video_big_buck_bunny;
MediaItem mediaItem1 = new UriMediaItem.Builder(RawResourceDataSource.buildRawResourceUri(resId1)).setStartPosition(6_000).setEndPosition(7_000).build();
MediaItem mediaItem2 = new UriMediaItem.Builder(RawResourceDataSource.buildRawResourceUri(resId1)).setStartPosition(3_000).setEndPosition(4_000).build();
List<MediaItem> items = new ArrayList<>();
items.add(mediaItem1);
items.add(mediaItem2);
sessionPlayerConnector.setPlaylist(items, null);
CountDownLatch onPlaybackCompletedLatch = new CountDownLatch(1);
SessionPlayer.PlayerCallback callback = new SessionPlayer.PlayerCallback() {
@Override
public void onPlaybackCompleted(SessionPlayer player) {
onPlaybackCompletedLatch.countDown();
}
};
sessionPlayerConnector.registerPlayerCallback(executor, callback);
sessionPlayerConnector.prepare().get();
sessionPlayerConnector.setPlaybackSpeed(2.0f);
sessionPlayerConnector.play();
assertThat(onPlaybackCompletedLatch.await(PLAYBACK_COMPLETED_WAIT_TIME_MS, MILLISECONDS)).isTrue();
assertThat(sessionPlayerConnector.getCurrentMediaItem()).isEqualTo(mediaItem2);
assertThat(sessionPlayerConnector.getPlaybackSpeed()).isWithin(0.001f).of(2.0f);
}
use of androidx.test.filters.LargeTest in project ExoPlayer by google.
the class SessionPlayerConnectorTest method pause_byUnderlyingPlayer_notifiesOnPlayerStateChanges.
@Test
@LargeTest
public void pause_byUnderlyingPlayer_notifiesOnPlayerStateChanges() throws Exception {
TestUtils.loadResource(R.raw.audio, sessionPlayerConnector);
ExoPlayer exoPlayer = playerTestRule.getExoPlayer();
assertPlayerResultSuccess(sessionPlayerConnector.prepare());
CountDownLatch onPausedLatch = new CountDownLatch(1);
sessionPlayerConnector.registerPlayerCallback(executor, new SessionPlayer.PlayerCallback() {
@Override
public void onPlayerStateChanged(SessionPlayer player, int playerState) {
if (playerState == PLAYER_STATE_PAUSED) {
onPausedLatch.countDown();
}
}
});
assertPlayerResultSuccess(sessionPlayerConnector.play());
InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> exoPlayer.setPlayWhenReady(false));
assertThat(onPausedLatch.await(PLAYER_STATE_CHANGE_WAIT_TIME_MS, MILLISECONDS)).isTrue();
}
Aggregations