Search in sources :

Example 16 with FakeMediaSource

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

the class ExoPlayerTest method adInMovingLiveWindow_keepsContentPosition.

@Test
public void adInMovingLiveWindow_keepsContentPosition() throws Exception {
    ExoPlayer player = new TestExoPlayerBuilder(context).build();
    AdPlaybackState adPlaybackState = FakeTimeline.createAdPlaybackState(/* adsPerAdGroup= */
    1, /* adGroupTimesUs...= */
    42_000_004_000_000L);
    Timeline liveTimeline1 = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
    1, /* id= */
    0, /* isSeekable= */
    true, /* isDynamic= */
    true, /* isLive= */
    true, /* isPlaceholder= */
    false, /* durationUs= */
    10_000_000, /* defaultPositionUs= */
    3_000_000, /* windowOffsetInFirstPeriodUs= */
    42_000_000_000_000L, adPlaybackState));
    Timeline liveTimeline2 = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
    1, /* id= */
    0, /* isSeekable= */
    true, /* isDynamic= */
    true, /* isLive= */
    true, /* isPlaceholder= */
    false, /* durationUs= */
    10_000_000, /* defaultPositionUs= */
    3_000_000, /* windowOffsetInFirstPeriodUs= */
    42_000_002_000_000L, adPlaybackState));
    FakeMediaSource fakeMediaSource = new FakeMediaSource(liveTimeline1);
    player.setMediaSource(fakeMediaSource);
    player.prepare();
    player.play();
    // Wait until the ad is playing.
    runUntilPositionDiscontinuity(player, Player.DISCONTINUITY_REASON_AUTO_TRANSITION);
    long contentPositionBeforeLiveWindowUpdateMs = player.getContentPosition();
    fakeMediaSource.setNewSourceInfo(liveTimeline2);
    runUntilTimelineChanged(player);
    long contentPositionAfterLiveWindowUpdateMs = player.getContentPosition();
    player.release();
    assertThat(contentPositionBeforeLiveWindowUpdateMs).isEqualTo(4000);
    assertThat(contentPositionAfterLiveWindowUpdateMs).isEqualTo(2000);
}
Also used : NoUidTimeline(com.google.android.exoplayer2.testutil.NoUidTimeline) SinglePeriodTimeline(com.google.android.exoplayer2.source.SinglePeriodTimeline) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) AdPlaybackState(com.google.android.exoplayer2.source.ads.AdPlaybackState) ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState(com.google.android.exoplayer2.source.ads.ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState) 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 17 with FakeMediaSource

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

the class ExoPlayerTest method seekTo_cancelsSourceDiscontinuity_callsOnPositionDiscontinuity.

@Test
public void seekTo_cancelsSourceDiscontinuity_callsOnPositionDiscontinuity() throws Exception {
    Timeline timeline1 = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
    1, /* id= */
    1), new TimelineWindowDefinition(/* periodCount= */
    1, /* id= */
    2));
    final Timeline timeline2 = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
    1, /* id= */
    1), new TimelineWindowDefinition(/* periodCount= */
    1, /* id= */
    3));
    final FakeMediaSource mediaSource = new FakeMediaSource(timeline1, ExoPlayerTestRunner.VIDEO_FORMAT);
    ExoPlayer player = new TestExoPlayerBuilder(context).build();
    Player.Listener listener = mock(Player.Listener.class);
    player.addListener(listener);
    player.setMediaSource(mediaSource);
    player.prepare();
    TestPlayerRunHelper.playUntilPosition(player, /* mediaItemIndex= */
    1, /* positionMs= */
    2000);
    player.seekTo(/* mediaItemIndex= */
    1, /* positionMs= */
    2122);
    // This causes a DISCONTINUITY_REASON_REMOVE between pending operations that needs to be
    // cancelled by the seek below.
    mediaSource.setNewSourceInfo(timeline2);
    player.play();
    player.seekTo(/* mediaItemIndex= */
    0, /* positionMs= */
    2222);
    TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_ENDED);
    ArgumentCaptor<Player.PositionInfo> oldPosition = ArgumentCaptor.forClass(Player.PositionInfo.class);
    ArgumentCaptor<Player.PositionInfo> newPosition = ArgumentCaptor.forClass(Player.PositionInfo.class);
    InOrder inOrder = inOrder(listener);
    inOrder.verify(listener).onPositionDiscontinuity(any(), any(), eq(Player.DISCONTINUITY_REASON_AUTO_TRANSITION));
    inOrder.verify(listener, times(2)).onPositionDiscontinuity(oldPosition.capture(), newPosition.capture(), eq(Player.DISCONTINUITY_REASON_SEEK));
    inOrder.verify(listener).onPositionDiscontinuity(any(), any(), eq(Player.DISCONTINUITY_REASON_AUTO_TRANSITION));
    inOrder.verify(listener, never()).onPositionDiscontinuity(any(), any(), anyInt());
    List<Player.PositionInfo> oldPositions = oldPosition.getAllValues();
    List<Player.PositionInfo> newPositions = newPosition.getAllValues();
    // First seek
    assertThat(oldPositions.get(0).mediaItemIndex).isEqualTo(1);
    assertThat(oldPositions.get(0).positionMs).isIn(Range.closed(1980L, 2000L));
    assertThat(oldPositions.get(0).contentPositionMs).isIn(Range.closed(1980L, 2000L));
    assertThat(newPositions.get(0).mediaItemIndex).isEqualTo(1);
    assertThat(newPositions.get(0).positionMs).isEqualTo(2122);
    assertThat(newPositions.get(0).contentPositionMs).isEqualTo(2122);
    // Second seek.
    assertThat(oldPositions.get(1).mediaItemIndex).isEqualTo(1);
    assertThat(oldPositions.get(1).positionMs).isEqualTo(2122);
    assertThat(oldPositions.get(1).contentPositionMs).isEqualTo(2122);
    assertThat(newPositions.get(1).mediaItemIndex).isEqualTo(0);
    assertThat(newPositions.get(1).positionMs).isEqualTo(2222);
    assertThat(newPositions.get(1).contentPositionMs).isEqualTo(2222);
    player.release();
}
Also used : 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) PositionInfo(com.google.android.exoplayer2.Player.PositionInfo) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) Test(org.junit.Test)

Example 18 with FakeMediaSource

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

the class ExoPlayerTest method seekTo_whilePlayingAd_doesntBlockFutureUpdates.

// https://github.com/google/ExoPlayer/issues/8349
@Test
public void seekTo_whilePlayingAd_doesntBlockFutureUpdates() throws Exception {
    long contentDurationMs = 10_000;
    long adDurationMs = 4_000;
    AdPlaybackState adPlaybackState = new AdPlaybackState(/* adsId= */
    new Object(), /* adGroupTimesUs...= */
    0).withAdCount(/* adGroupIndex= */
    0, /* adCount= */
    1).withAdUri(/* adGroupIndex= */
    0, /* adIndexInAdGroup= */
    0, Uri.EMPTY);
    long[][] durationsUs = new long[1][];
    durationsUs[0] = new long[] { Util.msToUs(adDurationMs) };
    adPlaybackState = adPlaybackState.withAdDurationsUs(durationsUs);
    Timeline adTimeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
    1, /* id= */
    0, /* isSeekable= */
    true, /* isDynamic= */
    false, /* durationUs= */
    Util.msToUs(contentDurationMs), adPlaybackState));
    FakeMediaSource adsMediaSource = new FakeMediaSource(adTimeline);
    ExoPlayer player = new TestExoPlayerBuilder(context).build();
    player.setMediaSource(adsMediaSource);
    player.pause();
    player.prepare();
    runUntilPlaybackState(player, Player.STATE_READY);
    player.seekTo(0, 8000);
    player.play();
    // This times out if playback info updates after the seek are blocked.
    runUntilPlaybackState(player, Player.STATE_ENDED);
}
Also used : NoUidTimeline(com.google.android.exoplayer2.testutil.NoUidTimeline) SinglePeriodTimeline(com.google.android.exoplayer2.source.SinglePeriodTimeline) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) AdPlaybackState(com.google.android.exoplayer2.source.ads.AdPlaybackState) ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState(com.google.android.exoplayer2.source.ads.ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState) 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 19 with FakeMediaSource

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

the class ExoPlayerTest method repeatModeChanges.

@Test
public void repeatModeChanges() throws Exception {
    Timeline timeline = new FakeTimeline(/* windowCount= */
    3);
    FakeRenderer renderer = new FakeRenderer(C.TRACK_TYPE_VIDEO);
    ExoPlayer player = new TestExoPlayerBuilder(context).setRenderers(renderer).build();
    AnalyticsListener mockAnalyticsListener = mock(AnalyticsListener.class);
    player.addAnalyticsListener(mockAnalyticsListener);
    player.setMediaSource(new FakeMediaSource(timeline, ExoPlayerTestRunner.VIDEO_FORMAT));
    player.prepare();
    runUntilTimelineChanged(player);
    playUntilStartOfMediaItem(player, /* mediaItemIndex= */
    1);
    player.setRepeatMode(Player.REPEAT_MODE_ONE);
    playUntilStartOfMediaItem(player, /* mediaItemIndex= */
    1);
    player.setRepeatMode(Player.REPEAT_MODE_OFF);
    playUntilStartOfMediaItem(player, /* mediaItemIndex= */
    2);
    player.setRepeatMode(Player.REPEAT_MODE_ONE);
    playUntilStartOfMediaItem(player, /* mediaItemIndex= */
    2);
    player.setRepeatMode(Player.REPEAT_MODE_ALL);
    playUntilStartOfMediaItem(player, /* mediaItemIndex= */
    0);
    player.setRepeatMode(Player.REPEAT_MODE_ONE);
    playUntilStartOfMediaItem(player, /* mediaItemIndex= */
    0);
    playUntilStartOfMediaItem(player, /* mediaItemIndex= */
    0);
    player.setRepeatMode(Player.REPEAT_MODE_OFF);
    playUntilStartOfMediaItem(player, /* mediaItemIndex= */
    1);
    playUntilStartOfMediaItem(player, /* mediaItemIndex= */
    2);
    player.play();
    runUntilPlaybackState(player, Player.STATE_ENDED);
    ArgumentCaptor<AnalyticsListener.EventTime> eventTimes = ArgumentCaptor.forClass(AnalyticsListener.EventTime.class);
    verify(mockAnalyticsListener, times(10)).onMediaItemTransition(eventTimes.capture(), any(), anyInt());
    assertThat(eventTimes.getAllValues().stream().map(eventTime -> eventTime.currentWindowIndex).collect(Collectors.toList())).containsExactly(0, 1, 1, 2, 2, 0, 0, 0, 1, 2).inOrder();
    assertThat(renderer.isEnded).isTrue();
}
Also used : FakeRenderer(com.google.android.exoplayer2.testutil.FakeRenderer) NoUidTimeline(com.google.android.exoplayer2.testutil.NoUidTimeline) SinglePeriodTimeline(com.google.android.exoplayer2.source.SinglePeriodTimeline) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) AnalyticsListener(com.google.android.exoplayer2.analytics.AnalyticsListener) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) Test(org.junit.Test)

Example 20 with FakeMediaSource

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

the class ExoPlayerTest method setShuffleModeEnabled_notifiesAvailableCommandsChanged.

@Test
public void setShuffleModeEnabled_notifiesAvailableCommandsChanged() {
    Player.Commands commandsWithSeekToPreviousWindow = createWithDefaultCommands(COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM);
    Player.Commands commandsWithSeekToNextWindow = createWithDefaultCommands(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);
    MediaSource mediaSource = new ConcatenatingMediaSource(false, new FakeShuffleOrder(/* length= */
    2), new FakeMediaSource(), new FakeMediaSource());
    player.addMediaSource(mediaSource);
    verify(mockListener).onAvailableCommandsChanged(commandsWithSeekToNextWindow);
    // Check that there were no other calls to onAvailableCommandsChanged.
    verify(mockListener).onAvailableCommandsChanged(any());
    player.setShuffleModeEnabled(true);
    verify(mockListener).onAvailableCommandsChanged(commandsWithSeekToPreviousWindow);
    verify(mockListener, times(2)).onAvailableCommandsChanged(any());
}
Also used : Listener(com.google.android.exoplayer2.Player.Listener) 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) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) ConcatenatingMediaSource(com.google.android.exoplayer2.source.ConcatenatingMediaSource) FakeShuffleOrder(com.google.android.exoplayer2.testutil.FakeShuffleOrder) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) Test(org.junit.Test)

Aggregations

FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)262 Test (org.junit.Test)252 FakeTimeline (com.google.android.exoplayer2.testutil.FakeTimeline)177 TestExoPlayerBuilder (com.google.android.exoplayer2.testutil.TestExoPlayerBuilder)169 ActionSchedule (com.google.android.exoplayer2.testutil.ActionSchedule)113 SinglePeriodTimeline (com.google.android.exoplayer2.source.SinglePeriodTimeline)111 NoUidTimeline (com.google.android.exoplayer2.testutil.NoUidTimeline)109 PlayerRunnable (com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable)94 TimelineWindowDefinition (com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition)93 ExoPlayerTestRunner (com.google.android.exoplayer2.testutil.ExoPlayerTestRunner)89 ConcatenatingMediaSource (com.google.android.exoplayer2.source.ConcatenatingMediaSource)84 MediaSource (com.google.android.exoplayer2.source.MediaSource)76 Listener (com.google.android.exoplayer2.Player.Listener)64 ServerSideAdInsertionMediaSource (com.google.android.exoplayer2.source.ads.ServerSideAdInsertionMediaSource)53 ClippingMediaSource (com.google.android.exoplayer2.source.ClippingMediaSource)52 CompositeMediaSource (com.google.android.exoplayer2.source.CompositeMediaSource)52 MaskingMediaSource (com.google.android.exoplayer2.source.MaskingMediaSource)52 FakeAdaptiveMediaSource (com.google.android.exoplayer2.testutil.FakeAdaptiveMediaSource)52 MediaPeriodId (com.google.android.exoplayer2.source.MediaSource.MediaPeriodId)45 AdPlaybackState (com.google.android.exoplayer2.source.ads.AdPlaybackState)44