Search in sources :

Example 1 with TestExoPlayerBuilder

use of com.google.android.exoplayer2.testutil.TestExoPlayerBuilder in project ExoPlayer by google.

the class ExoPlayerTest method setRepeatMode_all_notifiesAvailableCommandsChanged.

@Test
public void setRepeatMode_all_notifiesAvailableCommandsChanged() {
    Player.Commands defaultCommands = createWithDefaultCommands();
    Player.Commands commandsWithSeekToPreviousAndNextWindow = createWithDefaultCommands(COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM, COMMAND_SEEK_TO_NEXT_MEDIA_ITEM, COMMAND_SEEK_TO_NEXT);
    Player.Listener mockListener = mock(Player.Listener.class);
    ExoPlayer player = new TestExoPlayerBuilder(context).build();
    player.addListener(mockListener);
    player.addMediaSource(new FakeMediaSource());
    verify(mockListener).onAvailableCommandsChanged(defaultCommands);
    // Check that there were no other calls to onAvailableCommandsChanged.
    verify(mockListener).onAvailableCommandsChanged(any());
    player.setRepeatMode(Player.REPEAT_MODE_ALL);
    verify(mockListener).onAvailableCommandsChanged(commandsWithSeekToPreviousAndNextWindow);
    verify(mockListener, times(2)).onAvailableCommandsChanged(any());
}
Also used : Listener(com.google.android.exoplayer2.Player.Listener) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) Test(org.junit.Test)

Example 2 with TestExoPlayerBuilder

use of com.google.android.exoplayer2.testutil.TestExoPlayerBuilder 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 3 with TestExoPlayerBuilder

use of com.google.android.exoplayer2.testutil.TestExoPlayerBuilder in project ExoPlayer by google.

the class ExoPlayerTest method playShortDurationPeriods.

/**
 * Tests playback of periods with very short duration.
 */
@Test
public void playShortDurationPeriods() throws Exception {
    // TimelineWindowDefinition.DEFAULT_WINDOW_DURATION_US / 100 = 1000 us per period.
    Timeline timeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
    100, /* id= */
    0));
    FakeRenderer renderer = new FakeRenderer(C.TRACK_TYPE_VIDEO);
    ExoPlayer player = new TestExoPlayerBuilder(context).setRenderers(renderer).build();
    Player.Listener mockPlayerListener = mock(Player.Listener.class);
    player.addListener(mockPlayerListener);
    player.setMediaSource(new FakeMediaSource(timeline, ExoPlayerTestRunner.VIDEO_FORMAT));
    player.prepare();
    player.play();
    runUntilPlaybackState(player, Player.STATE_ENDED);
    InOrder inOrder = inOrder(mockPlayerListener);
    inOrder.verify(mockPlayerListener).onTimelineChanged(argThat(noUid(placeholderTimeline)), eq(Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED));
    inOrder.verify(mockPlayerListener).onTimelineChanged(argThat(noUid(timeline)), eq(Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE));
    inOrder.verify(mockPlayerListener, times(99)).onPositionDiscontinuity(any(), any(), eq(Player.DISCONTINUITY_REASON_AUTO_TRANSITION));
    assertThat(renderer.getFormatsRead()).hasSize(100);
    assertThat(renderer.sampleBufferReadCount).isEqualTo(100);
    assertThat(renderer.isEnded).isTrue();
}
Also used : FakeRenderer(com.google.android.exoplayer2.testutil.FakeRenderer) 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) InOrder(org.mockito.InOrder) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) TimelineWindowDefinition(com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) Test(org.junit.Test)

Example 4 with TestExoPlayerBuilder

use of com.google.android.exoplayer2.testutil.TestExoPlayerBuilder in project ExoPlayer by google.

the class ExoPlayerTest method mediaSourceMaybeThrowSourceInfoRefreshError_isNotThrownUntilPlaybackReachedFailingItem.

@Test
public void mediaSourceMaybeThrowSourceInfoRefreshError_isNotThrownUntilPlaybackReachedFailingItem() throws Exception {
    ExoPlayer player = new TestExoPlayerBuilder(context).build();
    player.addMediaSource(new FakeMediaSource());
    player.addMediaSource(new FakeMediaSource(/* timeline= */
    null) {

        @Override
        public void maybeThrowSourceInfoRefreshError() throws IOException {
            throw new IOException();
        }
    });
    player.prepare();
    player.play();
    ExoPlaybackException error = TestPlayerRunHelper.runUntilError(player);
    Object period1Uid = player.getCurrentTimeline().getPeriod(/* periodIndex= */
    1, new Timeline.Period(), /* setIds= */
    true).uid;
    assertThat(error.mediaPeriodId.periodUid).isEqualTo(period1Uid);
    assertThat(player.getCurrentMediaItemIndex()).isEqualTo(1);
}
Also used : FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) MediaPeriod(com.google.android.exoplayer2.source.MediaPeriod) FakeMediaPeriod(com.google.android.exoplayer2.testutil.FakeMediaPeriod) IOException(java.io.IOException) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) Test(org.junit.Test)

Example 5 with TestExoPlayerBuilder

use of com.google.android.exoplayer2.testutil.TestExoPlayerBuilder in project ExoPlayer by google.

the class ExoPlayerTest method seekTo_sameWindow_doesNotNotifyMediaItemTransition.

@Test
public void seekTo_sameWindow_doesNotNotifyMediaItemTransition() throws Exception {
    List<MediaItem> reportedMediaItems = new ArrayList<>();
    List<Integer> reportedTransitionReasons = new ArrayList<>();
    MediaSource mediaSource1 = FakeMediaSource.createWithWindowId(/* windowId= */
    new Object());
    MediaSource mediaSource2 = FakeMediaSource.createWithWindowId(/* windowId= */
    new Object());
    ExoPlayer player = new TestExoPlayerBuilder(context).build();
    player.addListener(new Listener() {

        @Override
        public void onMediaItemTransition(@Nullable MediaItem mediaItem, int reason) {
            reportedMediaItems.add(mediaItem);
            reportedTransitionReasons.add(reason);
        }
    });
    player.setMediaSources(ImmutableList.of(mediaSource1, mediaSource2));
    player.prepare();
    runUntilPlaybackState(player, Player.STATE_READY);
    player.seekTo(/* mediaItemIndex= */
    0, /* positionMs= */
    2000);
    assertThat(reportedMediaItems).containsExactly(mediaSource1.getMediaItem()).inOrder();
    assertThat(reportedTransitionReasons).containsExactly(Player.MEDIA_ITEM_TRANSITION_REASON_PLAYLIST_CHANGED).inOrder();
    player.release();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TransferListener(com.google.android.exoplayer2.upstream.TransferListener) Listener(com.google.android.exoplayer2.Player.Listener) MediaSourceEventListener(com.google.android.exoplayer2.source.MediaSourceEventListener) AnalyticsListener(com.google.android.exoplayer2.analytics.AnalyticsListener) DrmSessionEventListener(com.google.android.exoplayer2.drm.DrmSessionEventListener) ServerSideAdInsertionMediaSource(com.google.android.exoplayer2.source.ads.ServerSideAdInsertionMediaSource) FakeAdaptiveMediaSource(com.google.android.exoplayer2.testutil.FakeAdaptiveMediaSource) MaskingMediaSource(com.google.android.exoplayer2.source.MaskingMediaSource) ConcatenatingMediaSource(com.google.android.exoplayer2.source.ConcatenatingMediaSource) MediaSource(com.google.android.exoplayer2.source.MediaSource) CompositeMediaSource(com.google.android.exoplayer2.source.CompositeMediaSource) ClippingMediaSource(com.google.android.exoplayer2.source.ClippingMediaSource) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) TestPlayerRunHelper.playUntilStartOfMediaItem(com.google.android.exoplayer2.robolectric.TestPlayerRunHelper.playUntilStartOfMediaItem) ArrayList(java.util.ArrayList) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) Test(org.junit.Test)

Aggregations

TestExoPlayerBuilder (com.google.android.exoplayer2.testutil.TestExoPlayerBuilder)115 Test (org.junit.Test)115 FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)101 Listener (com.google.android.exoplayer2.Player.Listener)74 FakeTimeline (com.google.android.exoplayer2.testutil.FakeTimeline)74 SinglePeriodTimeline (com.google.android.exoplayer2.source.SinglePeriodTimeline)61 NoUidTimeline (com.google.android.exoplayer2.testutil.NoUidTimeline)61 TimelineWindowDefinition (com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition)55 TestPlayerRunHelper.playUntilStartOfMediaItem (com.google.android.exoplayer2.robolectric.TestPlayerRunHelper.playUntilStartOfMediaItem)37 PositionInfo (com.google.android.exoplayer2.Player.PositionInfo)31 ConcatenatingMediaSource (com.google.android.exoplayer2.source.ConcatenatingMediaSource)30 InOrder (org.mockito.InOrder)30 TransferListener (com.google.android.exoplayer2.upstream.TransferListener)29 MediaSource (com.google.android.exoplayer2.source.MediaSource)28 FakeRenderer (com.google.android.exoplayer2.testutil.FakeRenderer)28 ArrayList (java.util.ArrayList)28 AnalyticsListener (com.google.android.exoplayer2.analytics.AnalyticsListener)27 ClippingMediaSource (com.google.android.exoplayer2.source.ClippingMediaSource)27 CompositeMediaSource (com.google.android.exoplayer2.source.CompositeMediaSource)27 MaskingMediaSource (com.google.android.exoplayer2.source.MaskingMediaSource)27