Search in sources :

Example 26 with LargeTest

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);
}
Also used : UriMediaItem(androidx.media2.common.UriMediaItem) MediaItem(androidx.media2.common.MediaItem) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) AtomicReference(java.util.concurrent.atomic.AtomicReference) ExoPlayer(com.google.android.exoplayer2.ExoPlayer) 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 27 with LargeTest

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();
}
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)

Example 28 with LargeTest

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();
        }
    }
}
Also used : Player(com.google.android.exoplayer2.Player) ExoPlayer(com.google.android.exoplayer2.ExoPlayer) SessionPlayer(androidx.media2.common.SessionPlayer) ForwardingPlayer(com.google.android.exoplayer2.ForwardingPlayer) ForwardingPlayer(com.google.android.exoplayer2.ForwardingPlayer) 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 29 with LargeTest

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);
}
Also used : UriMediaItem(androidx.media2.common.UriMediaItem) MediaItem(androidx.media2.common.MediaItem) SessionPlayer(androidx.media2.common.SessionPlayer) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) UriMediaItem(androidx.media2.common.UriMediaItem) 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 30 with LargeTest

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();
}
Also used : SessionPlayer(androidx.media2.common.SessionPlayer) ExoPlayer(com.google.android.exoplayer2.ExoPlayer) 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

LargeTest (androidx.test.filters.LargeTest)36 Test (org.junit.Test)36 MediumTest (androidx.test.filters.MediumTest)29 SmallTest (androidx.test.filters.SmallTest)29 SessionPlayer (androidx.media2.common.SessionPlayer)24 CountDownLatch (java.util.concurrent.CountDownLatch)23 MediaItem (androidx.media2.common.MediaItem)13 UriMediaItem (androidx.media2.common.UriMediaItem)13 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)12 ArrayList (java.util.ArrayList)9 MediaMetadata (androidx.media2.common.MediaMetadata)7 ExoPlayer (com.google.android.exoplayer2.ExoPlayer)7 AudioAttributesCompat (androidx.media.AudioAttributesCompat)3 PlayerResult (androidx.media2.common.SessionPlayer.PlayerResult)3 ViewInteraction (androidx.test.espresso.ViewInteraction)3 TestUtils.assertPlayerResult (com.google.android.exoplayer2.ext.media2.TestUtils.assertPlayerResult)3 Activity (android.app.Activity)2 Intent (android.content.Intent)2 Bundle (android.os.Bundle)2 CancellationSignal (android.os.CancellationSignal)2