diff --git a/libraries/common/src/main/java/androidx/media3/common/Player.java b/libraries/common/src/main/java/androidx/media3/common/Player.java index 8b045f6305..794ef81beb 100644 --- a/libraries/common/src/main/java/androidx/media3/common/Player.java +++ b/libraries/common/src/main/java/androidx/media3/common/Player.java @@ -1427,6 +1427,9 @@ public interface Player { *
The currently available commands can be inspected with {@link #getAvailableCommands()} and * {@link #isCommandAvailable(int)}. * + *
See the documentation of each command constant for the details of which methods it permits + * calling. + * *
One of the following values: * *
The following methods must only be called if this command is {@linkplain + * #isCommandAvailable(int) available}: + * + *
The {@link #prepare()} method must only be called if this command is {@linkplain + * #isCommandAvailable(int) available}. + */ int COMMAND_PREPARE = 2; - /** Command to stop playback. */ + + /** + * Command to stop playback. + * + *
The {@link #stop()} method must only be called if this command is {@linkplain + * #isCommandAvailable(int) available}. + */ int COMMAND_STOP = 3; - /** Command to seek to the default position of the current {@link MediaItem}. */ + + /** + * Command to seek to the default position of the current {@link MediaItem}. + * + *
The {@link #seekToDefaultPosition()} method must only be called if this command is + * {@linkplain #isCommandAvailable(int) available}. + */ int COMMAND_SEEK_TO_DEFAULT_POSITION = 4; - /** Command to seek anywhere inside the current {@link MediaItem}. */ + + /** + * Command to seek anywhere inside the current {@link MediaItem}. + * + *
The {@link #seekTo(long)} method must only be called if this command is {@linkplain + * #isCommandAvailable(int) available}. + */ int COMMAND_SEEK_IN_CURRENT_MEDIA_ITEM = 5; /** * @deprecated Use {@link #COMMAND_SEEK_IN_CURRENT_MEDIA_ITEM} instead. */ @UnstableApi @Deprecated int COMMAND_SEEK_IN_CURRENT_WINDOW = COMMAND_SEEK_IN_CURRENT_MEDIA_ITEM; - /** Command to seek to the default position of the previous {@link MediaItem}. */ + + /** + * Command to seek to the default position of the previous {@link MediaItem}. + * + *
The {@link #seekToPreviousMediaItem()} method must only be called if this command is + * {@linkplain #isCommandAvailable(int) available}. + */ int COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM = 6; /** * @deprecated Use {@link #COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM} instead. @@ -1527,9 +1571,17 @@ public interface Player { /** * Command to seek to an earlier position in the current {@link MediaItem} or the default position * of the previous {@link MediaItem}. + * + *
The {@link #seekToPrevious()} method must only be called if this command is {@linkplain + * #isCommandAvailable(int) available}. */ int COMMAND_SEEK_TO_PREVIOUS = 7; - /** Command to seek to the default position of the next {@link MediaItem}. */ + /** + * Command to seek to the default position of the next {@link MediaItem}. + * + *
The {@link #seekToNextMediaItem()} method must only be called if this command is {@linkplain + * #isCommandAvailable(int) available}. + */ int COMMAND_SEEK_TO_NEXT_MEDIA_ITEM = 8; /** * @deprecated Use {@link #COMMAND_SEEK_TO_NEXT_MEDIA_ITEM} instead. @@ -1538,57 +1590,259 @@ public interface Player { /** * Command to seek to a later position in the current {@link MediaItem} or the default position of * the next {@link MediaItem}. + * + *
The {@link #seekToNext()} method must only be called if this command is {@linkplain + * #isCommandAvailable(int) available}. */ int COMMAND_SEEK_TO_NEXT = 9; - /** Command to seek anywhere in any {@link MediaItem}. */ + + /** + * Command to seek anywhere in any {@link MediaItem}. + * + *
The following methods must only be called if this command is {@linkplain + * #isCommandAvailable(int) available}: + * + *
The {@link #seekBack()} method must only be called if this command is {@linkplain + * #isCommandAvailable(int) available}. + */ int COMMAND_SEEK_BACK = 11; - /** Command to seek forward by a fixed increment inside the current {@link MediaItem}. */ + /** + * Command to seek forward by a fixed increment inside the current {@link MediaItem}. + * + *
The {@link #seekForward()} method must only be called if this command is {@linkplain + * #isCommandAvailable(int) available}. + */ int COMMAND_SEEK_FORWARD = 12; - /** Command to set the playback speed and pitch. */ + + /** + * Command to set the playback speed and pitch. + * + *
The following methods must only be called if this command is {@linkplain + * #isCommandAvailable(int) available}: + * + *
The {@link #setShuffleModeEnabled(boolean)} method must only be called if this command is + * {@linkplain #isCommandAvailable(int) available}. + */ int COMMAND_SET_SHUFFLE_MODE = 14; - /** Command to set the repeat mode. */ + + /** + * Command to set the repeat mode. + * + *
The {@link #setRepeatMode(int)} method must only be called if this command is {@linkplain + * #isCommandAvailable(int) available}. + */ int COMMAND_SET_REPEAT_MODE = 15; - /** Command to get the currently playing {@link MediaItem}. */ + + /** + * Command to get the currently playing {@link MediaItem}. + * + *
The {@link #getCurrentMediaItem()} method must only be called if this command is {@linkplain + * #isCommandAvailable(int) available}. + */ int COMMAND_GET_CURRENT_MEDIA_ITEM = 16; - /** Command to get the information about the current timeline. */ + + /** + * Command to get the information about the current timeline. + * + *
The following methods must only be called if this command is {@linkplain + * #isCommandAvailable(int) available}: + * + *
The following methods must only be called if this command is {@linkplain + * #isCommandAvailable(int) available}: + * + *
The {@link #setPlaylistMetadata(MediaMetadata)} method must only be called if this command + * is {@linkplain #isCommandAvailable(int) available}. + */ // TODO(b/263132691): Rename this to COMMAND_SET_PLAYLIST_METADATA int COMMAND_SET_MEDIA_ITEMS_METADATA = 19; - /** Command to set a {@link MediaItem}. */ + + /** + * Command to set a {@link MediaItem}. + * + *
The following methods must only be called if this command is {@linkplain + * #isCommandAvailable(int) available}: + * + *
The following methods must only be called if this command is {@linkplain + * #isCommandAvailable(int) available}: + * + *
The {@link #getAudioAttributes()} method must only be called if this command is {@linkplain + * #isCommandAvailable(int) available}. + */ int COMMAND_GET_AUDIO_ATTRIBUTES = 21; - /** Command to get the player volume. */ + + /** + * Command to get the player volume. + * + *
The {@link #getVolume()} method must only be called if this command is {@linkplain + * #isCommandAvailable(int) available}. + */ int COMMAND_GET_VOLUME = 22; - /** Command to get the device volume and whether it is muted. */ + + /** + * Command to get the device volume and whether it is muted. + * + *
The following methods must only be called if this command is {@linkplain + * #isCommandAvailable(int) available}: + * + *
The {@link #setVolume(float)} method must only be called if this command is {@linkplain + * #isCommandAvailable(int) available}. + */ int COMMAND_SET_VOLUME = 24; - /** Command to set the device volume. */ + /** + * Command to set the device volume. + * + *
The {@link #setDeviceVolume(int)} method must only be called if this command is {@linkplain + * #isCommandAvailable(int) available}. + */ int COMMAND_SET_DEVICE_VOLUME = 25; - /** Command to increase and decrease the device volume and mute it. */ + + /** + * Command to increase and decrease the device volume and mute it. + * + *
The following methods must only be called if this command is {@linkplain + * #isCommandAvailable(int) available}: + * + *
The following methods must only be called if this command is {@linkplain + * #isCommandAvailable(int) available}: + * + *
The {@link #getCurrentCues()} method must only be called if this command is {@linkplain + * #isCommandAvailable(int) available}. + */ int COMMAND_GET_TEXT = 28; - /** Command to set the player's track selection parameters. */ + + /** + * Command to set the player's track selection parameters. + * + *
The {@link #setTrackSelectionParameters(TrackSelectionParameters)} method must only be + * called if this command is {@linkplain #isCommandAvailable(int) available}. + */ int COMMAND_SET_TRACK_SELECTION_PARAMETERS = 29; - /** Command to get details of the current track selection. */ + + /** + * Command to get details of the current track selection. + * + *
The {@link #getCurrentTracks()} method must only be called if this command is {@linkplain + * #isCommandAvailable(int) available}. + */ int COMMAND_GET_TRACKS = 30; /** Represents an invalid {@link Command}. */ @@ -1626,6 +1880,9 @@ public interface Player { * Clears the playlist, adds the specified {@linkplain MediaItem media items} and resets the * position to the default position. * + *
This method must only be called if {@link #COMMAND_CHANGE_MEDIA_ITEMS} is {@linkplain
+ * #getAvailableCommands() available}.
+ *
* @param mediaItems The new {@linkplain MediaItem media items}.
*/
void setMediaItems(List This method must only be called if {@link #COMMAND_CHANGE_MEDIA_ITEMS} is {@linkplain
+ * #getAvailableCommands() available}.
+ *
* @param mediaItems The new {@linkplain MediaItem media items}.
* @param resetPosition Whether the playback position should be reset to the default position in
* the first {@link Timeline.Window}. If false, playback will start from the position defined
@@ -1643,6 +1903,9 @@ public interface Player {
/**
* Clears the playlist and adds the specified {@linkplain MediaItem media items}.
*
+ * This method must only be called if {@link #COMMAND_CHANGE_MEDIA_ITEMS} is {@linkplain
+ * #getAvailableCommands() available}.
+ *
* @param mediaItems The new {@linkplain MediaItem media items}.
* @param startIndex The {@link MediaItem} index to start playback from. If {@link C#INDEX_UNSET}
* is passed, the current position is not reset.
@@ -1659,6 +1922,9 @@ public interface Player {
* Clears the playlist, adds the specified {@link MediaItem} and resets the position to the
* default position.
*
+ * This method must only be called if {@link #COMMAND_SET_MEDIA_ITEM} is {@linkplain
+ * #getAvailableCommands() available}.
+ *
* @param mediaItem The new {@link MediaItem}.
*/
void setMediaItem(MediaItem mediaItem);
@@ -1666,6 +1932,9 @@ public interface Player {
/**
* Clears the playlist and adds the specified {@link MediaItem}.
*
+ * This method must only be called if {@link #COMMAND_SET_MEDIA_ITEM} is {@linkplain
+ * #getAvailableCommands() available}.
+ *
* @param mediaItem The new {@link MediaItem}.
* @param startPositionMs The position in milliseconds to start playback from.
*/
@@ -1674,6 +1943,9 @@ public interface Player {
/**
* Clears the playlist and adds the specified {@link MediaItem}.
*
+ * This method must only be called if {@link #COMMAND_SET_MEDIA_ITEM} is {@linkplain
+ * #getAvailableCommands() available}.
+ *
* @param mediaItem The new {@link MediaItem}.
* @param resetPosition Whether the playback position should be reset to the default position. If
* false, playback will start from the position defined by {@link #getCurrentMediaItemIndex()}
@@ -1684,6 +1956,9 @@ public interface Player {
/**
* Adds a media item to the end of the playlist.
*
+ * This method must only be called if {@link #COMMAND_CHANGE_MEDIA_ITEMS} is {@linkplain
+ * #getAvailableCommands() available}.
+ *
* @param mediaItem The {@link MediaItem} to add.
*/
void addMediaItem(MediaItem mediaItem);
@@ -1691,6 +1966,9 @@ public interface Player {
/**
* Adds a media item at the given index of the playlist.
*
+ * This method must only be called if {@link #COMMAND_CHANGE_MEDIA_ITEMS} is {@linkplain
+ * #getAvailableCommands() available}.
+ *
* @param index The index at which to add the media item. If the index is larger than the size of
* the playlist, the media item is added to the end of the playlist.
* @param mediaItem The {@link MediaItem} to add.
@@ -1700,6 +1978,9 @@ public interface Player {
/**
* Adds a list of media items to the end of the playlist.
*
+ * This method must only be called if {@link #COMMAND_CHANGE_MEDIA_ITEMS} is {@linkplain
+ * #getAvailableCommands() available}.
+ *
* @param mediaItems The {@linkplain MediaItem media items} to add.
*/
void addMediaItems(List This method must only be called if {@link #COMMAND_CHANGE_MEDIA_ITEMS} is {@linkplain
+ * #getAvailableCommands() available}.
+ *
* @param index The index at which to add the media items. If the index is larger than the size of
* the playlist, the media items are added to the end of the playlist.
* @param mediaItems The {@linkplain MediaItem media items} to add.
@@ -1716,6 +2000,9 @@ public interface Player {
/**
* Moves the media item at the current index to the new index.
*
+ * This method must only be called if {@link #COMMAND_CHANGE_MEDIA_ITEMS} is {@linkplain
+ * #getAvailableCommands() available}.
+ *
* @param currentIndex The current index of the media item to move. If the index is larger than
* the size of the playlist, the request is ignored.
* @param newIndex The new index of the media item. If the new index is larger than the size of
@@ -1726,6 +2013,9 @@ public interface Player {
/**
* Moves the media item range to the new index.
*
+ * This method must only be called if {@link #COMMAND_CHANGE_MEDIA_ITEMS} is {@linkplain
+ * #getAvailableCommands() available}.
+ *
* @param fromIndex The start of the range to move. If the index is larger than the size of the
* playlist, the request is ignored.
* @param toIndex The first item not to be included in the range (exclusive). If the index is
@@ -1739,6 +2029,9 @@ public interface Player {
/**
* Removes the media item at the given index of the playlist.
*
+ * This method must only be called if {@link #COMMAND_CHANGE_MEDIA_ITEMS} is {@linkplain
+ * #getAvailableCommands() available}.
+ *
* @param index The index at which to remove the media item. If the index is larger than the size
* of the playlist, the request is ignored.
*/
@@ -1747,6 +2040,9 @@ public interface Player {
/**
* Removes a range of media items from the playlist.
*
+ * This method must only be called if {@link #COMMAND_CHANGE_MEDIA_ITEMS} is {@linkplain
+ * #getAvailableCommands() available}.
+ *
* @param fromIndex The index at which to start removing media items. If the index is larger than
* the size of the playlist, the request is ignored.
* @param toIndex The index of the first item to be kept (exclusive). If the index is larger than
@@ -1754,7 +2050,12 @@ public interface Player {
*/
void removeMediaItems(int fromIndex, int toIndex);
- /** Clears the playlist. */
+ /**
+ * Clears the playlist.
+ *
+ * This method must only be called if {@link #COMMAND_CHANGE_MEDIA_ITEMS} is {@linkplain
+ * #getAvailableCommands() available}.
+ */
void clearMediaItems();
/**
@@ -1762,13 +2063,6 @@ public interface Player {
*
* This method does not execute the command.
*
- * Executing a command that is not available (for example, calling {@link
- * #seekToNextMediaItem()} if {@link #COMMAND_SEEK_TO_NEXT_MEDIA_ITEM} is unavailable) will
- * neither throw an exception nor generate a {@link #getPlayerError()} player error}.
- *
- * {@link #COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM} and {@link #COMMAND_SEEK_TO_NEXT_MEDIA_ITEM}
- * are unavailable if there is no such {@link MediaItem}.
- *
* @param command A {@link Command}.
* @return Whether the {@link Command} is available.
* @see Listener#onAvailableCommandsChanged(Commands)
@@ -1785,13 +2079,6 @@ public interface Player {
* Listener#onAvailableCommandsChanged(Commands)} to get an update when the available commands
* change.
*
- * Executing a command that is not available (for example, calling {@link
- * #seekToNextMediaItem()} if {@link #COMMAND_SEEK_TO_NEXT_MEDIA_ITEM} is unavailable) will
- * neither throw an exception nor generate a {@link #getPlayerError()} player error}.
- *
- * {@link #COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM} and {@link #COMMAND_SEEK_TO_NEXT_MEDIA_ITEM}
- * are unavailable if there is no such {@link MediaItem}.
- *
* @return The currently available {@link Commands}.
* @see Listener#onAvailableCommandsChanged
*/
@@ -1800,6 +2087,9 @@ public interface Player {
/**
* Prepares the player.
*
+ * This method must only be called if {@link #COMMAND_PREPARE} is {@linkplain
+ * #getAvailableCommands() available}.
+ *
* This will move the player out of {@link #STATE_IDLE idle state} and the player will start
* loading media and acquire resources needed for playback.
*/
@@ -1857,10 +2147,18 @@ public interface Player {
/**
* Resumes playback as soon as {@link #getPlaybackState()} == {@link #STATE_READY}. Equivalent to
* {@link #setPlayWhenReady(boolean) setPlayWhenReady(true)}.
+ *
+ * This method must only be called if {@link #COMMAND_PLAY_PAUSE} is {@linkplain
+ * #getAvailableCommands() available}.
*/
void play();
- /** Pauses playback. Equivalent to {@link #setPlayWhenReady(boolean) setPlayWhenReady(false)}. */
+ /**
+ * Pauses playback. Equivalent to {@link #setPlayWhenReady(boolean) setPlayWhenReady(false)}.
+ *
+ * This method must only be called if {@link #COMMAND_PLAY_PAUSE} is {@linkplain
+ * #getAvailableCommands() available}.
+ */
void pause();
/**
@@ -1868,6 +2166,9 @@ public interface Player {
*
* If the player is already in the ready state then this method pauses and resumes playback.
*
+ * This method must only be called if {@link #COMMAND_PLAY_PAUSE} is {@linkplain
+ * #getAvailableCommands() available}.
+ *
* @param playWhenReady Whether playback should proceed when ready.
*/
void setPlayWhenReady(boolean playWhenReady);
@@ -1883,6 +2184,9 @@ public interface Player {
/**
* Sets the {@link RepeatMode} to be used for playback.
*
+ * This method must only be called if {@link #COMMAND_SET_REPEAT_MODE} is {@linkplain
+ * #getAvailableCommands() available}.
+ *
* @param repeatMode The repeat mode.
*/
void setRepeatMode(@RepeatMode int repeatMode);
@@ -1899,6 +2203,9 @@ public interface Player {
/**
* Sets whether shuffling of media items is enabled.
*
+ * This method must only be called if {@link #COMMAND_SET_SHUFFLE_MODE} is {@linkplain
+ * #getAvailableCommands() available}.
+ *
* @param shuffleModeEnabled Whether shuffling is enabled.
*/
void setShuffleModeEnabled(boolean shuffleModeEnabled);
@@ -1922,6 +2229,9 @@ public interface Player {
* Seeks to the default position associated with the current {@link MediaItem}. The position can
* depend on the type of media being played. For live streams it will typically be the live edge.
* For other streams it will typically be the start.
+ *
+ * This method must only be called if {@link #COMMAND_SEEK_TO_DEFAULT_POSITION} is {@linkplain
+ * #getAvailableCommands() available}.
*/
void seekToDefaultPosition();
@@ -1930,6 +2240,9 @@ public interface Player {
* depend on the type of media being played. For live streams it will typically be the live edge.
* For other streams it will typically be the start.
*
+ * This method must only be called if {@link #COMMAND_SEEK_TO_MEDIA_ITEM} is {@linkplain
+ * #getAvailableCommands() available}.
+ *
* @param mediaItemIndex The index of the {@link MediaItem} whose associated default position
* should be seeked to. If the index is larger than the size of the playlist, the request is
* ignored.
@@ -1939,6 +2252,9 @@ public interface Player {
/**
* Seeks to a position specified in milliseconds in the current {@link MediaItem}.
*
+ * This method must only be called if {@link #COMMAND_SEEK_IN_CURRENT_MEDIA_ITEM} is
+ * {@linkplain #getAvailableCommands() available}.
+ *
* @param positionMs The seek position in the current {@link MediaItem}, or {@link C#TIME_UNSET}
* to seek to the media item's default position.
*/
@@ -1947,6 +2263,9 @@ public interface Player {
/**
* Seeks to a position specified in milliseconds in the specified {@link MediaItem}.
*
+ * This method must only be called if {@link #COMMAND_SEEK_TO_MEDIA_ITEM} is {@linkplain
+ * #getAvailableCommands() available}.
+ *
* @param mediaItemIndex The index of the {@link MediaItem}. If the index is larger than the size
* of the playlist, the request is ignored.
* @param positionMs The seek position in the specified {@link MediaItem}, or {@link C#TIME_UNSET}
@@ -1964,6 +2283,9 @@ public interface Player {
/**
* Seeks back in the current {@link MediaItem} by {@link #getSeekBackIncrement()} milliseconds.
+ *
+ * This method must only be called if {@link #COMMAND_SEEK_BACK} is {@linkplain
+ * #getAvailableCommands() available}.
*/
void seekBack();
@@ -1978,6 +2300,9 @@ public interface Player {
/**
* Seeks forward in the current {@link MediaItem} by {@link #getSeekForwardIncrement()}
* milliseconds.
+ *
+ * This method must only be called if {@link #COMMAND_SEEK_FORWARD} is {@linkplain
+ * #getAvailableCommands() available}.
*/
void seekForward();
@@ -2027,6 +2352,9 @@ public interface Player {
* Note: When the repeat mode is {@link #REPEAT_MODE_ONE}, this method behaves the same as when
* the current repeat mode is {@link #REPEAT_MODE_OFF}. See {@link #REPEAT_MODE_ONE} for more
* details.
+ *
+ * This method must only be called if {@link #COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM} is
+ * {@linkplain #getAvailableCommands() available}.
*/
void seekToPreviousMediaItem();
@@ -2058,6 +2386,9 @@ public interface Player {
* MediaItem}.
*
This method must only be called if {@link #COMMAND_SEEK_TO_PREVIOUS} is {@linkplain + * #getAvailableCommands() available}. */ void seekToPrevious(); @@ -2107,6 +2438,9 @@ public interface Player { *
Note: When the repeat mode is {@link #REPEAT_MODE_ONE}, this method behaves the same as when * the current repeat mode is {@link #REPEAT_MODE_OFF}. See {@link #REPEAT_MODE_ONE} for more * details. + * + *
This method must only be called if {@link #COMMAND_SEEK_TO_NEXT_MEDIA_ITEM} is {@linkplain + * #getAvailableCommands() available}. */ void seekToNextMediaItem(); @@ -2122,6 +2456,9 @@ public interface Player { * has not ended, seeks to the live edge of the current {@link MediaItem}. *
This method must only be called if {@link #COMMAND_SEEK_TO_NEXT} is {@linkplain + * #getAvailableCommands() available}. */ void seekToNext(); @@ -2133,6 +2470,9 @@ public interface Player { * Listener#onPlaybackParametersChanged(PlaybackParameters)} will be called whenever the currently * active playback parameters change. * + *
This method must only be called if {@link #COMMAND_SET_SPEED_AND_PITCH} is {@linkplain + * #getAvailableCommands() available}. + * * @param playbackParameters The playback parameters. */ void setPlaybackParameters(PlaybackParameters playbackParameters); @@ -2143,6 +2483,9 @@ public interface Player { *
This is equivalent to {@code * setPlaybackParameters(getPlaybackParameters().withSpeed(speed))}. * + *
This method must only be called if {@link #COMMAND_SET_SPEED_AND_PITCH} is {@linkplain + * #getAvailableCommands() available}. + * * @param speed The linear factor by which playback will be sped up. Must be higher than 0. 1 is * normal speed, 2 is twice as fast, 0.5 is half normal speed. */ @@ -2166,6 +2509,9 @@ public interface Player { * *
Calling this method does not clear the playlist, reset the playback position or the playback * error. + * + *
This method must only be called if {@link #COMMAND_STOP} is {@linkplain + * #getAvailableCommands() available}. */ void stop(); @@ -2182,11 +2528,15 @@ public interface Player { * Releases the player. This method must be called when the player is no longer required. The * player must not be used after calling this method. */ + // TODO(b/261158047): Document that COMMAND_RELEASE must be available once it exists. void release(); /** * Returns the current tracks. * + *
This method must only be called if {@link #COMMAND_GET_TRACKS} is {@linkplain + * #getAvailableCommands() available}. + * * @see Listener#onTracksChanged(Tracks) */ Tracks getCurrentTracks(); @@ -2214,6 +2564,9 @@ public interface Player { * .setMaxVideoSizeSd() * .build()) * } + * + *
This method must only be called if {@link #COMMAND_SET_TRACK_SELECTION_PARAMETERS} is + * {@linkplain #getAvailableCommands() available}. */ void setTrackSelectionParameters(TrackSelectionParameters parameters); @@ -2226,16 +2579,27 @@ public interface Player { * metadata that has been parsed from the media and output via {@link * Listener#onMetadata(Metadata)}. If a field is populated in the {@link MediaItem#mediaMetadata}, * it will be prioritised above the same field coming from static or timed metadata. + * + *
This method must only be called if {@link #COMMAND_GET_MEDIA_ITEMS_METADATA} is {@linkplain + * #getAvailableCommands() available}. */ MediaMetadata getMediaMetadata(); /** * Returns the playlist {@link MediaMetadata}, as set by {@link * #setPlaylistMetadata(MediaMetadata)}, or {@link MediaMetadata#EMPTY} if not supported. + * + *
This method must only be called if {@link #COMMAND_GET_MEDIA_ITEMS_METADATA} is {@linkplain + * #getAvailableCommands() available}. */ MediaMetadata getPlaylistMetadata(); - /** Sets the playlist {@link MediaMetadata}. */ + /** + * Sets the playlist {@link MediaMetadata}. + * + *
This method must only be called if {@link #COMMAND_SET_MEDIA_ITEMS_METADATA} is {@linkplain + * #getAvailableCommands() available}. + */ void setPlaylistMetadata(MediaMetadata mediaMetadata); /** @@ -2248,11 +2612,19 @@ public interface Player { /** * Returns the current {@link Timeline}. Never null, but may be empty. * + *
This method must only be called if {@link #COMMAND_GET_TIMELINE} is {@linkplain + * #getAvailableCommands() available}. + * * @see Listener#onTimelineChanged(Timeline, int) */ Timeline getCurrentTimeline(); - /** Returns the index of the period currently being played. */ + /** + * Returns the index of the period currently being played. + * + *
This method must only be called if {@link #COMMAND_GET_TIMELINE} is {@linkplain + * #getAvailableCommands() available}. + */ int getCurrentPeriodIndex(); /** @@ -2266,6 +2638,9 @@ public interface Player { * Returns the index of the current {@link MediaItem} in the {@link #getCurrentTimeline() * timeline}, or the prospective index if the {@link #getCurrentTimeline() current timeline} is * empty. + * + *
This method must only be called if {@link #COMMAND_GET_TIMELINE} is {@linkplain + * #getAvailableCommands() available}. */ int getCurrentMediaItemIndex(); @@ -2285,6 +2660,9 @@ public interface Player { *
Note: When the repeat mode is {@link #REPEAT_MODE_ONE}, this method behaves the same as when * the current repeat mode is {@link #REPEAT_MODE_OFF}. See {@link #REPEAT_MODE_ONE} for more * details. + * + *
This method must only be called if {@link #COMMAND_GET_TIMELINE} is {@linkplain + * #getAvailableCommands() available}. */ int getNextMediaItemIndex(); @@ -2304,21 +2682,37 @@ public interface Player { *
Note: When the repeat mode is {@link #REPEAT_MODE_ONE}, this method behaves the same as when * the current repeat mode is {@link #REPEAT_MODE_OFF}. See {@link #REPEAT_MODE_ONE} for more * details. + * + *
This method must only be called if {@link #COMMAND_GET_TIMELINE} is {@linkplain + * #getAvailableCommands() available}. */ int getPreviousMediaItemIndex(); /** * Returns the currently playing {@link MediaItem}. May be null if the timeline is empty. * + *
This method must only be called if {@link #COMMAND_GET_CURRENT_MEDIA_ITEM} is {@linkplain + * #getAvailableCommands() available}. + * * @see Listener#onMediaItemTransition(MediaItem, int) */ @Nullable MediaItem getCurrentMediaItem(); - /** Returns the number of {@linkplain MediaItem media items} in the playlist. */ + /** + * Returns the number of {@linkplain MediaItem media items} in the playlist. + * + *
This method must only be called if {@link #COMMAND_GET_TIMELINE} is {@linkplain + * #getAvailableCommands() available}. + */ int getMediaItemCount(); - /** Returns the {@link MediaItem} at the given index. */ + /** + * Returns the {@link MediaItem} at the given index. + * + *
This method must only be called if {@link #COMMAND_GET_TIMELINE} is {@linkplain + * #getAvailableCommands() available}. + */ MediaItem getMediaItemAt(int index); /** @@ -2416,12 +2810,18 @@ public interface Player { /** * If {@link #isPlayingAd()} returns true, returns the index of the ad group in the period * currently being played. Returns {@link C#INDEX_UNSET} otherwise. + * + *
This method must only be called if {@link #COMMAND_GET_TIMELINE} is {@linkplain + * #getAvailableCommands() available}. */ int getCurrentAdGroupIndex(); /** * If {@link #isPlayingAd()} returns true, returns the index of the ad in its ad group. Returns * {@link C#INDEX_UNSET} otherwise. + * + *
This method must only be called if {@link #COMMAND_GET_TIMELINE} is {@linkplain + * #getAvailableCommands() available}. */ int getCurrentAdIndexInAdGroup(); @@ -2446,13 +2846,21 @@ public interface Player { */ long getContentBufferedPosition(); - /** Returns the attributes for audio playback. */ + /** + * Returns the attributes for audio playback. + * + *
This method must only be called if {@link #COMMAND_GET_AUDIO_ATTRIBUTES} is {@linkplain + * #getAvailableCommands() available}. + */ AudioAttributes getAudioAttributes(); /** * Sets the audio volume, valid values are between 0 (silence) and 1 (unity gain, signal * unchanged), inclusive. * + *
This method must only be called if {@link #COMMAND_SET_VOLUME} is {@linkplain + * #getAvailableCommands() available}. + * * @param volume Linear output gain to apply to all audio channels. */ void setVolume(@FloatRange(from = 0, to = 1.0) float volume); @@ -2460,6 +2868,9 @@ public interface Player { /** * Returns the audio volume, with 0 being silence and 1 being unity gain (signal unchanged). * + *
This method must only be called if {@link #COMMAND_GET_VOLUME} is {@linkplain + * #getAvailableCommands() available}. + * * @return The linear gain applied to all audio channels. */ @FloatRange(from = 0, to = 1.0) @@ -2468,6 +2879,9 @@ public interface Player { /** * Clears any {@link Surface}, {@link SurfaceHolder}, {@link SurfaceView} or {@link TextureView} * currently set on the player. + * + *
This method must only be called if {@link #COMMAND_SET_VIDEO_SURFACE} is {@linkplain + * #getAvailableCommands() available}. */ void clearVideoSurface(); @@ -2475,6 +2889,9 @@ public interface Player { * Clears the {@link Surface} onto which video is being rendered if it matches the one passed. * Else does nothing. * + *
This method must only be called if {@link #COMMAND_SET_VIDEO_SURFACE} is {@linkplain + * #getAvailableCommands() available}. + * * @param surface The surface to clear. */ void clearVideoSurface(@Nullable Surface surface); @@ -2490,6 +2907,9 @@ public interface Player { * this method, since passing the holder allows the player to track the lifecycle of the surface * automatically. * + *
This method must only be called if {@link #COMMAND_SET_VIDEO_SURFACE} is {@linkplain + * #getAvailableCommands() available}. + * * @param surface The {@link Surface}. */ void setVideoSurface(@Nullable Surface surface); @@ -2501,6 +2921,9 @@ public interface Player { *
The thread that calls the {@link SurfaceHolder.Callback} methods must be the thread * associated with {@link #getApplicationLooper()}. * + *
This method must only be called if {@link #COMMAND_SET_VIDEO_SURFACE} is {@linkplain + * #getAvailableCommands() available}. + * * @param surfaceHolder The surface holder. */ void setVideoSurfaceHolder(@Nullable SurfaceHolder surfaceHolder); @@ -2509,6 +2932,9 @@ public interface Player { * Clears the {@link SurfaceHolder} that holds the {@link Surface} onto which video is being * rendered if it matches the one passed. Else does nothing. * + *
This method must only be called if {@link #COMMAND_SET_VIDEO_SURFACE} is {@linkplain + * #getAvailableCommands() available}. + * * @param surfaceHolder The surface holder to clear. */ void clearVideoSurfaceHolder(@Nullable SurfaceHolder surfaceHolder); @@ -2520,6 +2946,9 @@ public interface Player { *
The thread that calls the {@link SurfaceHolder.Callback} methods must be the thread * associated with {@link #getApplicationLooper()}. * + *
This method must only be called if {@link #COMMAND_SET_VIDEO_SURFACE} is {@linkplain + * #getAvailableCommands() available}. + * * @param surfaceView The surface view. */ void setVideoSurfaceView(@Nullable SurfaceView surfaceView); @@ -2528,6 +2957,9 @@ public interface Player { * Clears the {@link SurfaceView} onto which video is being rendered if it matches the one passed. * Else does nothing. * + *
This method must only be called if {@link #COMMAND_SET_VIDEO_SURFACE} is {@linkplain + * #getAvailableCommands() available}. + * * @param surfaceView The texture view to clear. */ void clearVideoSurfaceView(@Nullable SurfaceView surfaceView); @@ -2539,6 +2971,9 @@ public interface Player { *
The thread that calls the {@link TextureView.SurfaceTextureListener} methods must be the * thread associated with {@link #getApplicationLooper()}. * + *
This method must only be called if {@link #COMMAND_SET_VIDEO_SURFACE} is {@linkplain + * #getAvailableCommands() available}. + * * @param textureView The texture view. */ void setVideoTextureView(@Nullable TextureView textureView); @@ -2547,6 +2982,9 @@ public interface Player { * Clears the {@link TextureView} onto which video is being rendered if it matches the one passed. * Else does nothing. * + *
This method must only be called if {@link #COMMAND_SET_VIDEO_SURFACE} is {@linkplain + * #getAvailableCommands() available}. + * * @param textureView The texture view to clear. */ void clearVideoTextureView(@Nullable TextureView textureView); @@ -2569,7 +3007,12 @@ public interface Player { @UnstableApi Size getSurfaceSize(); - /** Returns the current {@link CueGroup}. */ + /** + * Returns the current {@link CueGroup}. + * + *
This method must only be called if {@link #COMMAND_GET_TEXT} is {@linkplain + * #getAvailableCommands() available}. + */ CueGroup getCurrentCues(); /** Gets the device information. */ @@ -2585,26 +3028,52 @@ public interface Player { * *
For devices with {@link DeviceInfo#PLAYBACK_TYPE_REMOTE remote playback}, the volume of the * remote device is returned. + * + *
This method must only be called if {@link #COMMAND_GET_DEVICE_VOLUME} is {@linkplain + * #getAvailableCommands() available}. */ @IntRange(from = 0) int getDeviceVolume(); - /** Gets whether the device is muted or not. */ + /** + * Gets whether the device is muted or not. + * + *
This method must only be called if {@link #COMMAND_GET_DEVICE_VOLUME} is {@linkplain + * #getAvailableCommands() available}. + */ boolean isDeviceMuted(); /** * Sets the volume of the device. * + *
This method must only be called if {@link #COMMAND_SET_DEVICE_VOLUME} is {@linkplain + * #getAvailableCommands() available}. + * * @param volume The volume to set. */ void setDeviceVolume(@IntRange(from = 0) int volume); - /** Increases the volume of the device. */ + /** + * Increases the volume of the device. + * + *
This method must only be called if {@link #COMMAND_ADJUST_DEVICE_VOLUME} is {@linkplain + * #getAvailableCommands() available}. + */ void increaseDeviceVolume(); - /** Decreases the volume of the device. */ + /** + * Decreases the volume of the device. + * + *
This method must only be called if {@link #COMMAND_ADJUST_DEVICE_VOLUME} is {@linkplain + * #getAvailableCommands() available}. + */ void decreaseDeviceVolume(); - /** Sets the mute state of the device. */ + /** + * Sets the mute state of the device. + * + *
This method must only be called if {@link #COMMAND_ADJUST_DEVICE_VOLUME} is {@linkplain + * #getAvailableCommands() available}. + */ void setDeviceMuted(boolean muted); }