Search in sources :

Example 1 with HeartRating

use of androidx.media2.session.HeartRating 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)

Aggregations

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