use of androidx.media.AudioAttributesCompat in project ExoPlayer by google.
the class SessionPlayerConnectorTest method play_onceWithAudioResourceOnMainThread_notifiesOnPlayerStateChanged.
@Test
@MediumTest
public void play_onceWithAudioResourceOnMainThread_notifiesOnPlayerStateChanged() throws Exception {
CountDownLatch onPlayerStatePlayingLatch = new CountDownLatch(1);
InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> {
try {
TestUtils.loadResource(R.raw.audio, sessionPlayerConnector);
} catch (Exception e) {
assertWithMessage(e.getMessage()).fail();
}
AudioAttributesCompat attributes = new AudioAttributesCompat.Builder().setLegacyStreamType(AudioManager.STREAM_MUSIC).build();
sessionPlayerConnector.setAudioAttributes(attributes);
sessionPlayerConnector.registerPlayerCallback(executor, new SessionPlayer.PlayerCallback() {
@Override
public void onPlayerStateChanged(SessionPlayer player, int playerState) {
if (playerState == PLAYER_STATE_PLAYING) {
onPlayerStatePlayingLatch.countDown();
}
}
});
sessionPlayerConnector.prepare();
sessionPlayerConnector.play();
});
assertThat(onPlayerStatePlayingLatch.await(PLAYER_STATE_CHANGE_WAIT_TIME_MS, MILLISECONDS)).isTrue();
}
use of androidx.media.AudioAttributesCompat in project ExoPlayer by google.
the class SessionPlayerConnectorTest method close_throwsNoExceptionAndDoesNotCrash.
@Test
@LargeTest
public void close_throwsNoExceptionAndDoesNotCrash() throws Exception {
TestUtils.loadResource(R.raw.audio, sessionPlayerConnector);
AudioAttributesCompat attributes = new AudioAttributesCompat.Builder().setLegacyStreamType(AudioManager.STREAM_MUSIC).build();
sessionPlayerConnector.setAudioAttributes(attributes);
sessionPlayerConnector.prepare();
sessionPlayerConnector.play();
sessionPlayerConnector.close();
// Set the player to null so we don't try to close it again in tearDown().
sessionPlayerConnector = null;
// Tests whether the notification from the player after the close() doesn't crash.
Thread.sleep(PLAYER_STATE_CHANGE_WAIT_TIME_MS);
}
use of androidx.media.AudioAttributesCompat in project ExoPlayer by google.
the class SessionPlayerConnectorTest method getPlayerState_withPrepareAndPlayAndPause_changesAsExpected.
@Test
@LargeTest
public void getPlayerState_withPrepareAndPlayAndPause_changesAsExpected() throws Exception {
TestUtils.loadResource(R.raw.audio, sessionPlayerConnector);
AudioAttributesCompat attributes = new AudioAttributesCompat.Builder().setLegacyStreamType(AudioManager.STREAM_MUSIC).build();
sessionPlayerConnector.setAudioAttributes(attributes);
sessionPlayerConnector.setRepeatMode(SessionPlayer.REPEAT_MODE_ALL);
assertThat(sessionPlayerConnector.getPlayerState()).isEqualTo(SessionPlayer.PLAYER_STATE_IDLE);
assertPlayerResultSuccess(sessionPlayerConnector.prepare());
assertThat(sessionPlayerConnector.getPlayerState()).isEqualTo(SessionPlayer.PLAYER_STATE_PAUSED);
assertPlayerResultSuccess(sessionPlayerConnector.play());
assertThat(sessionPlayerConnector.getPlayerState()).isEqualTo(PLAYER_STATE_PLAYING);
}
use of androidx.media.AudioAttributesCompat 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();
}
Aggregations