Search in sources :

Example 6 with PlaybackException

use of androidx.media3.common.PlaybackException in project media by androidx.

the class MediaControllerCompatCallbackWithMediaSessionTest method playerError_notified.

@Test
public void playerError_notified() throws Exception {
    PlaybackException testPlayerError = new PlaybackException(/* messaage= */
    "player error", /* cause= */
    null, PlaybackException.ERROR_CODE_UNSPECIFIED);
    CountDownLatch latch = new CountDownLatch(1);
    AtomicReference<PlaybackStateCompat> playbackStateCompatRef = new AtomicReference<>();
    MediaControllerCompat.Callback callback = new MediaControllerCompat.Callback() {

        @Override
        public void onPlaybackStateChanged(PlaybackStateCompat state) {
            playbackStateCompatRef.set(state);
            latch.countDown();
        }
    };
    controllerCompat.registerCallback(callback, handler);
    session.getMockPlayer().notifyPlayerError(testPlayerError);
    assertThat(latch.await(TIMEOUT_MS, MILLISECONDS)).isTrue();
    PlaybackStateCompat state = playbackStateCompatRef.get();
    assertPlaybackStateCompatErrorEquals(state, testPlayerError);
}
Also used : PlaybackException(androidx.media3.common.PlaybackException) PlaybackStateCompat(android.support.v4.media.session.PlaybackStateCompat) AtomicReference(java.util.concurrent.atomic.AtomicReference) MediaControllerCompat(android.support.v4.media.session.MediaControllerCompat) CountDownLatch(java.util.concurrent.CountDownLatch) LargeTest(androidx.test.filters.LargeTest) Test(org.junit.Test)

Example 7 with PlaybackException

use of androidx.media3.common.PlaybackException in project media by androidx.

the class MediaControllerStateMaskingTest method stop.

@Test
public void stop() throws Exception {
    long duration = 6000L;
    long initialCurrentPosition = 3000L;
    long initialBufferedPosition = duration;
    int initialBufferedPercentage = 100;
    long initialTotalBufferedDuration = initialBufferedPosition - initialCurrentPosition;
    int testPlaybackState = Player.STATE_IDLE;
    long testCurrentPosition = 3000L;
    long testBufferedPosition = testCurrentPosition;
    int testBufferedPercentage = 50;
    long testTotalBufferedDuration = testBufferedPosition - testCurrentPosition;
    Timeline testTimeline = MediaTestUtils.createTimeline(3);
    PlaybackException testPlaybackException = new PlaybackException(/* message= */
    "test", /* cause= */
    null, PlaybackException.ERROR_CODE_REMOTE_ERROR);
    Bundle playerConfig = new RemoteMediaSession.MockPlayerConfigBuilder().setDuration(duration).setPlaybackState(Player.STATE_READY).setPlayerError(testPlaybackException).setTimeline(testTimeline).setCurrentPosition(initialCurrentPosition).setBufferedPosition(initialBufferedPosition).setBufferedPercentage(initialBufferedPercentage).setTotalBufferedDuration(initialTotalBufferedDuration).build();
    remoteSession.setPlayer(playerConfig);
    MediaController controller = controllerTestRule.createController(remoteSession.getToken());
    CountDownLatch latch = new CountDownLatch(2);
    AtomicInteger playbackStateFromCallbackRef = new AtomicInteger();
    AtomicReference<Player.Events> onEventsRef = new AtomicReference<>();
    Player.Listener listener = new Player.Listener() {

        @Override
        public void onPlaybackStateChanged(int playbackState) {
            playbackStateFromCallbackRef.set(playbackState);
            latch.countDown();
        }

        @Override
        public void onEvents(Player player, Player.Events events) {
            onEventsRef.set(events);
            latch.countDown();
        }
    };
    threadTestRule.getHandler().postAndSync(() -> controller.addListener(listener));
    AtomicInteger playbackStateFromGetterRef = new AtomicInteger();
    AtomicReference<PlaybackException> playerErrorFromGetterRef = new AtomicReference<>();
    AtomicReference<Timeline> timelineFromGetterRef = new AtomicReference<>();
    AtomicLong currentPositionFromGetterRef = new AtomicLong();
    AtomicLong bufferedPositionFromGetterRef = new AtomicLong();
    AtomicInteger bufferedPercentageFromGetterRef = new AtomicInteger();
    AtomicLong totalBufferedDurationFromGetterRef = new AtomicLong();
    threadTestRule.getHandler().postAndSync(() -> {
        controller.stop();
        playbackStateFromGetterRef.set(controller.getPlaybackState());
        playerErrorFromGetterRef.set(controller.getPlayerError());
        timelineFromGetterRef.set(controller.getCurrentTimeline());
        currentPositionFromGetterRef.set(controller.getCurrentPosition());
        bufferedPositionFromGetterRef.set(controller.getBufferedPosition());
        bufferedPercentageFromGetterRef.set(controller.getBufferedPercentage());
        totalBufferedDurationFromGetterRef.set(controller.getTotalBufferedDuration());
    });
    assertThat(latch.await(TIMEOUT_MS, MILLISECONDS)).isTrue();
    assertThat(playbackStateFromCallbackRef.get()).isEqualTo(testPlaybackState);
    assertThat(onEventsRef.get().contains(Player.EVENT_PLAYBACK_STATE_CHANGED)).isTrue();
    assertThat(playbackStateFromGetterRef.get()).isEqualTo(testPlaybackState);
    assertThat(playerErrorFromGetterRef.get().errorInfoEquals(testPlaybackException)).isTrue();
    assertThat(timelineFromGetterRef.get().getWindowCount()).isEqualTo(testTimeline.getWindowCount());
    assertThat(currentPositionFromGetterRef.get()).isEqualTo(testCurrentPosition);
    assertThat(bufferedPositionFromGetterRef.get()).isEqualTo(testBufferedPosition);
    assertThat(bufferedPercentageFromGetterRef.get()).isEqualTo(testBufferedPercentage);
    assertThat(totalBufferedDurationFromGetterRef.get()).isEqualTo(testTotalBufferedDuration);
}
Also used : PlaybackException(androidx.media3.common.PlaybackException) Player(androidx.media3.common.Player) Bundle(android.os.Bundle) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) MediaTestUtils.createTimeline(androidx.media3.session.MediaTestUtils.createTimeline) Timeline(androidx.media3.common.Timeline) AtomicLong(java.util.concurrent.atomic.AtomicLong) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LargeTest(androidx.test.filters.LargeTest) Test(org.junit.Test)

Example 8 with PlaybackException

use of androidx.media3.common.PlaybackException in project media by androidx.

the class MediaControllerStateMaskingTest method prepare.

@Test
public void prepare() throws Exception {
    int testPlaybackState = Player.STATE_ENDED;
    Bundle playerConfig = new RemoteMediaSession.MockPlayerConfigBuilder().setPlaybackState(Player.STATE_IDLE).setPlayerError(new PlaybackException(/* message= */
    "test", /* cause= */
    null, PlaybackException.ERROR_CODE_REMOTE_ERROR)).build();
    remoteSession.setPlayer(playerConfig);
    MediaController controller = controllerTestRule.createController(remoteSession.getToken());
    CountDownLatch latch = new CountDownLatch(2);
    AtomicInteger playbackStateFromCallbackRef = new AtomicInteger();
    AtomicReference<Player.Events> onEventsRef = new AtomicReference<>();
    Player.Listener listener = new Player.Listener() {

        @Override
        public void onPlaybackStateChanged(int playbackState) {
            playbackStateFromCallbackRef.set(playbackState);
            latch.countDown();
        }

        @Override
        public void onEvents(Player player, Player.Events events) {
            onEventsRef.set(events);
            latch.countDown();
        }
    };
    threadTestRule.getHandler().postAndSync(() -> controller.addListener(listener));
    AtomicInteger playbackStateFromGetterRef = new AtomicInteger();
    AtomicReference<PlaybackException> playerErrorRef = new AtomicReference<>();
    threadTestRule.getHandler().postAndSync(() -> {
        controller.prepare();
        playbackStateFromGetterRef.set(controller.getPlaybackState());
        playerErrorRef.set(controller.getPlayerError());
    });
    assertThat(latch.await(TIMEOUT_MS, MILLISECONDS)).isTrue();
    assertThat(playbackStateFromCallbackRef.get()).isEqualTo(testPlaybackState);
    assertThat(onEventsRef.get().contains(Player.EVENT_PLAYBACK_STATE_CHANGED)).isTrue();
    assertThat(playbackStateFromGetterRef.get()).isEqualTo(testPlaybackState);
    assertThat(playerErrorRef.get()).isNull();
}
Also used : PlaybackException(androidx.media3.common.PlaybackException) Player(androidx.media3.common.Player) Bundle(android.os.Bundle) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LargeTest(androidx.test.filters.LargeTest) Test(org.junit.Test)

Example 9 with PlaybackException

use of androidx.media3.common.PlaybackException in project media by androidx.

the class PlayerView method updateErrorMessage.

private void updateErrorMessage() {
    if (errorMessageView != null) {
        if (customErrorMessage != null) {
            errorMessageView.setText(customErrorMessage);
            errorMessageView.setVisibility(View.VISIBLE);
            return;
        }
        @Nullable PlaybackException error = player != null ? player.getPlayerError() : null;
        if (error != null && errorMessageProvider != null) {
            CharSequence errorMessage = errorMessageProvider.getErrorMessage(error).second;
            errorMessageView.setText(errorMessage);
            errorMessageView.setVisibility(View.VISIBLE);
        } else {
            errorMessageView.setVisibility(View.GONE);
        }
    }
}
Also used : PlaybackException(androidx.media3.common.PlaybackException) Nullable(androidx.annotation.Nullable)

Example 10 with PlaybackException

use of androidx.media3.common.PlaybackException in project media by androidx.

the class DefaultAnalyticsCollector method onPlayerError.

@Override
public final void onPlayerError(PlaybackException error) {
    EventTime eventTime = getEventTimeForErrorEvent(error);
    sendEvent(eventTime, AnalyticsListener.EVENT_PLAYER_ERROR, listener -> listener.onPlayerError(eventTime, error));
}
Also used : EventTime(androidx.media3.exoplayer.analytics.AnalyticsListener.EventTime)

Aggregations

PlaybackException (androidx.media3.common.PlaybackException)20 Test (org.junit.Test)12 Nullable (androidx.annotation.Nullable)9 AtomicReference (java.util.concurrent.atomic.AtomicReference)9 LargeTest (androidx.test.filters.LargeTest)7 CountDownLatch (java.util.concurrent.CountDownLatch)7 Bundle (android.os.Bundle)5 Player (androidx.media3.common.Player)5 MediaItem (androidx.media3.common.MediaItem)4 ExoPlaybackException (androidx.media3.exoplayer.ExoPlaybackException)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 Timeline (androidx.media3.common.Timeline)3 MediaControllerCompat (android.support.v4.media.session.MediaControllerCompat)2 PlaybackStateCompat (android.support.v4.media.session.PlaybackStateCompat)2 AudioAttributes (androidx.media3.common.AudioAttributes)2 DeviceInfo (androidx.media3.common.DeviceInfo)2 MediaMetadata (androidx.media3.common.MediaMetadata)2 PlaybackParameters (androidx.media3.common.PlaybackParameters)2 PositionInfo (androidx.media3.common.Player.PositionInfo)2 State (androidx.media3.common.Player.State)2