use of com.google.android.exoplayer2.testutil.FakeMediaSourceFactory in project ExoPlayer by google.
the class ExoPlayerTest method setMediaItems_callsListenersWithSameInstanceOfMediaItem.
@Test
public void setMediaItems_callsListenersWithSameInstanceOfMediaItem() throws Exception {
ArgumentCaptor<Timeline> timeline = ArgumentCaptor.forClass(Timeline.class);
ArgumentCaptor<Player.PositionInfo> oldPosition = ArgumentCaptor.forClass(Player.PositionInfo.class);
ArgumentCaptor<Player.PositionInfo> newPosition = ArgumentCaptor.forClass(Player.PositionInfo.class);
ArgumentCaptor<MediaItem> currentMediaItem = ArgumentCaptor.forClass(MediaItem.class);
Window window = new Timeline.Window();
ExoPlayer player = new TestExoPlayerBuilder(context).setMediaSourceFactory(new FakeMediaSourceFactory()).build();
Player.Listener listener = mock(Player.Listener.class);
player.addListener(listener);
List<MediaItem> playlist = ImmutableList.of(MediaItem.fromUri("http://item-0.com/"), MediaItem.fromUri("http://item-1.com/"));
player.setMediaItems(playlist);
player.prepare();
player.seekTo(/* positionMs= */
2000);
player.play();
TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_ENDED);
InOrder inOrder = inOrder(listener);
inOrder.verify(listener).onTimelineChanged(timeline.capture(), eq(Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED));
inOrder.verify(listener).onMediaItemTransition(currentMediaItem.capture(), eq(Player.MEDIA_ITEM_TRANSITION_REASON_PLAYLIST_CHANGED));
inOrder.verify(listener).onPositionDiscontinuity(oldPosition.capture(), newPosition.capture(), eq(Player.DISCONTINUITY_REASON_SEEK));
inOrder.verify(listener).onPositionDiscontinuity(oldPosition.capture(), newPosition.capture(), eq(Player.DISCONTINUITY_REASON_AUTO_TRANSITION));
inOrder.verify(listener).onMediaItemTransition(currentMediaItem.capture(), eq(Player.MEDIA_ITEM_TRANSITION_REASON_AUTO));
inOrder.verify(listener, never()).onPositionDiscontinuity(any(), any(), anyInt());
inOrder.verify(listener, never()).onMediaItemTransition(any(), anyInt());
assertThat(timeline.getValue().getWindow(0, window).mediaItem).isSameInstanceAs(playlist.get(0));
assertThat(timeline.getValue().getWindow(1, window).mediaItem).isSameInstanceAs(playlist.get(1));
assertThat(oldPosition.getAllValues().get(0).mediaItem).isSameInstanceAs(playlist.get(0));
assertThat(newPosition.getAllValues().get(0).mediaItem).isSameInstanceAs(playlist.get(0));
assertThat(oldPosition.getAllValues().get(1).mediaItem).isSameInstanceAs(playlist.get(0));
assertThat(newPosition.getAllValues().get(1).mediaItem).isSameInstanceAs(playlist.get(1));
assertThat(currentMediaItem.getAllValues().get(0)).isSameInstanceAs(playlist.get(0));
assertThat(currentMediaItem.getAllValues().get(1)).isSameInstanceAs(playlist.get(1));
player.release();
}
use of com.google.android.exoplayer2.testutil.FakeMediaSourceFactory in project ExoPlayer by google.
the class FakeMediaSourceFactoryTest method createMediaSource_mediaItemIsSameInstance.
@Test
public void createMediaSource_mediaItemIsSameInstance() {
FakeMediaSourceFactory fakeMediaSourceFactory = new FakeMediaSourceFactory();
MediaItem mediaItem = MediaItem.fromUri("http://google.com/0");
@Nullable AtomicReference<MediaItem> reportedMediaItem = new AtomicReference<>();
MediaSource mediaSource = fakeMediaSourceFactory.createMediaSource(mediaItem);
mediaSource.prepareSource((source, timeline) -> {
int firstWindowIndex = timeline.getFirstWindowIndex(/* shuffleModeEnabled= */
false);
reportedMediaItem.set(timeline.getWindow(firstWindowIndex, new Window()).mediaItem);
}, /* mediaTransferListener= */
null, PlayerId.UNSET);
assertThat(reportedMediaItem.get()).isSameInstanceAs(mediaItem);
assertThat(mediaSource.getMediaItem()).isSameInstanceAs(mediaItem);
}
Aggregations