Search in sources :

Example 6 with COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM

use of com.google.android.exoplayer2.Player.COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM in project ExoPlayer by google.

the class ExoPlayerTest method addMediaSource_atTheStart_notifiesAvailableCommandsChanged.

@Test
public void addMediaSource_atTheStart_notifiesAvailableCommandsChanged() {
    Player.Commands defaultCommands = createWithDefaultCommands();
    Player.Commands commandsWithSeekToPreviousWindow = createWithDefaultCommands(COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM);
    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.addMediaSource(/* index= */
    0, new FakeMediaSource());
    verify(mockListener).onAvailableCommandsChanged(commandsWithSeekToPreviousWindow);
    verify(mockListener, times(2)).onAvailableCommandsChanged(any());
    player.addMediaSource(/* index= */
    0, new FakeMediaSource());
    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 7 with COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM

use of com.google.android.exoplayer2.Player.COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM in project ExoPlayer by google.

the class ExoPlayerTest method isCommandAvailable_duringAd_isFalseForSeekCommands.

@Test
public void isCommandAvailable_duringAd_isFalseForSeekCommands() throws Exception {
    AdPlaybackState adPlaybackState = new AdPlaybackState(/* adsId= */
    new Object(), /* adGroupTimesUs...= */
    0).withAdCount(/* adGroupIndex= */
    0, /* adCount= */
    1).withAdUri(/* adGroupIndex= */
    0, /* adIndexInAdGroup= */
    0, Uri.EMPTY).withAdDurationsUs(/* adDurationUs= */
    new long[][] { { Util.msToUs(4_000) } });
    Timeline adTimeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
    1, /* id= */
    0, /* isSeekable= */
    true, /* isDynamic= */
    false, /* durationUs= */
    Util.msToUs(10_000), adPlaybackState));
    ExoPlayer player = new TestExoPlayerBuilder(context).build();
    player.addMediaSources(ImmutableList.of(new FakeMediaSource(), new FakeMediaSource(adTimeline), new FakeMediaSource()));
    player.seekTo(/* mediaItemIndex= */
    1, /* positionMs= */
    0);
    player.prepare();
    runUntilPlaybackState(player, Player.STATE_READY);
    assertThat(player.isCommandAvailable(COMMAND_SEEK_IN_CURRENT_MEDIA_ITEM)).isFalse();
    assertThat(player.isCommandAvailable(COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM)).isFalse();
    assertThat(player.isCommandAvailable(COMMAND_SEEK_TO_PREVIOUS)).isFalse();
    assertThat(player.isCommandAvailable(COMMAND_SEEK_TO_NEXT_MEDIA_ITEM)).isFalse();
    assertThat(player.isCommandAvailable(COMMAND_SEEK_TO_NEXT)).isFalse();
    assertThat(player.isCommandAvailable(COMMAND_SEEK_TO_MEDIA_ITEM)).isFalse();
    assertThat(player.isCommandAvailable(COMMAND_SEEK_BACK)).isFalse();
    assertThat(player.isCommandAvailable(COMMAND_SEEK_FORWARD)).isFalse();
}
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 8 with COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM

use of com.google.android.exoplayer2.Player.COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM in project ExoPlayer by google.

the class CastPlayerTest method removeMediaItem_atTheStart_notifiesAvailableCommandsChanged.

@Test
public void removeMediaItem_atTheStart_notifiesAvailableCommandsChanged() {
    when(mockRemoteMediaClient.queueJumpToItem(anyInt(), anyLong(), eq(null))).thenReturn(mockPendingResult);
    Player.Commands defaultCommands = createWithDefaultCommands();
    Player.Commands commandsWithSeekToPreviousWindow = createWithDefaultCommands(COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM);
    Player.Commands emptyTimelineCommands = createWithDefaultCommands(/* isTimelineEmpty= */
    true);
    MediaItem mediaItem1 = createMediaItem(/* mediaQueueItemId= */
    1);
    MediaItem mediaItem2 = createMediaItem(/* mediaQueueItemId= */
    2);
    MediaItem mediaItem3 = createMediaItem(/* mediaQueueItemId= */
    3);
    castPlayer.addMediaItems(ImmutableList.of(mediaItem1, mediaItem2, mediaItem3));
    updateTimeLine(ImmutableList.of(mediaItem1, mediaItem2, mediaItem3), /* mediaQueueItemIds= */
    new int[] { 1, 2, 3 }, /* currentItemId= */
    3);
    verify(mockListener).onAvailableCommandsChanged(commandsWithSeekToPreviousWindow);
    // Check that there were no other calls to onAvailableCommandsChanged.
    verify(mockListener).onAvailableCommandsChanged(any());
    castPlayer.removeMediaItem(/* index= */
    0);
    updateTimeLine(ImmutableList.of(mediaItem2, mediaItem3), /* mediaQueueItemIds= */
    new int[] { 2, 3 }, /* currentItemId= */
    3);
    verify(mockListener).onAvailableCommandsChanged(any());
    castPlayer.removeMediaItem(/* index= */
    0);
    updateTimeLine(ImmutableList.of(mediaItem3), /* mediaQueueItemIds= */
    new int[] { 3 }, /* currentItemId= */
    3);
    verify(mockListener).onAvailableCommandsChanged(defaultCommands);
    verify(mockListener, times(2)).onAvailableCommandsChanged(any());
    castPlayer.removeMediaItem(/* index= */
    0);
    updateTimeLine(ImmutableList.of(), /* mediaQueueItemIds= */
    new int[0], /* currentItemId= */
    C.INDEX_UNSET);
    verify(mockListener).onAvailableCommandsChanged(emptyTimelineCommands);
    verify(mockListener, times(3)).onAvailableCommandsChanged(any());
}
Also used : Player(com.google.android.exoplayer2.Player) MediaItem(com.google.android.exoplayer2.MediaItem) Test(org.junit.Test)

Example 9 with COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM

use of com.google.android.exoplayer2.Player.COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM in project ExoPlayer by google.

the class CastPlayerTest method addMediaItem_atTheStart_notifiesAvailableCommandsChanged.

@Test
public void addMediaItem_atTheStart_notifiesAvailableCommandsChanged() {
    Player.Commands defaultCommands = createWithDefaultCommands();
    Player.Commands commandsWithSeekToPreviousWindow = createWithDefaultCommands(COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM);
    MediaItem mediaItem1 = createMediaItem(/* mediaQueueItemId= */
    1);
    MediaItem mediaItem2 = createMediaItem(/* mediaQueueItemId= */
    2);
    MediaItem mediaItem3 = createMediaItem(/* mediaQueueItemId= */
    3);
    castPlayer.addMediaItem(mediaItem1);
    updateTimeLine(ImmutableList.of(mediaItem1), /* mediaQueueItemIds= */
    new int[] { 1 }, /* currentItemId= */
    1);
    verify(mockListener).onAvailableCommandsChanged(defaultCommands);
    // Check that there were no other calls to onAvailableCommandsChanged.
    verify(mockListener).onAvailableCommandsChanged(any());
    castPlayer.addMediaItem(/* index= */
    0, mediaItem2);
    updateTimeLine(ImmutableList.of(mediaItem2, mediaItem1), /* mediaQueueItemIds= */
    new int[] { 2, 1 }, /* currentItemId= */
    1);
    verify(mockListener).onAvailableCommandsChanged(commandsWithSeekToPreviousWindow);
    verify(mockListener, times(2)).onAvailableCommandsChanged(any());
    castPlayer.addMediaItem(/* index= */
    0, mediaItem3);
    updateTimeLine(ImmutableList.of(mediaItem3, mediaItem2, mediaItem1), /* mediaQueueItemIds= */
    new int[] { 3, 2, 1 }, /* currentItemId= */
    1);
    verify(mockListener, times(2)).onAvailableCommandsChanged(any());
}
Also used : Player(com.google.android.exoplayer2.Player) MediaItem(com.google.android.exoplayer2.MediaItem) Test(org.junit.Test)

Example 10 with COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM

use of com.google.android.exoplayer2.Player.COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM in project ExoPlayer by google.

the class ExoPlayerTest method isCommandAvailable_isTrueForAvailableCommands.

@Test
public void isCommandAvailable_isTrueForAvailableCommands() {
    ExoPlayer player = new TestExoPlayerBuilder(context).build();
    player.addMediaSources(ImmutableList.of(new FakeMediaSource(), new FakeMediaSource()));
    assertThat(player.isCommandAvailable(COMMAND_PLAY_PAUSE)).isTrue();
    assertThat(player.isCommandAvailable(COMMAND_PREPARE)).isTrue();
    assertThat(player.isCommandAvailable(COMMAND_STOP)).isTrue();
    assertThat(player.isCommandAvailable(COMMAND_SEEK_TO_DEFAULT_POSITION)).isTrue();
    assertThat(player.isCommandAvailable(COMMAND_SEEK_IN_CURRENT_MEDIA_ITEM)).isFalse();
    assertThat(player.isCommandAvailable(COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM)).isFalse();
    assertThat(player.isCommandAvailable(COMMAND_SEEK_TO_PREVIOUS)).isTrue();
    assertThat(player.isCommandAvailable(COMMAND_SEEK_TO_NEXT_MEDIA_ITEM)).isTrue();
    assertThat(player.isCommandAvailable(COMMAND_SEEK_TO_NEXT)).isTrue();
    assertThat(player.isCommandAvailable(COMMAND_SEEK_TO_MEDIA_ITEM)).isTrue();
    assertThat(player.isCommandAvailable(COMMAND_SEEK_BACK)).isFalse();
    assertThat(player.isCommandAvailable(COMMAND_SEEK_FORWARD)).isFalse();
    assertThat(player.isCommandAvailable(COMMAND_SET_SPEED_AND_PITCH)).isTrue();
    assertThat(player.isCommandAvailable(COMMAND_SET_SHUFFLE_MODE)).isTrue();
    assertThat(player.isCommandAvailable(COMMAND_SET_REPEAT_MODE)).isTrue();
    assertThat(player.isCommandAvailable(COMMAND_GET_CURRENT_MEDIA_ITEM)).isTrue();
    assertThat(player.isCommandAvailable(COMMAND_GET_TIMELINE)).isTrue();
    assertThat(player.isCommandAvailable(COMMAND_GET_MEDIA_ITEMS_METADATA)).isTrue();
    assertThat(player.isCommandAvailable(COMMAND_SET_MEDIA_ITEMS_METADATA)).isTrue();
    assertThat(player.isCommandAvailable(COMMAND_CHANGE_MEDIA_ITEMS)).isTrue();
    assertThat(player.isCommandAvailable(COMMAND_GET_AUDIO_ATTRIBUTES)).isTrue();
    assertThat(player.isCommandAvailable(COMMAND_GET_VOLUME)).isTrue();
    assertThat(player.isCommandAvailable(COMMAND_GET_DEVICE_VOLUME)).isTrue();
    assertThat(player.isCommandAvailable(COMMAND_SET_VOLUME)).isTrue();
    assertThat(player.isCommandAvailable(COMMAND_SET_DEVICE_VOLUME)).isTrue();
    assertThat(player.isCommandAvailable(COMMAND_ADJUST_DEVICE_VOLUME)).isTrue();
    assertThat(player.isCommandAvailable(COMMAND_SET_VIDEO_SURFACE)).isTrue();
    assertThat(player.isCommandAvailable(COMMAND_GET_TEXT)).isTrue();
    assertThat(player.isCommandAvailable(COMMAND_SET_TRACK_SELECTION_PARAMETERS)).isTrue();
    assertThat(player.isCommandAvailable(COMMAND_GET_TRACK_INFOS)).isTrue();
}
Also used : FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)11 FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)9 TestExoPlayerBuilder (com.google.android.exoplayer2.testutil.TestExoPlayerBuilder)9 Listener (com.google.android.exoplayer2.Player.Listener)7 MediaItem (com.google.android.exoplayer2.MediaItem)2 Player (com.google.android.exoplayer2.Player)2 Timeline (com.google.android.exoplayer2.Timeline)1 ClippingMediaSource (com.google.android.exoplayer2.source.ClippingMediaSource)1 CompositeMediaSource (com.google.android.exoplayer2.source.CompositeMediaSource)1 ConcatenatingMediaSource (com.google.android.exoplayer2.source.ConcatenatingMediaSource)1 MaskingMediaSource (com.google.android.exoplayer2.source.MaskingMediaSource)1 MediaSource (com.google.android.exoplayer2.source.MediaSource)1 SinglePeriodTimeline (com.google.android.exoplayer2.source.SinglePeriodTimeline)1 AdPlaybackState (com.google.android.exoplayer2.source.ads.AdPlaybackState)1 ServerSideAdInsertionMediaSource (com.google.android.exoplayer2.source.ads.ServerSideAdInsertionMediaSource)1 ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState (com.google.android.exoplayer2.source.ads.ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState)1 FakeAdaptiveMediaSource (com.google.android.exoplayer2.testutil.FakeAdaptiveMediaSource)1 FakeShuffleOrder (com.google.android.exoplayer2.testutil.FakeShuffleOrder)1 FakeTimeline (com.google.android.exoplayer2.testutil.FakeTimeline)1 TimelineWindowDefinition (com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition)1