Skip to content

Commit

Permalink
Explicitly document most Player.Listener methods in terms of getters
Browse files Browse the repository at this point in the history
This makes it implicitly clear that if the value of a getter changes due
to a change in command availability then the listener will be invoked,
without needing to explicitly document every command on every listener
method.

#minor-release

PiperOrigin-RevId: 503178383
(cherry picked from commit 280889b)
  • Loading branch information
icbaker authored and christosts committed Jan 25, 2023
1 parent 43677b9 commit 967224c
Showing 1 changed file with 23 additions and 28 deletions.
51 changes: 23 additions & 28 deletions libraries/common/src/main/java/androidx/media3/common/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -605,9 +605,15 @@ private static Commands fromBundle(Bundle bundle) {
}

/**
* Listener of all changes in the Player.
* Listener for changes in a {@link Player}.
*
* <p>All methods have no-op default implementations to allow selective overrides.
*
* <p>If the return value of a {@link Player} getter changes due to a change in {@linkplain
* #onAvailableCommandsChanged(Commands) command availability}, the corresponding listener
* method(s) will be invoked. If the return value of a {@link Player} getter does not change
* because the corresponding command is {@linkplain #onAvailableCommandsChanged(Commands) not
* available}, the corresponding listener method will not be invoked.
*/
interface Listener {

Expand All @@ -617,9 +623,6 @@ interface Listener {
* <p>State changes and events that happen within one {@link Looper} message queue iteration are
* reported together and only after all individual callbacks were triggered.
*
* <p>Only state changes represented by {@linkplain Event events} are reported through this
* method.
*
* <p>Listeners should prefer this method over individual callbacks in the following cases:
*
* <ul>
Expand All @@ -645,7 +648,7 @@ interface Listener {
default void onEvents(Player player, Events events) {}

/**
* Called when the timeline has been refreshed.
* Called when the value of {@link Player#getCurrentTimeline()} changes.
*
* <p>Note that the current {@link MediaItem} or playback position may change as a result of a
* timeline change. If playback can't continue smoothly because of this timeline change, a
Expand All @@ -664,9 +667,8 @@ default void onTimelineChanged(Timeline timeline, @TimelineChangeReason int reas
* Called when playback transitions to a media item or starts repeating a media item according
* to the current {@link #getRepeatMode() repeat mode}.
*
* <p>Note that this callback is also called when the playlist becomes non-empty or empty as a
* consequence of a playlist change or {@linkplain #onAvailableCommandsChanged(Commands) a
* change in available commands}.
* <p>Note that this callback is also called when the value of {@link #getCurrentTimeline()}
* becomes non-empty or empty.
*
* <p>{@link #onEvents(Player, Events)} will also be called to report this event along with
* other events that happen in the same {@link Looper} message queue iteration.
Expand All @@ -678,7 +680,7 @@ default void onMediaItemTransition(
@Nullable MediaItem mediaItem, @MediaItemTransitionReason int reason) {}

/**
* Called when the tracks change.
* Called when the value of {@link Player#getCurrentTracks()} changes.
*
* <p>{@link #onEvents(Player, Events)} will also be called to report this event along with
* other events that happen in the same {@link Looper} message queue iteration.
Expand All @@ -688,14 +690,7 @@ default void onMediaItemTransition(
default void onTracksChanged(Tracks tracks) {}

/**
* Called when the combined {@link MediaMetadata} changes.
*
* <p>The provided {@link MediaMetadata} is a combination of the {@link MediaItem#mediaMetadata
* MediaItem metadata}, the static metadata in the media's {@link Format#metadata Format}, and
* any timed 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.
* Called when the value of {@link Player#getMediaMetadata()} changes.
*
* <p>This method may be called multiple times in quick succession.
*
Expand All @@ -707,7 +702,7 @@ default void onTracksChanged(Tracks tracks) {}
default void onMediaMetadataChanged(MediaMetadata mediaMetadata) {}

/**
* Called when the playlist {@link MediaMetadata} changes.
* Called when the value of {@link Player#getPlaylistMetadata()} changes.
*
* <p>{@link #onEvents(Player, Events)} will also be called to report this event along with
* other events that happen in the same {@link Looper} message queue iteration.
Expand Down Expand Up @@ -876,10 +871,10 @@ default void onPositionDiscontinuity(
PositionInfo oldPosition, PositionInfo newPosition, @DiscontinuityReason int reason) {}

/**
* Called when the current playback parameters change. The playback parameters may change due to
* a call to {@link #setPlaybackParameters(PlaybackParameters)}, or the player itself may change
* them (for example, if audio playback switches to passthrough or offload mode, where speed
* adjustment is no longer possible).
* Called when the value of {@link #getPlaybackParameters()} changes. The playback parameters
* may change due to a call to {@link #setPlaybackParameters(PlaybackParameters)}, or the player
* itself may change them (for example, if audio playback switches to passthrough or offload
* mode, where speed adjustment is no longer possible).
*
* <p>{@link #onEvents(Player, Events)} will also be called to report this event along with
* other events that happen in the same {@link Looper} message queue iteration.
Expand Down Expand Up @@ -940,7 +935,7 @@ default void onSeekProcessed() {}
default void onAudioSessionIdChanged(int audioSessionId) {}

/**
* Called when the audio attributes change.
* Called when the value of {@link #getAudioAttributes()} changes.
*
* <p>{@link #onEvents(Player, Events)} will also be called to report this event along with
* other events that happen in the same {@link Looper} message queue iteration.
Expand All @@ -950,7 +945,7 @@ default void onAudioSessionIdChanged(int audioSessionId) {}
default void onAudioAttributesChanged(AudioAttributes audioAttributes) {}

/**
* Called when the volume changes.
* Called when the value of {@link #getVolume()} changes.
*
* <p>{@link #onEvents(Player, Events)} will also be called to report this event along with
* other events that happen in the same {@link Looper} message queue iteration.
Expand Down Expand Up @@ -980,7 +975,7 @@ default void onSkipSilenceEnabledChanged(boolean skipSilenceEnabled) {}
default void onDeviceInfoChanged(DeviceInfo deviceInfo) {}

/**
* Called when the device volume or mute state changes.
* Called when the value of {@link #getDeviceVolume()} or {@link #isDeviceMuted()} changes.
*
* <p>{@link #onEvents(Player, Events)} will also be called to report this event along with
* other events that happen in the same {@link Looper} message queue iteration.
Expand Down Expand Up @@ -1024,7 +1019,7 @@ default void onSurfaceSizeChanged(int width, int height) {}
default void onRenderedFirstFrame() {}

/**
* Called when there is a change in the {@linkplain Cue cues}.
* Called when the value of {@link #getCurrentCues()} changes.
*
* <p>Both this method and {@link #onCues(CueGroup)} are called when there is a change in the
* cues. You should only implement one or the other.
Expand All @@ -1039,7 +1034,7 @@ default void onRenderedFirstFrame() {}
default void onCues(List<Cue> cues) {}

/**
* Called when there is a change in the {@link CueGroup}.
* Called when the value of {@link #getCurrentCues()} changes.
*
* <p>Both this method and {@link #onCues(List)} are called when there is a change in the cues.
* You should only implement one or the other.
Expand Down Expand Up @@ -1390,7 +1385,7 @@ default void onMetadata(Metadata metadata) {}

/**
* Commands that indicate which method calls are currently permitted on a particular {@code
* Player} instance, and which corresponding {@link Player.Listener} methods will be invoked.
* Player} instance.
*
* <p>The currently available commands can be inspected with {@link #getAvailableCommands()} and
* {@link #isCommandAvailable(int)}.
Expand Down

0 comments on commit 967224c

Please sign in to comment.