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:
parent
c7751344d4
commit
842ca9c09f
@ -71,6 +71,14 @@ public abstract class BasePlayer implements Player {
|
||||
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
|
||||
public final void play() {
|
||||
setPlayWhenReady(true);
|
||||
|
@ -929,6 +929,17 @@ public interface Player {
|
||||
/** {@link #getPlaybackParameters()} changed. */
|
||||
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. */
|
||||
@Nullable
|
||||
AudioComponent getAudioComponent();
|
||||
@ -1100,6 +1111,19 @@ public interface Player {
|
||||
/** Clears the playlist. */
|
||||
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. */
|
||||
void prepare();
|
||||
|
||||
|
@ -916,7 +916,8 @@ public class PlayerControlView extends FrameLayout {
|
||||
enablePrevious = isSeekable || !window.isDynamic || player.hasPrevious();
|
||||
enableRewind = isSeekable && controlDispatcher.isRewindEnabled();
|
||||
enableFastForward = isSeekable && controlDispatcher.isFastForwardEnabled();
|
||||
enableNext = window.isLive() || player.hasNext();
|
||||
enableNext =
|
||||
window.isLive() || player.isCommandAvailable(Player.COMMAND_SEEK_TO_NEXT_MEDIA_ITEM);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1144,7 +1144,8 @@ public class StyledPlayerControlView extends FrameLayout {
|
||||
enablePrevious = isSeekable || !window.isDynamic || player.hasPrevious();
|
||||
enableRewind = isSeekable && controlDispatcher.isRewindEnabled();
|
||||
enableFastForward = isSeekable && controlDispatcher.isFastForwardEnabled();
|
||||
enableNext = window.isLive() || player.hasNext();
|
||||
enableNext =
|
||||
window.isLive() || player.isCommandAvailable(Player.COMMAND_SEEK_TO_NEXT_MEDIA_ITEM);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user