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