Search in sources :

Example 1 with AudioAttributesCompat

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();
}
Also used : AudioAttributesCompat(androidx.media.AudioAttributesCompat) SessionPlayer(androidx.media2.common.SessionPlayer) CountDownLatch(java.util.concurrent.CountDownLatch) MediumTest(androidx.test.filters.MediumTest) LargeTest(androidx.test.filters.LargeTest) SmallTest(androidx.test.filters.SmallTest) Test(org.junit.Test) MediumTest(androidx.test.filters.MediumTest)

Example 2 with AudioAttributesCompat

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);
}
Also used : AudioAttributesCompat(androidx.media.AudioAttributesCompat) MediumTest(androidx.test.filters.MediumTest) LargeTest(androidx.test.filters.LargeTest) SmallTest(androidx.test.filters.SmallTest) Test(org.junit.Test) LargeTest(androidx.test.filters.LargeTest)

Example 3 with AudioAttributesCompat

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);
}
Also used : AudioAttributesCompat(androidx.media.AudioAttributesCompat) MediumTest(androidx.test.filters.MediumTest) LargeTest(androidx.test.filters.LargeTest) SmallTest(androidx.test.filters.SmallTest) Test(org.junit.Test) LargeTest(androidx.test.filters.LargeTest)

Example 4 with AudioAttributesCompat

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();
}
Also used : AudioAttributesCompat(androidx.media.AudioAttributesCompat) SessionPlayer(androidx.media2.common.SessionPlayer) CountDownLatch(java.util.concurrent.CountDownLatch) MediumTest(androidx.test.filters.MediumTest) LargeTest(androidx.test.filters.LargeTest) SmallTest(androidx.test.filters.SmallTest) Test(org.junit.Test) LargeTest(androidx.test.filters.LargeTest)

Aggregations

AudioAttributesCompat (androidx.media.AudioAttributesCompat)4 LargeTest (androidx.test.filters.LargeTest)4 MediumTest (androidx.test.filters.MediumTest)4 SmallTest (androidx.test.filters.SmallTest)4 Test (org.junit.Test)4 SessionPlayer (androidx.media2.common.SessionPlayer)2 CountDownLatch (java.util.concurrent.CountDownLatch)2