Add method to query whether a command is available

- Other commands will be added later.
- The returned value is a boolean until we decide what it should be.

PiperOrigin-RevId: 357535877
This commit is contained in:
kimvde 2021-02-15 10:30:44 +00:00 committed by kim-vde
parent c7751344d4
commit 842ca9c09f
4 changed files with 36 additions and 2 deletions

View File

@ -71,6 +71,14 @@ public abstract class BasePlayer implements Player {
removeMediaItems(/* fromIndex= */ index, /* toIndex= */ index + 1); removeMediaItems(/* fromIndex= */ index, /* toIndex= */ index + 1);
} }
@Override
public boolean isCommandAvailable(@Command int command) {
if (command == COMMAND_SEEK_TO_NEXT_MEDIA_ITEM) {
return hasNext();
}
throw new IllegalArgumentException();
}
@Override @Override
public final void play() { public final void play() {
setPlayWhenReady(true); setPlayWhenReady(true);

View File

@ -929,6 +929,17 @@ public interface Player {
/** {@link #getPlaybackParameters()} changed. */ /** {@link #getPlaybackParameters()} changed. */
int EVENT_PLAYBACK_PARAMETERS_CHANGED = 13; int EVENT_PLAYBACK_PARAMETERS_CHANGED = 13;
/**
* Commands that can be executed on a {@code Player}. One of {@link
* #COMMAND_SEEK_TO_NEXT_MEDIA_ITEM}.
*/
@Documented
@Retention(RetentionPolicy.SOURCE)
@IntDef({COMMAND_SEEK_TO_NEXT_MEDIA_ITEM})
@interface Command {}
/** Command to seek to the next {@link MediaItem} in the playlist. */
int COMMAND_SEEK_TO_NEXT_MEDIA_ITEM = 0;
/** Returns the component of this player for audio output, or null if audio is not supported. */ /** Returns the component of this player for audio output, or null if audio is not supported. */
@Nullable @Nullable
AudioComponent getAudioComponent(); AudioComponent getAudioComponent();
@ -1100,6 +1111,19 @@ public interface Player {
/** Clears the playlist. */ /** Clears the playlist. */
void clearMediaItems(); void clearMediaItems();
/**
* Returns whether the provided {@link Command} is available.
*
* <p>This method does not execute the command.
*
* <p>Executing a command that is not available (for example, calling {@link #next()} if {@link
* #COMMAND_SEEK_TO_NEXT_MEDIA_ITEM} is unavailable) is a no-op.
*
* @param command A {@link Command}.
* @return Whether the {@link Command} is available.
*/
boolean isCommandAvailable(@Command int command);
/** Prepares the player. */ /** Prepares the player. */
void prepare(); void prepare();

View File

@ -916,7 +916,8 @@ public class PlayerControlView extends FrameLayout {
enablePrevious = isSeekable || !window.isDynamic || player.hasPrevious(); enablePrevious = isSeekable || !window.isDynamic || player.hasPrevious();
enableRewind = isSeekable && controlDispatcher.isRewindEnabled(); enableRewind = isSeekable && controlDispatcher.isRewindEnabled();
enableFastForward = isSeekable && controlDispatcher.isFastForwardEnabled(); enableFastForward = isSeekable && controlDispatcher.isFastForwardEnabled();
enableNext = window.isLive() || player.hasNext(); enableNext =
window.isLive() || player.isCommandAvailable(Player.COMMAND_SEEK_TO_NEXT_MEDIA_ITEM);
} }
} }

View File

@ -1144,7 +1144,8 @@ public class StyledPlayerControlView extends FrameLayout {
enablePrevious = isSeekable || !window.isDynamic || player.hasPrevious(); enablePrevious = isSeekable || !window.isDynamic || player.hasPrevious();
enableRewind = isSeekable && controlDispatcher.isRewindEnabled(); enableRewind = isSeekable && controlDispatcher.isRewindEnabled();
enableFastForward = isSeekable && controlDispatcher.isFastForwardEnabled(); enableFastForward = isSeekable && controlDispatcher.isFastForwardEnabled();
enableNext = window.isLive() || player.hasNext(); enableNext =
window.isLive() || player.isCommandAvailable(Player.COMMAND_SEEK_TO_NEXT_MEDIA_ITEM);
} }
} }