use of androidx.media3.exoplayer.offline.DownloadHelper.Callback in project media by androidx.
the class MediaControllerCompatCallbackWithMediaSessionTest method setPlayer_playbackTypeNotChanged_remote.
@Test
public void setPlayer_playbackTypeNotChanged_remote() throws Exception {
DeviceInfo deviceInfo = new DeviceInfo(DeviceInfo.PLAYBACK_TYPE_REMOTE, /* minVolume= */
0, /* maxVolume= */
10);
Bundle playerConfig = new RemoteMediaSession.MockPlayerConfigBuilder().setDeviceInfo(deviceInfo).setDeviceVolume(1).build();
session.setPlayer(playerConfig);
DeviceInfo deviceInfoToUpdate = new DeviceInfo(DeviceInfo.PLAYBACK_TYPE_REMOTE, /* minVolume= */
0, /* maxVolume= */
25);
int legacyPlaybackTypeToUpdate = MediaControllerCompat.PlaybackInfo.PLAYBACK_TYPE_REMOTE;
int deviceVolumeToUpdate = 10;
CountDownLatch playbackInfoNotified = new CountDownLatch(1);
MediaControllerCompat.Callback callback = new MediaControllerCompat.Callback() {
@Override
public void onAudioInfoChanged(MediaControllerCompat.PlaybackInfo info) {
if (info.getPlaybackType() == legacyPlaybackTypeToUpdate && info.getMaxVolume() == deviceInfoToUpdate.maxVolume && info.getCurrentVolume() == deviceVolumeToUpdate) {
playbackInfoNotified.countDown();
}
}
};
controllerCompat.registerCallback(callback, handler);
Bundle playerConfigToUpdate = new RemoteMediaSession.MockPlayerConfigBuilder().setDeviceInfo(deviceInfoToUpdate).setDeviceVolume(deviceVolumeToUpdate).build();
session.setPlayer(playerConfigToUpdate);
// In API 21+, onAudioInfoChanged() is not called when playbackType is not changed.
if (Util.SDK_INT >= 21) {
PollingCheck.waitFor(TIMEOUT_MS, () -> {
MediaControllerCompat.PlaybackInfo info = controllerCompat.getPlaybackInfo();
return info.getPlaybackType() == legacyPlaybackTypeToUpdate && info.getMaxVolume() == deviceInfoToUpdate.maxVolume && info.getCurrentVolume() == deviceVolumeToUpdate;
});
} else {
assertThat(playbackInfoNotified.await(TIMEOUT_MS, MILLISECONDS)).isTrue();
MediaControllerCompat.PlaybackInfo info = controllerCompat.getPlaybackInfo();
assertThat(info.getPlaybackType()).isEqualTo(legacyPlaybackTypeToUpdate);
assertThat(info.getMaxVolume()).isEqualTo(deviceInfoToUpdate.maxVolume);
assertThat(info.getCurrentVolume()).isEqualTo(deviceVolumeToUpdate);
}
}
use of androidx.media3.exoplayer.offline.DownloadHelper.Callback 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.exoplayer.offline.DownloadHelper.Callback in project media by androidx.
the class MediaControllerCompatCallbackWithMediaSessionTest method onPlaybackParametersChanged_notifiesPlaybackStateCompatChanges.
@Test
public void onPlaybackParametersChanged_notifiesPlaybackStateCompatChanges() throws Exception {
PlaybackParameters playbackParameters = new PlaybackParameters(/* speed= */
1.5f);
AtomicReference<PlaybackStateCompat> playbackStateRef = new AtomicReference<>();
CountDownLatch latch = new CountDownLatch(1);
MediaControllerCompat.Callback callback = new MediaControllerCompat.Callback() {
@Override
public void onPlaybackStateChanged(PlaybackStateCompat state) {
playbackStateRef.set(state);
latch.countDown();
}
};
controllerCompat.registerCallback(callback, handler);
session.getMockPlayer().notifyPlaybackParametersChanged(playbackParameters);
assertThat(latch.await(TIMEOUT_MS, MILLISECONDS)).isTrue();
assertThat(playbackStateRef.get().getPlaybackSpeed()).isWithin(EPSILON).of(playbackParameters.speed);
assertThat(controllerCompat.getPlaybackState().getPlaybackSpeed()).isWithin(EPSILON).of(playbackParameters.speed);
}
use of androidx.media3.exoplayer.offline.DownloadHelper.Callback in project media by androidx.
the class MediaControllerCompatCallbackWithMediaSessionTest method setPlayer_isNotified.
@Test
public void setPlayer_isNotified() throws Exception {
@State int testState = STATE_READY;
boolean testPlayWhenReady = true;
long testDurationMs = 200;
long testCurrentPositionMs = 11;
long testBufferedPositionMs = 100;
PlaybackParameters playbackParameters = new PlaybackParameters(/* speed= */
1.5f);
int testItemIndex = 0;
List<MediaItem> testMediaItems = MediaTestUtils.createMediaItems(/* size= */
3);
testMediaItems.set(testItemIndex, new MediaItem.Builder().setMediaId(testMediaItems.get(testItemIndex).mediaId).setMediaMetadata(new MediaMetadata.Builder().setUserRating(new HeartRating(/* isHeart= */
true)).build()).build());
Timeline testTimeline = new PlaylistTimeline(testMediaItems);
String testPlaylistTitle = "testPlaylistTitle";
MediaMetadata testPlaylistMetadata = new MediaMetadata.Builder().setTitle(testPlaylistTitle).build();
boolean testShuffleModeEnabled = true;
@RepeatMode int testRepeatMode = Player.REPEAT_MODE_ONE;
AtomicReference<PlaybackStateCompat> playbackStateRef = new AtomicReference<>();
AtomicReference<MediaMetadataCompat> metadataRef = new AtomicReference<>();
AtomicReference<CharSequence> queueTitleRef = new AtomicReference<>();
AtomicInteger shuffleModeRef = new AtomicInteger();
AtomicInteger repeatModeRef = new AtomicInteger();
CountDownLatch latchForPlaybackState = new CountDownLatch(1);
CountDownLatch latchForMetadata = new CountDownLatch(1);
CountDownLatch latchForQueue = new CountDownLatch(2);
CountDownLatch latchForShuffleMode = new CountDownLatch(1);
CountDownLatch latchForRepeatMode = new CountDownLatch(1);
MediaControllerCompat.Callback callback = new MediaControllerCompat.Callback() {
@Override
public void onPlaybackStateChanged(PlaybackStateCompat state) {
playbackStateRef.set(state);
latchForPlaybackState.countDown();
}
@Override
public void onMetadataChanged(MediaMetadataCompat metadata) {
metadataRef.set(metadata);
latchForMetadata.countDown();
}
@Override
public void onQueueChanged(List<QueueItem> queue) {
latchForQueue.countDown();
}
@Override
public void onQueueTitleChanged(CharSequence title) {
queueTitleRef.set(title);
latchForQueue.countDown();
}
@Override
public void onRepeatModeChanged(int repeatMode) {
repeatModeRef.set(repeatMode);
latchForRepeatMode.countDown();
}
@Override
public void onShuffleModeChanged(int shuffleMode) {
shuffleModeRef.set(shuffleMode);
latchForShuffleMode.countDown();
}
};
controllerCompat.registerCallback(callback, handler);
Bundle playerConfig = new RemoteMediaSession.MockPlayerConfigBuilder().setPlaybackState(testState).setPlayWhenReady(testPlayWhenReady).setCurrentPosition(testCurrentPositionMs).setBufferedPosition(testBufferedPositionMs).setDuration(testDurationMs).setPlaybackParameters(playbackParameters).setTimeline(testTimeline).setPlaylistMetadata(testPlaylistMetadata).setCurrentMediaItemIndex(testItemIndex).setShuffleModeEnabled(testShuffleModeEnabled).setRepeatMode(testRepeatMode).build();
session.setPlayer(playerConfig);
assertThat(latchForPlaybackState.await(TIMEOUT_MS, MILLISECONDS)).isTrue();
assertThat(playbackStateRef.get().getBufferedPosition()).isEqualTo(testBufferedPositionMs);
assertThat(playbackStateRef.get().getPosition()).isEqualTo(testCurrentPositionMs);
assertThat(playbackStateRef.get().getPlaybackSpeed()).isWithin(EPSILON).of(playbackParameters.speed);
assertThat(latchForMetadata.await(TIMEOUT_MS, MILLISECONDS)).isTrue();
assertThat(metadataRef.get().getString(METADATA_KEY_MEDIA_ID)).isEqualTo(testMediaItems.get(testItemIndex).mediaId);
assertThat(metadataRef.get().getLong(METADATA_KEY_DURATION)).isEqualTo(testDurationMs);
@PlaybackStateCompat.State int playbackStateFromControllerCompat = MediaUtils.convertToPlaybackState(playbackStateRef.get(), metadataRef.get(), /* timeDiffMs= */
C.TIME_UNSET);
assertThat(playbackStateFromControllerCompat).isEqualTo(testState);
assertThat(metadataRef.get().getRating(METADATA_KEY_USER_RATING).hasHeart()).isTrue();
assertThat(latchForQueue.await(TIMEOUT_MS, MILLISECONDS)).isTrue();
List<QueueItem> queue = controllerCompat.getQueue();
assertThat(queue).hasSize(testTimeline.getWindowCount());
for (int i = 0; i < testTimeline.getWindowCount(); i++) {
assertThat(queue.get(i).getDescription().getMediaId()).isEqualTo(testMediaItems.get(i).mediaId);
}
assertThat(queueTitleRef.get().toString()).isEqualTo(testPlaylistTitle);
assertThat(latchForShuffleMode.await(TIMEOUT_MS, TimeUnit.MILLISECONDS)).isTrue();
assertThat(shuffleModeRef.get()).isEqualTo(PlaybackStateCompat.SHUFFLE_MODE_ALL);
assertThat(latchForRepeatMode.await(TIMEOUT_MS, TimeUnit.MILLISECONDS)).isTrue();
assertThat(repeatModeRef.get()).isEqualTo(PlaybackStateCompat.REPEAT_MODE_ONE);
}
use of androidx.media3.exoplayer.offline.DownloadHelper.Callback in project media by androidx.
the class MediaControllerCompatCallbackWithMediaSessionTest method playlistMetadataChange.
@Test
public void playlistMetadataChange() throws Exception {
AtomicReference<CharSequence> queueTitleRef = new AtomicReference<>();
CountDownLatch latch = new CountDownLatch(1);
MediaControllerCompat.Callback callback = new MediaControllerCompat.Callback() {
@Override
public void onQueueTitleChanged(CharSequence title) {
queueTitleRef.set(title);
latch.countDown();
}
};
controllerCompat.registerCallback(callback, handler);
String playlistTitle = "playlistTitle";
MediaMetadata playlistMetadata = new MediaMetadata.Builder().setTitle(playlistTitle).build();
session.getMockPlayer().setPlaylistMetadata(playlistMetadata);
session.getMockPlayer().notifyPlaylistMetadataChanged();
assertThat(latch.await(TIMEOUT_MS, MILLISECONDS)).isTrue();
assertThat(queueTitleRef.get().toString()).isEqualTo(playlistTitle);
}
Aggregations