Search in sources :

Example 1 with MediumTest

use of androidx.test.filters.MediumTest 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)

Aggregations

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