Search in sources :

Example 86 with FakeMediaSource

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

the class ExoPlayerTest method seekBack_pastZero_seeksToZero.

@Test
public void seekBack_pastZero_seeksToZero() throws Exception {
    ExoPlayer player = new TestExoPlayerBuilder(context).build();
    Timeline fakeTimeline = new FakeTimeline(new TimelineWindowDefinition(/* isSeekable= */
    true, /* isDynamic= */
    true, /* durationUs= */
    Util.msToUs(C.DEFAULT_SEEK_BACK_INCREMENT_MS)));
    player.setMediaSource(new FakeMediaSource(fakeTimeline));
    player.prepare();
    TestPlayerRunHelper.playUntilPosition(player, /* mediaItemIndex= */
    0, /* positionMs= */
    C.DEFAULT_SEEK_BACK_INCREMENT_MS / 2);
    player.seekBack();
    assertThat(player.getCurrentPosition()).isEqualTo(0);
    player.release();
}
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) 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 87 with FakeMediaSource

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

the class ExoPlayerTest method setRepeatMode_one_doesNotNotifyAvailableCommandsChanged.

@Test
public void setRepeatMode_one_doesNotNotifyAvailableCommandsChanged() {
    Player.Commands defaultCommands = createWithDefaultCommands();
    Player.Listener mockListener = mock(Player.Listener.class);
    ExoPlayer player = new TestExoPlayerBuilder(context).build();
    player.addListener(mockListener);
    player.addMediaSource(new FakeMediaSource());
    verify(mockListener).onAvailableCommandsChanged(defaultCommands);
    player.setRepeatMode(Player.REPEAT_MODE_ONE);
    verify(mockListener).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 88 with FakeMediaSource

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

the class ExoPlayerTest method play_withPreMidAndPostRollAd_callsOnDiscontinuityCorrectly.

@Test
public void play_withPreMidAndPostRollAd_callsOnDiscontinuityCorrectly() throws Exception {
    ExoPlayer player = new TestExoPlayerBuilder(context).build();
    Player.Listener listener = mock(Player.Listener.class);
    player.addListener(listener);
    AdPlaybackState adPlaybackState = FakeTimeline.createAdPlaybackState(/* adsPerAdGroup= */
    2, /* adGroupTimesUs...= */
    0, 7 * C.MICROS_PER_SECOND, C.TIME_END_OF_SOURCE);
    TimelineWindowDefinition adTimeline = new TimelineWindowDefinition(/* periodCount= */
    1, /* id= */
    0, /* isSeekable= */
    true, /* isDynamic= */
    false, /* isLive= */
    false, /* isPlaceholder= */
    false, /* durationUs= */
    10 * C.MICROS_PER_SECOND, /* defaultPositionUs= */
    0, /* windowOffsetInFirstPeriodUs= */
    0, adPlaybackState);
    player.setMediaSource(new FakeMediaSource(new FakeTimeline(adTimeline)));
    player.prepare();
    player.play();
    TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_ENDED);
    ArgumentCaptor<Player.PositionInfo> oldPosition = ArgumentCaptor.forClass(Player.PositionInfo.class);
    ArgumentCaptor<Player.PositionInfo> newPosition = ArgumentCaptor.forClass(Player.PositionInfo.class);
    verify(listener, never()).onPositionDiscontinuity(any(), any(), not(eq(Player.DISCONTINUITY_REASON_AUTO_TRANSITION)));
    verify(listener, times(8)).onPositionDiscontinuity(oldPosition.capture(), newPosition.capture(), eq(Player.DISCONTINUITY_REASON_AUTO_TRANSITION));
    // first ad group (pre-roll)
    // starts with ad to ad transition
    List<Player.PositionInfo> oldPositions = oldPosition.getAllValues();
    List<Player.PositionInfo> newPositions = newPosition.getAllValues();
    assertThat(oldPositions.get(0).mediaItemIndex).isEqualTo(0);
    assertThat(oldPositions.get(0).positionMs).isEqualTo(5000);
    assertThat(oldPositions.get(0).contentPositionMs).isEqualTo(0);
    assertThat(oldPositions.get(0).adGroupIndex).isEqualTo(0);
    assertThat(oldPositions.get(0).adIndexInAdGroup).isEqualTo(0);
    assertThat(newPositions.get(0).mediaItemIndex).isEqualTo(0);
    assertThat(newPositions.get(0).positionMs).isEqualTo(0);
    assertThat(newPositions.get(0).contentPositionMs).isEqualTo(0);
    assertThat(newPositions.get(0).adGroupIndex).isEqualTo(0);
    assertThat(newPositions.get(0).adIndexInAdGroup).isEqualTo(1);
    // ad to content transition
    assertThat(oldPositions.get(1).mediaItemIndex).isEqualTo(0);
    assertThat(oldPositions.get(1).positionMs).isEqualTo(5000);
    assertThat(oldPositions.get(1).contentPositionMs).isEqualTo(0);
    assertThat(oldPositions.get(1).adGroupIndex).isEqualTo(0);
    assertThat(oldPositions.get(1).adIndexInAdGroup).isEqualTo(1);
    assertThat(newPositions.get(1).mediaItemIndex).isEqualTo(0);
    assertThat(newPositions.get(1).positionMs).isEqualTo(0);
    assertThat(newPositions.get(1).contentPositionMs).isEqualTo(0);
    assertThat(newPositions.get(1).adGroupIndex).isEqualTo(-1);
    assertThat(newPositions.get(1).adIndexInAdGroup).isEqualTo(-1);
    // second add group (mid-roll)
    assertThat(oldPositions.get(2).mediaItemIndex).isEqualTo(0);
    assertThat(oldPositions.get(2).positionMs).isEqualTo(7000);
    assertThat(oldPositions.get(2).contentPositionMs).isEqualTo(7000);
    assertThat(oldPositions.get(2).adGroupIndex).isEqualTo(-1);
    assertThat(oldPositions.get(2).adIndexInAdGroup).isEqualTo(-1);
    assertThat(newPositions.get(2).mediaItemIndex).isEqualTo(0);
    assertThat(newPositions.get(2).positionMs).isEqualTo(0);
    assertThat(newPositions.get(2).contentPositionMs).isEqualTo(7000);
    assertThat(newPositions.get(2).adGroupIndex).isEqualTo(1);
    assertThat(newPositions.get(2).adIndexInAdGroup).isEqualTo(0);
    // ad to ad transition
    assertThat(oldPositions.get(3).mediaItemIndex).isEqualTo(0);
    assertThat(oldPositions.get(3).positionMs).isEqualTo(5000);
    assertThat(oldPositions.get(3).contentPositionMs).isEqualTo(7000);
    assertThat(oldPositions.get(3).adGroupIndex).isEqualTo(1);
    assertThat(oldPositions.get(3).adIndexInAdGroup).isEqualTo(0);
    assertThat(newPositions.get(3).mediaItemIndex).isEqualTo(0);
    assertThat(newPositions.get(3).positionMs).isEqualTo(0);
    assertThat(newPositions.get(3).contentPositionMs).isEqualTo(7000);
    assertThat(newPositions.get(3).adGroupIndex).isEqualTo(1);
    assertThat(newPositions.get(3).adIndexInAdGroup).isEqualTo(1);
    // ad to content transition
    assertThat(oldPositions.get(4).mediaItemIndex).isEqualTo(0);
    assertThat(oldPositions.get(4).positionMs).isEqualTo(5000);
    assertThat(oldPositions.get(4).contentPositionMs).isEqualTo(7000);
    assertThat(oldPositions.get(4).adGroupIndex).isEqualTo(1);
    assertThat(oldPositions.get(4).adIndexInAdGroup).isEqualTo(1);
    assertThat(newPositions.get(4).mediaItemIndex).isEqualTo(0);
    assertThat(newPositions.get(4).positionMs).isEqualTo(7000);
    assertThat(newPositions.get(4).contentPositionMs).isEqualTo(7000);
    assertThat(newPositions.get(4).adGroupIndex).isEqualTo(-1);
    assertThat(newPositions.get(4).adIndexInAdGroup).isEqualTo(-1);
    // third add group (post-roll)
    assertThat(oldPositions.get(5).mediaItemIndex).isEqualTo(0);
    assertThat(oldPositions.get(5).positionMs).isEqualTo(10000);
    assertThat(oldPositions.get(5).contentPositionMs).isEqualTo(10000);
    assertThat(oldPositions.get(5).adGroupIndex).isEqualTo(-1);
    assertThat(oldPositions.get(5).adIndexInAdGroup).isEqualTo(-1);
    assertThat(newPositions.get(5).mediaItemIndex).isEqualTo(0);
    assertThat(newPositions.get(5).positionMs).isEqualTo(0);
    assertThat(newPositions.get(5).contentPositionMs).isEqualTo(10000);
    assertThat(newPositions.get(5).adGroupIndex).isEqualTo(2);
    assertThat(newPositions.get(5).adIndexInAdGroup).isEqualTo(0);
    // ad to ad transition
    assertThat(oldPositions.get(6).mediaItemIndex).isEqualTo(0);
    assertThat(oldPositions.get(6).positionMs).isEqualTo(5000);
    assertThat(oldPositions.get(6).contentPositionMs).isEqualTo(10000);
    assertThat(oldPositions.get(6).adGroupIndex).isEqualTo(2);
    assertThat(oldPositions.get(6).adIndexInAdGroup).isEqualTo(0);
    assertThat(newPositions.get(6).mediaItemIndex).isEqualTo(0);
    assertThat(newPositions.get(6).positionMs).isEqualTo(0);
    assertThat(newPositions.get(6).contentPositionMs).isEqualTo(10000);
    assertThat(newPositions.get(6).adGroupIndex).isEqualTo(2);
    assertThat(newPositions.get(6).adIndexInAdGroup).isEqualTo(1);
    // post roll ad to end of content transition
    assertThat(oldPositions.get(7).mediaItemIndex).isEqualTo(0);
    assertThat(oldPositions.get(7).positionMs).isEqualTo(5000);
    assertThat(oldPositions.get(7).contentPositionMs).isEqualTo(10000);
    assertThat(oldPositions.get(7).adGroupIndex).isEqualTo(2);
    assertThat(oldPositions.get(7).adIndexInAdGroup).isEqualTo(1);
    assertThat(newPositions.get(7).mediaItemIndex).isEqualTo(0);
    assertThat(newPositions.get(7).positionMs).isEqualTo(9999);
    assertThat(newPositions.get(7).contentPositionMs).isEqualTo(9999);
    assertThat(newPositions.get(7).adGroupIndex).isEqualTo(-1);
    assertThat(newPositions.get(7).adIndexInAdGroup).isEqualTo(-1);
    player.release();
}
Also used : Listener(com.google.android.exoplayer2.Player.Listener) 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) PositionInfo(com.google.android.exoplayer2.Player.PositionInfo) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) Test(org.junit.Test)

Example 89 with FakeMediaSource

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

the class ExoPlayerTest method sendMessagesNonLinearPeriodOrder.

@Test
public void sendMessagesNonLinearPeriodOrder() throws Exception {
    Timeline fakeTimeline = new FakeTimeline();
    MediaSource[] fakeMediaSources = { new FakeMediaSource(fakeTimeline, ExoPlayerTestRunner.VIDEO_FORMAT), new FakeMediaSource(fakeTimeline, ExoPlayerTestRunner.VIDEO_FORMAT), new FakeMediaSource(fakeTimeline, ExoPlayerTestRunner.VIDEO_FORMAT) };
    ConcatenatingMediaSource mediaSource = new ConcatenatingMediaSource(false, new FakeShuffleOrder(3), fakeMediaSources);
    PositionGrabbingMessageTarget target1 = new PositionGrabbingMessageTarget();
    PositionGrabbingMessageTarget target2 = new PositionGrabbingMessageTarget();
    PositionGrabbingMessageTarget target3 = new PositionGrabbingMessageTarget();
    ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().waitForPlaybackState(Player.STATE_READY).sendMessage(target1, /* mediaItemIndex = */
    0, /* positionMs= */
    50).sendMessage(target2, /* mediaItemIndex = */
    1, /* positionMs= */
    50).sendMessage(target3, /* mediaItemIndex = */
    2, /* positionMs= */
    50).setShuffleModeEnabled(true).seek(/* mediaItemIndex= */
    2, /* positionMs= */
    0).play().build();
    new ExoPlayerTestRunner.Builder(context).setMediaSources(mediaSource).setActionSchedule(actionSchedule).build().start().blockUntilEnded(TIMEOUT_MS);
    assertThat(target1.mediaItemIndex).isEqualTo(0);
    assertThat(target2.mediaItemIndex).isEqualTo(1);
    assertThat(target3.mediaItemIndex).isEqualTo(2);
}
Also used : NoUidTimeline(com.google.android.exoplayer2.testutil.NoUidTimeline) SinglePeriodTimeline(com.google.android.exoplayer2.source.SinglePeriodTimeline) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) 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) ActionSchedule(com.google.android.exoplayer2.testutil.ActionSchedule) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) ConcatenatingMediaSource(com.google.android.exoplayer2.source.ConcatenatingMediaSource) ExoPlayerTestRunner(com.google.android.exoplayer2.testutil.ExoPlayerTestRunner) FakeShuffleOrder(com.google.android.exoplayer2.testutil.FakeShuffleOrder) Test(org.junit.Test)

Example 90 with FakeMediaSource

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

the class ExoPlayerTest method targetLiveOffsetInMedia_afterAutomaticPeriodTransition_adjustsLiveOffsetToTargetOffset.

@Test
public void targetLiveOffsetInMedia_afterAutomaticPeriodTransition_adjustsLiveOffsetToTargetOffset() throws Exception {
    long windowStartUnixTimeMs = 987_654_321_000L;
    long nowUnixTimeMs = windowStartUnixTimeMs + 10_000;
    ExoPlayer player = new TestExoPlayerBuilder(context).setClock(new FakeClock(/* initialTimeMs= */
    nowUnixTimeMs, /* isAutoAdvancing= */
    true)).build();
    Timeline nonLiveTimeline = new FakeTimeline();
    Timeline liveTimeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
    1, /* id= */
    0, /* isSeekable= */
    true, /* isDynamic= */
    true, /* isLive= */
    true, /* isPlaceholder= */
    false, /* durationUs= */
    1000 * C.MICROS_PER_SECOND, /* defaultPositionUs= */
    8 * C.MICROS_PER_SECOND, /* windowOffsetInFirstPeriodUs= */
    Util.msToUs(windowStartUnixTimeMs), ImmutableList.of(AdPlaybackState.NONE), new MediaItem.Builder().setUri(Uri.EMPTY).setLiveConfiguration(new MediaItem.LiveConfiguration.Builder().setTargetOffsetMs(9_000).build()).build()));
    player.pause();
    player.addMediaSource(new FakeMediaSource(nonLiveTimeline));
    player.addMediaSource(new FakeMediaSource(liveTimeline));
    player.prepare();
    TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY);
    // Play until close to the end of the available live window.
    TestPlayerRunHelper.playUntilPosition(player, /* mediaItemIndex= */
    1, /* positionMs= */
    999_000);
    long liveOffsetAtEnd = player.getCurrentLiveOffset();
    player.release();
    // Assert that player adjusted live offset to the media value.
    assertThat(liveOffsetAtEnd).isIn(Range.closed(8_900L, 9_100L));
}
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) FakeClock(com.google.android.exoplayer2.testutil.FakeClock) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) TestPlayerRunHelper.playUntilStartOfMediaItem(com.google.android.exoplayer2.robolectric.TestPlayerRunHelper.playUntilStartOfMediaItem) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) TimelineWindowDefinition(com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition) 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