Search in sources :

Example 1 with Rating

use of androidx.media2.common.Rating in project ExoPlayer by google.

the class SessionCallbackBuilderTest method allowedCommand_withoutPlaylist_disallowsSkipTo.

@Test
public void allowedCommand_withoutPlaylist_disallowsSkipTo() throws Exception {
    int testRewindIncrementMs = 100;
    int testFastForwardIncrementMs = 100;
    try (MediaSession session = createMediaSession(sessionPlayerConnector, new SessionCallbackBuilder(context, sessionPlayerConnector).setRatingCallback((mediaSession, controller, mediaId, rating) -> SessionResult.RESULT_ERROR_BAD_VALUE).setRewindIncrementMs(testRewindIncrementMs).setFastForwardIncrementMs(testFastForwardIncrementMs).setMediaItemProvider(new SessionCallbackBuilder.MediaIdMediaItemProvider()).build())) {
        assertPlayerResultSuccess(sessionPlayerConnector.setMediaItem(TestUtils.createMediaItem()));
        assertPlayerResultSuccess(sessionPlayerConnector.prepare());
        CountDownLatch latch = new CountDownLatch(1);
        OnConnectedListener listener = (controller, allowedCommands) -> {
            List<Integer> disallowedCommandCodes = Arrays.asList(SessionCommand.COMMAND_CODE_PLAYER_SKIP_TO_PLAYLIST_ITEM, SessionCommand.COMMAND_CODE_PLAYER_SKIP_TO_PREVIOUS_PLAYLIST_ITEM, SessionCommand.COMMAND_CODE_PLAYER_SKIP_TO_NEXT_PLAYLIST_ITEM);
            assertDisallowedCommands(disallowedCommandCodes, allowedCommands);
            latch.countDown();
        };
        try (MediaController controller = createConnectedController(session, listener, null)) {
            assertThat(latch.await(CONTROLLER_COMMAND_WAIT_TIME_MS, MILLISECONDS)).isTrue();
            assertSessionResultFailure(controller.skipToNextPlaylistItem());
            assertSessionResultFailure(controller.skipToPreviousPlaylistItem());
            assertSessionResultFailure(controller.skipToPlaylistItem(0));
        }
    }
}
Also used : Context(android.content.Context) HeartRating(androidx.media2.session.HeartRating) Arrays(java.util.Arrays) Bundle(android.os.Bundle) Uri(android.net.Uri) MediaSession(androidx.media2.session.MediaSession) RunWith(org.junit.runner.RunWith) SessionResult(androidx.media2.session.SessionResult) AndroidJUnit4(androidx.test.ext.junit.runners.AndroidJUnit4) TestUtils.assertPlayerResultSuccess(com.google.android.exoplayer2.ext.media2.TestUtils.assertPlayerResultSuccess) ApplicationProvider(androidx.test.core.app.ApplicationProvider) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) SessionCommand(androidx.media2.session.SessionCommand) ContextCompat(androidx.core.content.ContextCompat) LargeTest(androidx.test.filters.LargeTest) Before(org.junit.Before) SessionPlayer(androidx.media2.common.SessionPlayer) MediaMetadata(androidx.media2.common.MediaMetadata) Truth.assertWithMessage(com.google.common.truth.Truth.assertWithMessage) Executor(java.util.concurrent.Executor) TextUtils(android.text.TextUtils) UriMediaItem(androidx.media2.common.UriMediaItem) Test(org.junit.Test) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) Truth.assertThat(com.google.common.truth.Truth.assertThat) MediaItem(androidx.media2.common.MediaItem) Rating(androidx.media2.common.Rating) R(com.google.android.exoplayer2.ext.media2.test.R) CountDownLatch(java.util.concurrent.CountDownLatch) SessionCommandGroup(androidx.media2.session.SessionCommandGroup) List(java.util.List) Nullable(androidx.annotation.Nullable) Rule(org.junit.Rule) MediaController(androidx.media2.session.MediaController) RawResourceDataSource(com.google.android.exoplayer2.upstream.RawResourceDataSource) MediaController(androidx.media2.session.MediaController) MediaSession(androidx.media2.session.MediaSession) ArrayList(java.util.ArrayList) List(java.util.List) CountDownLatch(java.util.concurrent.CountDownLatch) LargeTest(androidx.test.filters.LargeTest) Test(org.junit.Test)

Example 2 with Rating

use of androidx.media2.common.Rating in project ExoPlayer by google.

the class SessionCallbackBuilderTest method constructor.

@Test
public void constructor() throws Exception {
    try (MediaSession session = createMediaSession(sessionPlayerConnector, new SessionCallbackBuilder(context, sessionPlayerConnector).build())) {
        assertPlayerResultSuccess(sessionPlayerConnector.setMediaItem(TestUtils.createMediaItem()));
        assertPlayerResultSuccess(sessionPlayerConnector.prepare());
        OnConnectedListener listener = (controller, allowedCommands) -> {
            List<Integer> disallowedCommandCodes = Arrays.asList(// no rating callback
            SessionCommand.COMMAND_CODE_SESSION_SET_RATING, // no media item provider
            SessionCommand.COMMAND_CODE_PLAYER_ADD_PLAYLIST_ITEM, SessionCommand.COMMAND_CODE_PLAYER_REPLACE_PLAYLIST_ITEM, // no media item provider
            SessionCommand.COMMAND_CODE_PLAYER_SET_MEDIA_ITEM, // no media item provider
            SessionCommand.COMMAND_CODE_PLAYER_SET_PLAYLIST, // no current media item
            SessionCommand.COMMAND_CODE_SESSION_REWIND, // no current media item
            SessionCommand.COMMAND_CODE_SESSION_FAST_FORWARD);
            assertDisallowedCommands(disallowedCommandCodes, allowedCommands);
        };
        try (MediaController controller = createConnectedController(session, listener, null)) {
            assertThat(controller.getPlayerState()).isEqualTo(SessionPlayer.PLAYER_STATE_PAUSED);
        }
    }
}
Also used : Context(android.content.Context) HeartRating(androidx.media2.session.HeartRating) Arrays(java.util.Arrays) Bundle(android.os.Bundle) Uri(android.net.Uri) MediaSession(androidx.media2.session.MediaSession) RunWith(org.junit.runner.RunWith) SessionResult(androidx.media2.session.SessionResult) AndroidJUnit4(androidx.test.ext.junit.runners.AndroidJUnit4) TestUtils.assertPlayerResultSuccess(com.google.android.exoplayer2.ext.media2.TestUtils.assertPlayerResultSuccess) ApplicationProvider(androidx.test.core.app.ApplicationProvider) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) SessionCommand(androidx.media2.session.SessionCommand) ContextCompat(androidx.core.content.ContextCompat) LargeTest(androidx.test.filters.LargeTest) Before(org.junit.Before) SessionPlayer(androidx.media2.common.SessionPlayer) MediaMetadata(androidx.media2.common.MediaMetadata) Truth.assertWithMessage(com.google.common.truth.Truth.assertWithMessage) Executor(java.util.concurrent.Executor) TextUtils(android.text.TextUtils) UriMediaItem(androidx.media2.common.UriMediaItem) Test(org.junit.Test) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) Truth.assertThat(com.google.common.truth.Truth.assertThat) MediaItem(androidx.media2.common.MediaItem) Rating(androidx.media2.common.Rating) R(com.google.android.exoplayer2.ext.media2.test.R) CountDownLatch(java.util.concurrent.CountDownLatch) SessionCommandGroup(androidx.media2.session.SessionCommandGroup) List(java.util.List) Nullable(androidx.annotation.Nullable) Rule(org.junit.Rule) MediaController(androidx.media2.session.MediaController) RawResourceDataSource(com.google.android.exoplayer2.upstream.RawResourceDataSource) MediaController(androidx.media2.session.MediaController) MediaSession(androidx.media2.session.MediaSession) ArrayList(java.util.ArrayList) List(java.util.List) LargeTest(androidx.test.filters.LargeTest) Test(org.junit.Test)

Example 3 with Rating

use of androidx.media2.common.Rating in project ExoPlayer by google.

the class SessionCallbackBuilderTest method setRatingCallback_withRatingCallback_receivesRatingCallback.

@Test
public void setRatingCallback_withRatingCallback_receivesRatingCallback() throws Exception {
    String testMediaId = "testRating";
    Rating testRating = new HeartRating(true);
    CountDownLatch latch = new CountDownLatch(1);
    SessionCallbackBuilder.RatingCallback ratingCallback = (session, controller, mediaId, rating) -> {
        assertThat(mediaId).isEqualTo(testMediaId);
        assertThat(rating).isEqualTo(testRating);
        latch.countDown();
        return SessionResult.RESULT_SUCCESS;
    };
    try (MediaSession session = createMediaSession(sessionPlayerConnector, new SessionCallbackBuilder(context, sessionPlayerConnector).setRatingCallback(ratingCallback).build())) {
        try (MediaController controller = createConnectedController(session)) {
            assertSessionResultSuccess(controller.setRating(testMediaId, testRating), CONTROLLER_COMMAND_WAIT_TIME_MS);
            assertThat(latch.await(0, MILLISECONDS)).isTrue();
        }
    }
}
Also used : Context(android.content.Context) HeartRating(androidx.media2.session.HeartRating) Arrays(java.util.Arrays) Bundle(android.os.Bundle) Uri(android.net.Uri) MediaSession(androidx.media2.session.MediaSession) RunWith(org.junit.runner.RunWith) SessionResult(androidx.media2.session.SessionResult) AndroidJUnit4(androidx.test.ext.junit.runners.AndroidJUnit4) TestUtils.assertPlayerResultSuccess(com.google.android.exoplayer2.ext.media2.TestUtils.assertPlayerResultSuccess) ApplicationProvider(androidx.test.core.app.ApplicationProvider) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) SessionCommand(androidx.media2.session.SessionCommand) ContextCompat(androidx.core.content.ContextCompat) LargeTest(androidx.test.filters.LargeTest) Before(org.junit.Before) SessionPlayer(androidx.media2.common.SessionPlayer) MediaMetadata(androidx.media2.common.MediaMetadata) Truth.assertWithMessage(com.google.common.truth.Truth.assertWithMessage) Executor(java.util.concurrent.Executor) TextUtils(android.text.TextUtils) UriMediaItem(androidx.media2.common.UriMediaItem) Test(org.junit.Test) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) Truth.assertThat(com.google.common.truth.Truth.assertThat) MediaItem(androidx.media2.common.MediaItem) Rating(androidx.media2.common.Rating) R(com.google.android.exoplayer2.ext.media2.test.R) CountDownLatch(java.util.concurrent.CountDownLatch) SessionCommandGroup(androidx.media2.session.SessionCommandGroup) List(java.util.List) Nullable(androidx.annotation.Nullable) Rule(org.junit.Rule) MediaController(androidx.media2.session.MediaController) RawResourceDataSource(com.google.android.exoplayer2.upstream.RawResourceDataSource) MediaController(androidx.media2.session.MediaController) MediaSession(androidx.media2.session.MediaSession) HeartRating(androidx.media2.session.HeartRating) Rating(androidx.media2.common.Rating) CountDownLatch(java.util.concurrent.CountDownLatch) HeartRating(androidx.media2.session.HeartRating) LargeTest(androidx.test.filters.LargeTest) Test(org.junit.Test)

Example 4 with Rating

use of androidx.media2.common.Rating in project ExoPlayer by google.

the class SessionCallbackBuilderTest method allowedCommand_whenPlaylistSet_allowsSkipTo.

@Test
public void allowedCommand_whenPlaylistSet_allowsSkipTo() throws Exception {
    List<MediaItem> testPlaylist = new ArrayList<>();
    testPlaylist.add(TestUtils.createMediaItem(R.raw.video_desks));
    testPlaylist.add(TestUtils.createMediaItem(R.raw.video_not_seekable));
    int testRewindIncrementMs = 100;
    int testFastForwardIncrementMs = 100;
    try (MediaSession session = createMediaSession(sessionPlayerConnector, new SessionCallbackBuilder(context, sessionPlayerConnector).setRatingCallback((mediaSession, controller, mediaId, rating) -> SessionResult.RESULT_ERROR_BAD_VALUE).setRewindIncrementMs(testRewindIncrementMs).setFastForwardIncrementMs(testFastForwardIncrementMs).setMediaItemProvider(new SessionCallbackBuilder.MediaIdMediaItemProvider()).build())) {
        assertPlayerResultSuccess(sessionPlayerConnector.setPlaylist(testPlaylist, null));
        assertPlayerResultSuccess(sessionPlayerConnector.prepare());
        OnConnectedListener connectedListener = (controller, allowedCommands) -> {
            List<Integer> allowedCommandCodes = Arrays.asList(SessionCommand.COMMAND_CODE_PLAYER_SKIP_TO_NEXT_PLAYLIST_ITEM, SessionCommand.COMMAND_CODE_PLAYER_SEEK_TO, SessionCommand.COMMAND_CODE_SESSION_REWIND, SessionCommand.COMMAND_CODE_SESSION_FAST_FORWARD);
            assertAllowedCommands(allowedCommandCodes, allowedCommands);
            List<Integer> disallowedCommandCodes = Arrays.asList(SessionCommand.COMMAND_CODE_PLAYER_SKIP_TO_PREVIOUS_PLAYLIST_ITEM);
            assertDisallowedCommands(disallowedCommandCodes, allowedCommands);
        };
        CountDownLatch allowedCommandChangedLatch = new CountDownLatch(1);
        OnAllowedCommandsChangedListener allowedCommandChangedListener = (controller, allowedCommands) -> {
            List<Integer> allowedCommandCodes = Arrays.asList(SessionCommand.COMMAND_CODE_PLAYER_SKIP_TO_PREVIOUS_PLAYLIST_ITEM);
            assertAllowedCommands(allowedCommandCodes, allowedCommands);
            List<Integer> disallowedCommandCodes = Arrays.asList(SessionCommand.COMMAND_CODE_PLAYER_SKIP_TO_NEXT_PLAYLIST_ITEM, SessionCommand.COMMAND_CODE_PLAYER_SEEK_TO, SessionCommand.COMMAND_CODE_SESSION_REWIND, SessionCommand.COMMAND_CODE_SESSION_FAST_FORWARD);
            assertDisallowedCommands(disallowedCommandCodes, allowedCommands);
            allowedCommandChangedLatch.countDown();
        };
        try (MediaController controller = createConnectedController(session, connectedListener, allowedCommandChangedListener)) {
            assertPlayerResultSuccess(sessionPlayerConnector.skipToNextPlaylistItem());
            assertThat(allowedCommandChangedLatch.await(CONTROLLER_COMMAND_WAIT_TIME_MS, MILLISECONDS)).isTrue();
            // Also test whether the rewind fails as expected.
            assertSessionResultFailure(controller.rewind());
            assertThat(sessionPlayerConnector.getCurrentPosition()).isEqualTo(0);
            assertThat(controller.getCurrentPosition()).isEqualTo(0);
        }
    }
}
Also used : Context(android.content.Context) HeartRating(androidx.media2.session.HeartRating) Arrays(java.util.Arrays) Bundle(android.os.Bundle) Uri(android.net.Uri) MediaSession(androidx.media2.session.MediaSession) RunWith(org.junit.runner.RunWith) SessionResult(androidx.media2.session.SessionResult) AndroidJUnit4(androidx.test.ext.junit.runners.AndroidJUnit4) TestUtils.assertPlayerResultSuccess(com.google.android.exoplayer2.ext.media2.TestUtils.assertPlayerResultSuccess) ApplicationProvider(androidx.test.core.app.ApplicationProvider) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) SessionCommand(androidx.media2.session.SessionCommand) ContextCompat(androidx.core.content.ContextCompat) LargeTest(androidx.test.filters.LargeTest) Before(org.junit.Before) SessionPlayer(androidx.media2.common.SessionPlayer) MediaMetadata(androidx.media2.common.MediaMetadata) Truth.assertWithMessage(com.google.common.truth.Truth.assertWithMessage) Executor(java.util.concurrent.Executor) TextUtils(android.text.TextUtils) UriMediaItem(androidx.media2.common.UriMediaItem) Test(org.junit.Test) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) Truth.assertThat(com.google.common.truth.Truth.assertThat) MediaItem(androidx.media2.common.MediaItem) Rating(androidx.media2.common.Rating) R(com.google.android.exoplayer2.ext.media2.test.R) CountDownLatch(java.util.concurrent.CountDownLatch) SessionCommandGroup(androidx.media2.session.SessionCommandGroup) List(java.util.List) Nullable(androidx.annotation.Nullable) Rule(org.junit.Rule) MediaController(androidx.media2.session.MediaController) RawResourceDataSource(com.google.android.exoplayer2.upstream.RawResourceDataSource) MediaController(androidx.media2.session.MediaController) ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) MediaSession(androidx.media2.session.MediaSession) UriMediaItem(androidx.media2.common.UriMediaItem) MediaItem(androidx.media2.common.MediaItem) ArrayList(java.util.ArrayList) List(java.util.List) LargeTest(androidx.test.filters.LargeTest) Test(org.junit.Test)

Aggregations

Context (android.content.Context)4 Uri (android.net.Uri)4 Bundle (android.os.Bundle)4 TextUtils (android.text.TextUtils)4 Nullable (androidx.annotation.Nullable)4 ContextCompat (androidx.core.content.ContextCompat)4 MediaItem (androidx.media2.common.MediaItem)4 MediaMetadata (androidx.media2.common.MediaMetadata)4 Rating (androidx.media2.common.Rating)4 SessionPlayer (androidx.media2.common.SessionPlayer)4 UriMediaItem (androidx.media2.common.UriMediaItem)4 HeartRating (androidx.media2.session.HeartRating)4 MediaController (androidx.media2.session.MediaController)4 MediaSession (androidx.media2.session.MediaSession)4 SessionCommand (androidx.media2.session.SessionCommand)4 SessionCommandGroup (androidx.media2.session.SessionCommandGroup)4 SessionResult (androidx.media2.session.SessionResult)4 ApplicationProvider (androidx.test.core.app.ApplicationProvider)4 AndroidJUnit4 (androidx.test.ext.junit.runners.AndroidJUnit4)4 LargeTest (androidx.test.filters.LargeTest)4