Search in sources :

Example 1 with FakeMediaSourceFactory

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();
}
Also used : Window(com.google.android.exoplayer2.Timeline.Window) InOrder(org.mockito.InOrder) Listener(com.google.android.exoplayer2.Player.Listener) NoUidTimeline(com.google.android.exoplayer2.testutil.NoUidTimeline) SinglePeriodTimeline(com.google.android.exoplayer2.source.SinglePeriodTimeline) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) TestPlayerRunHelper.playUntilStartOfMediaItem(com.google.android.exoplayer2.robolectric.TestPlayerRunHelper.playUntilStartOfMediaItem) FakeMediaSourceFactory(com.google.android.exoplayer2.testutil.FakeMediaSourceFactory) PositionInfo(com.google.android.exoplayer2.Player.PositionInfo) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) Test(org.junit.Test)

Example 2 with FakeMediaSourceFactory

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);
}
Also used : Window(com.google.android.exoplayer2.Timeline.Window) MediaSource(com.google.android.exoplayer2.source.MediaSource) MediaItem(com.google.android.exoplayer2.MediaItem) AtomicReference(java.util.concurrent.atomic.AtomicReference) Nullable(androidx.annotation.Nullable) Test(org.junit.Test)

Aggregations

Window (com.google.android.exoplayer2.Timeline.Window)2 Test (org.junit.Test)2 Nullable (androidx.annotation.Nullable)1 MediaItem (com.google.android.exoplayer2.MediaItem)1 Listener (com.google.android.exoplayer2.Player.Listener)1 PositionInfo (com.google.android.exoplayer2.Player.PositionInfo)1 TestPlayerRunHelper.playUntilStartOfMediaItem (com.google.android.exoplayer2.robolectric.TestPlayerRunHelper.playUntilStartOfMediaItem)1 MediaSource (com.google.android.exoplayer2.source.MediaSource)1 SinglePeriodTimeline (com.google.android.exoplayer2.source.SinglePeriodTimeline)1 FakeMediaSourceFactory (com.google.android.exoplayer2.testutil.FakeMediaSourceFactory)1 FakeTimeline (com.google.android.exoplayer2.testutil.FakeTimeline)1 NoUidTimeline (com.google.android.exoplayer2.testutil.NoUidTimeline)1 TestExoPlayerBuilder (com.google.android.exoplayer2.testutil.TestExoPlayerBuilder)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 InOrder (org.mockito.InOrder)1