Commit 0616c0d1 by christosts Committed by Andrew Lewis

Add Player.getAvailableCommands()

Add method getAvailableCommands() in Player interface to return
the available commands. Method isCommandAvailable() moved to
BasePlayer since it can be implelented by calling
getAvailableCommands().

PiperOrigin-RevId: 370059328
parent 87d8907b
......@@ -18,8 +18,9 @@
`onPositionDiscontinuity(int)` callback
([#6163](https://github.com/google/ExoPlayer/issues/6163),
[#4768](https://github.com/google/ExoPlayer/issues/4768)).
* Add `isCommandAvailable` method and `onAvailableCommandsChanged`
listener to query the commands that can be executed on the player.
* Add methods `Player.getAvailableCommands`, `PLayer.isCommandAvailable`
and `EventListener.onAvailableCommandsChanged` to query the commands
that can be executed on the player.
* `AdsLoader.AdViewProvider` and `AdsLoader.OverlayInfo` have been renamed
`com.google.android.exoplayer2.ui.AdViewProvider` and
`com.google.android.exoplayer2.ui.AdOverlayInfo` respectively.
......
......@@ -367,8 +367,8 @@ public final class CastPlayer extends BasePlayer {
}
@Override
public boolean isCommandAvailable(@Command int command) {
return availableCommands.contains(command);
public Commands getAvailableCommands() {
return availableCommands;
}
@Override
......
......@@ -195,14 +195,8 @@ import com.google.android.exoplayer2.util.ListenerSet;
}
@Override
public boolean isCommandAvailable(@Command int command) {
// Only support querrying the minimal set of command for testing.
switch (command) {
case COMMAND_GET_VOLUME:
return false;
default:
throw new UnsupportedOperationException();
}
public Commands getAvailableCommands() {
return Commands.EMPTY;
}
@Override
......
......@@ -81,6 +81,11 @@ public abstract class BasePlayer implements Player {
removeMediaItems(/* fromIndex= */ 0, /* toIndex= */ Integer.MAX_VALUE);
}
@Override
public final boolean isCommandAvailable(@Command int command) {
return getAvailableCommands().contains(command);
}
/** @deprecated Use {@link #getPlayerError()} instead. */
@Deprecated
@Override
......
......@@ -1207,6 +1207,25 @@ public interface Player {
*/
boolean isCommandAvailable(@Command int command);
/**
* Returns the player's currently available {@link Commands}.
*
* <p>The returned {@link Commands} are not updated when available commands change. Use {@link
* EventListener#onAvailableCommandsChanged(Commands)} to get an update when the available
* commands change.
*
* <p>Executing a command that is not available (for example, calling {@link #next()} if {@link
* #COMMAND_SEEK_TO_NEXT_MEDIA_ITEM} is unavailable) will neither throw an exception nor generate
* a {@link #getPlayerError()} player error}.
*
* <p>{@link #COMMAND_SEEK_TO_NEXT_MEDIA_ITEM} and {@link #COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM}
* are unavailable if there is no such {@link MediaItem}.
*
* @return The currently available {@link Commands}.
* @see EventListener#onAvailableCommandsChanged
*/
Commands getAvailableCommands();
/** Prepares the player. */
void prepare();
......
......@@ -340,8 +340,8 @@ import java.util.concurrent.CopyOnWriteArraySet;
}
@Override
public boolean isCommandAvailable(@Command int command) {
return availableCommands.contains(command);
public Commands getAvailableCommands() {
return availableCommands;
}
@Override
......
......@@ -1349,9 +1349,9 @@ public class SimpleExoPlayer extends BasePlayer
}
@Override
public boolean isCommandAvailable(@Command int command) {
public Commands getAvailableCommands() {
verifyApplicationThread();
return player.isCommandAvailable(command);
return player.getAvailableCommands();
}
@Override
......
......@@ -249,7 +249,7 @@ public class StubExoPlayer extends BasePlayer implements ExoPlayer {
}
@Override
public boolean isCommandAvailable(int command) {
public Commands getAvailableCommands() {
throw new UnsupportedOperationException();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment