Search in sources :

Example 1 with COMMAND_SEEK_FORWARD

use of androidx.media3.common.Player.COMMAND_SEEK_FORWARD in project media by androidx.

the class CastPlayerTest method isCommandAvailable_duringUnseekableItem_isFalseForSeekInCurrentCommands.

@Test
public void isCommandAvailable_duringUnseekableItem_isFalseForSeekInCurrentCommands() {
    MediaItem mediaItem = createMediaItem(/* mediaQueueItemId= */
    1);
    List<MediaItem> mediaItems = ImmutableList.of(mediaItem);
    int[] mediaQueueItemIds = new int[] { 1 };
    int[] streamTypes = new int[] { MediaInfo.STREAM_TYPE_LIVE };
    long[] durationsMs = new long[] { C.TIME_UNSET };
    castPlayer.addMediaItem(mediaItem);
    updateTimeLine(mediaItems, mediaQueueItemIds, /* currentItemId= */
    1, streamTypes, durationsMs, /* positionMs= */
    C.TIME_UNSET);
    assertThat(castPlayer.isCommandAvailable(COMMAND_SEEK_IN_CURRENT_MEDIA_ITEM)).isFalse();
    assertThat(castPlayer.isCommandAvailable(COMMAND_SEEK_BACK)).isFalse();
    assertThat(castPlayer.isCommandAvailable(COMMAND_SEEK_FORWARD)).isFalse();
}
Also used : MediaItem(androidx.media3.common.MediaItem) Test(org.junit.Test)

Example 2 with COMMAND_SEEK_FORWARD

use of androidx.media3.common.Player.COMMAND_SEEK_FORWARD in project media by androidx.

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(androidx.media3.test.utils.FakeMediaSource) TestExoPlayerBuilder(androidx.media3.test.utils.TestExoPlayerBuilder) Test(org.junit.Test)

Example 3 with COMMAND_SEEK_FORWARD

use of androidx.media3.common.Player.COMMAND_SEEK_FORWARD in project media by androidx.

the class PlayerNotificationManager method getActionButtons.

/**
 * Gets the names and order of the actions to be included in the notification at the current
 * player state.
 *
 * <p>The playback and custom actions are combined and placed in the following order if not
 * omitted:
 *
 * <pre>
 *   +------------------------------------------------+
 *   | prev | &lt;&lt; | play/pause | &gt;&gt; | next |
 *   +------------------------------------------------+
 * </pre>
 *
 * <p>This method can be safely overridden.
 */
protected List<CommandButton> getActionButtons() {
    Player player = session.getPlayer();
    boolean enablePrevious = player.isCommandAvailable(COMMAND_SEEK_TO_PREVIOUS);
    boolean enableRewind = player.isCommandAvailable(COMMAND_SEEK_BACK);
    boolean enableFastForward = player.isCommandAvailable(COMMAND_SEEK_FORWARD);
    boolean enableNext = player.isCommandAvailable(COMMAND_SEEK_TO_NEXT);
    List<CommandButton> buttons = new ArrayList<>();
    if (enablePrevious) {
        buttons.add(seekToPreviousButton);
    }
    if (enableRewind) {
        buttons.add(seekBackButton);
    }
    if (shouldShowPauseButton()) {
        buttons.add(pauseButton);
    } else {
        buttons.add(playButton);
    }
    if (enableFastForward) {
        buttons.add(seekForwardButton);
    }
    if (enableNext) {
        buttons.add(seekToNextButton);
    }
    return buttons;
}
Also used : Player(androidx.media3.common.Player) ArrayList(java.util.ArrayList)

Example 4 with COMMAND_SEEK_FORWARD

use of androidx.media3.common.Player.COMMAND_SEEK_FORWARD in project media by androidx.

the class LegacyPlayerControlView method updateNavigation.

private void updateNavigation() {
    if (!isVisible() || !isAttachedToWindow) {
        return;
    }
    @Nullable Player player = this.player;
    boolean enableSeeking = false;
    boolean enablePrevious = false;
    boolean enableRewind = false;
    boolean enableFastForward = false;
    boolean enableNext = false;
    if (player != null) {
        enableSeeking = player.isCommandAvailable(COMMAND_SEEK_IN_CURRENT_MEDIA_ITEM);
        enablePrevious = player.isCommandAvailable(COMMAND_SEEK_TO_PREVIOUS);
        enableRewind = player.isCommandAvailable(COMMAND_SEEK_BACK);
        enableFastForward = player.isCommandAvailable(COMMAND_SEEK_FORWARD);
        enableNext = player.isCommandAvailable(COMMAND_SEEK_TO_NEXT);
    }
    updateButton(showPreviousButton, enablePrevious, previousButton);
    updateButton(showRewindButton, enableRewind, rewindButton);
    updateButton(showFastForwardButton, enableFastForward, fastForwardButton);
    updateButton(showNextButton, enableNext, nextButton);
    if (timeBar != null) {
        timeBar.setEnabled(enableSeeking);
    }
}
Also used : Player(androidx.media3.common.Player) Nullable(androidx.annotation.Nullable)

Example 5 with COMMAND_SEEK_FORWARD

use of androidx.media3.common.Player.COMMAND_SEEK_FORWARD in project media by androidx.

the class ExoPlayerTest method isCommandAvailable_duringUnseekableItem_isFalseForSeekInCurrentCommands.

@Test
public void isCommandAvailable_duringUnseekableItem_isFalseForSeekInCurrentCommands() throws Exception {
    Timeline timelineWithUnseekableWindow = new FakeTimeline(new TimelineWindowDefinition(/* isSeekable= */
    false, /* isDynamic= */
    false, /* durationUs= */
    Util.msToUs(10_000)));
    ExoPlayer player = new TestExoPlayerBuilder(context).build();
    player.addMediaSource(new FakeMediaSource(timelineWithUnseekableWindow));
    player.prepare();
    runUntilPlaybackState(player, Player.STATE_READY);
    assertThat(player.isCommandAvailable(COMMAND_SEEK_IN_CURRENT_MEDIA_ITEM)).isFalse();
    assertThat(player.isCommandAvailable(COMMAND_SEEK_BACK)).isFalse();
    assertThat(player.isCommandAvailable(COMMAND_SEEK_FORWARD)).isFalse();
}
Also used : Timeline(androidx.media3.common.Timeline) NoUidTimeline(androidx.media3.test.utils.NoUidTimeline) FakeTimeline(androidx.media3.test.utils.FakeTimeline) SinglePeriodTimeline(androidx.media3.exoplayer.source.SinglePeriodTimeline) FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) FakeTimeline(androidx.media3.test.utils.FakeTimeline) TimelineWindowDefinition(androidx.media3.test.utils.FakeTimeline.TimelineWindowDefinition) TestExoPlayerBuilder(androidx.media3.test.utils.TestExoPlayerBuilder) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)5 Player (androidx.media3.common.Player)4 FakeMediaSource (androidx.media3.test.utils.FakeMediaSource)4 TestExoPlayerBuilder (androidx.media3.test.utils.TestExoPlayerBuilder)4 Nullable (androidx.annotation.Nullable)2 Timeline (androidx.media3.common.Timeline)2 SinglePeriodTimeline (androidx.media3.exoplayer.source.SinglePeriodTimeline)2 FakeTimeline (androidx.media3.test.utils.FakeTimeline)2 TimelineWindowDefinition (androidx.media3.test.utils.FakeTimeline.TimelineWindowDefinition)2 NoUidTimeline (androidx.media3.test.utils.NoUidTimeline)2 AdPlaybackState (androidx.media3.common.AdPlaybackState)1 ForwardingPlayer (androidx.media3.common.ForwardingPlayer)1 MediaItem (androidx.media3.common.MediaItem)1 Listener (androidx.media3.common.Player.Listener)1 ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState (androidx.media3.exoplayer.source.ads.ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState)1 ArrayList (java.util.ArrayList)1