public interface

Player.Listener

 androidx.media3.common.Player.Listener

Subclasses:

DefaultAnalyticsCollector, AnalyticsCollector, WearUnsuitableOutputPlaybackSuppressionResolverListener, ExoPlayerTestRunner

Overview

Listener for changes in a Player.

All methods have no-op default implementations to allow selective overrides.

If the return value of a Player getter changes due to a change in command availability, the corresponding listener method(s) will be invoked. If the return value of a Player getter does not change because the corresponding command is not available, the corresponding listener method will not be invoked.

Summary

Methods
public voidonAudioAttributesChanged(AudioAttributes audioAttributes)

Called when the value of Player.getAudioAttributes() changes.

public voidonAudioSessionIdChanged(int audioSessionId)

Called when the audio session ID changes.

public voidonAvailableCommandsChanged(Player.Commands availableCommands)

Called when the value returned from Player.isCommandAvailable(int) changes for at least one Player.Command.

public voidonCues(CueGroup cueGroup)

Called when the value of Player.getCurrentCues() changes.

public voidonCues(java.util.List<Cue> cues)

Called when the value of Player.getCurrentCues() changes.

public voidonDeviceInfoChanged(DeviceInfo deviceInfo)

Called when the device information changes

public voidonDeviceVolumeChanged(int volume, boolean muted)

Called when the value of Player.getDeviceVolume() or Player.isDeviceMuted() changes.

public voidonEvents(Player player, Player.Events events)

Called when one or more player states changed.

public voidonIsLoadingChanged(boolean isLoading)

Called when the player starts or stops loading the source.

public voidonIsPlayingChanged(boolean isPlaying)

Called when the value of Player.isPlaying() changes.

public voidonLoadingChanged(boolean isLoading)

public voidonMaxSeekToPreviousPositionChanged(long maxSeekToPreviousPositionMs)

Called when the value of Player.getMaxSeekToPreviousPosition() changes.

public voidonMediaItemTransition(MediaItem mediaItem, int reason)

Called when playback transitions to a media item or starts repeating a media item according to the current repeat mode.

public voidonMediaMetadataChanged(MediaMetadata mediaMetadata)

Called when the value of Player.getMediaMetadata() changes.

public voidonMetadata(Metadata metadata)

Called when there is metadata associated with the current playback time.

public voidonPlaybackParametersChanged(PlaybackParameters playbackParameters)

Called when the value of Player.getPlaybackParameters() changes.

public voidonPlaybackStateChanged(int playbackState)

Called when the value returned from Player.getPlaybackState() changes.

public voidonPlaybackSuppressionReasonChanged(int playbackSuppressionReason)

Called when the value returned from Player.getPlaybackSuppressionReason() changes.

public voidonPlayerError(PlaybackException error)

Called when an error occurs.

public voidonPlayerErrorChanged(PlaybackException error)

Called when the PlaybackException returned by Player.getPlayerError() changes.

public voidonPlayerStateChanged(boolean playWhenReady, int playbackState)

public voidonPlaylistMetadataChanged(MediaMetadata mediaMetadata)

Called when the value of Player.getPlaylistMetadata() changes.

public voidonPlayWhenReadyChanged(boolean playWhenReady, int reason)

Called when the value returned from Player.getPlayWhenReady() changes.

public voidonPositionDiscontinuity(int reason)

public voidonPositionDiscontinuity(Player.PositionInfo oldPosition, Player.PositionInfo newPosition, int reason)

Called when a position discontinuity occurs.

public voidonRenderedFirstFrame()

Called when a frame is rendered for the first time since setting the surface, or since the renderer was reset, or since the stream being rendered was changed.

public voidonRepeatModeChanged(int repeatMode)

Called when the value of Player.getRepeatMode() changes.

public voidonSeekBackIncrementChanged(long seekBackIncrementMs)

Called when the value of Player.getSeekBackIncrement() changes.

public voidonSeekForwardIncrementChanged(long seekForwardIncrementMs)

Called when the value of Player.getSeekForwardIncrement() changes.

public voidonShuffleModeEnabledChanged(boolean shuffleModeEnabled)

Called when the value of Player.getShuffleModeEnabled() changes.

public voidonSkipSilenceEnabledChanged(boolean skipSilenceEnabled)

Called when skipping silences is enabled or disabled in the audio stream.

public voidonSurfaceSizeChanged(int width, int height)

Called each time there's a change in the size of the surface onto which the video is being rendered.

public voidonTimelineChanged(Timeline timeline, int reason)

Called when the value of Player.getCurrentTimeline() changes.

public voidonTracksChanged(Tracks tracks)

Called when the value of Player.getCurrentTracks() changes.

public voidonTrackSelectionParametersChanged(TrackSelectionParameters parameters)

Called when the value returned from Player.getTrackSelectionParameters() changes.

public voidonVideoSizeChanged(VideoSize videoSize)

Called each time when Player.getVideoSize() changes.

public voidonVolumeChanged(float volume)

Called when the value of Player.getVolume() changes.

Methods

public void onEvents(Player player, Player.Events events)

Called when one or more player states changed.

State changes and events that happen within one message queue iteration are reported together and only after all individual callbacks were triggered.

Listeners should prefer this method over individual callbacks in the following cases:

Parameters:

player: The Player whose state changed. Use the getters to obtain the latest states.
events: The Player.Events that happened in this iteration, indicating which player states changed.

public void onTimelineChanged(Timeline timeline, int reason)

Called when the value of Player.getCurrentTimeline() changes.

Note that the current 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 separate Player.Listener callback will be triggered.

Player.Listener will also be called to report this event along with other events that happen in the same message queue iteration.

Parameters:

timeline: The latest timeline. Never null, but may be empty.
reason: The Player.TimelineChangeReason responsible for this timeline change.

public void onMediaItemTransition(MediaItem mediaItem, int reason)

Called when playback transitions to a media item or starts repeating a media item according to the current repeat mode.

Note that this callback is also called when the value of Player.getCurrentTimeline() becomes non-empty or empty.

Player.Listener will also be called to report this event along with other events that happen in the same message queue iteration.

Parameters:

mediaItem: The MediaItem. May be null if the playlist becomes empty.
reason: The reason for the transition.

public void onTracksChanged(Tracks tracks)

Called when the value of Player.getCurrentTracks() changes.

Player.Listener will also be called to report this event along with other events that happen in the same message queue iteration.

Parameters:

tracks: The available tracks information. Never null, but may be of length zero.

public void onMediaMetadataChanged(MediaMetadata mediaMetadata)

Called when the value of Player.getMediaMetadata() changes.

This method may be called multiple times in quick succession.

Player.Listener will also be called to report this event along with other events that happen in the same message queue iteration.

Parameters:

mediaMetadata: The combined MediaMetadata.

public void onPlaylistMetadataChanged(MediaMetadata mediaMetadata)

Called when the value of Player.getPlaylistMetadata() changes.

Player.Listener will also be called to report this event along with other events that happen in the same message queue iteration.

public void onIsLoadingChanged(boolean isLoading)

Called when the player starts or stops loading the source.

Player.Listener will also be called to report this event along with other events that happen in the same message queue iteration.

Parameters:

isLoading: Whether the source is currently being loaded.

public void onLoadingChanged(boolean isLoading)

Deprecated: Use Player.Listener.onIsLoadingChanged(boolean) instead.

public void onAvailableCommandsChanged(Player.Commands availableCommands)

Called when the value returned from Player.isCommandAvailable(int) changes for at least one Player.Command.

Player.Listener will also be called to report this event along with other events that happen in the same message queue iteration.

Parameters:

availableCommands: The available Player.Commands.

public void onTrackSelectionParametersChanged(TrackSelectionParameters parameters)

Called when the value returned from Player.getTrackSelectionParameters() changes.

Player.Listener will also be called to report this event along with other events that happen in the same message queue iteration.

Parameters:

parameters: The new TrackSelectionParameters.

public void onPlayerStateChanged(boolean playWhenReady, int playbackState)

Deprecated: Use Player.Listener.onPlaybackStateChanged(int) and Player.Listener.onPlayWhenReadyChanged(boolean, int) instead.

public void onPlaybackStateChanged(int playbackState)

Called when the value returned from Player.getPlaybackState() changes.

Player.Listener will also be called to report this event along with other events that happen in the same message queue iteration.

Parameters:

playbackState: The new playback Player.State.

public void onPlayWhenReadyChanged(boolean playWhenReady, int reason)

Called when the value returned from Player.getPlayWhenReady() changes.

The current playWhenReady value may be re-reported if the reason for this value changes.

Player.Listener will also be called to report this event along with other events that happen in the same message queue iteration.

Parameters:

playWhenReady: Whether playback will proceed when ready.
reason: The Player.PlayWhenReadyChangeReason for the change.

public void onPlaybackSuppressionReasonChanged(int playbackSuppressionReason)

Called when the value returned from Player.getPlaybackSuppressionReason() changes.

Player.Listener will also be called to report this event along with other events that happen in the same message queue iteration.

Parameters:

playbackSuppressionReason: The current Player.PlaybackSuppressionReason.

public void onIsPlayingChanged(boolean isPlaying)

Called when the value of Player.isPlaying() changes.

Player.Listener will also be called to report this event along with other events that happen in the same message queue iteration.

Parameters:

isPlaying: Whether the player is playing.

public void onRepeatModeChanged(int repeatMode)

Called when the value of Player.getRepeatMode() changes.

Player.Listener will also be called to report this event along with other events that happen in the same message queue iteration.

Parameters:

repeatMode: The Player.RepeatMode used for playback.

public void onShuffleModeEnabledChanged(boolean shuffleModeEnabled)

Called when the value of Player.getShuffleModeEnabled() changes.

Player.Listener will also be called to report this event along with other events that happen in the same message queue iteration.

Parameters:

shuffleModeEnabled: Whether shuffling of media items is enabled.

public void onPlayerError(PlaybackException error)

Called when an error occurs. The playback state will transition to Player.STATE_IDLE immediately after this method is called. The player instance can still be used, and Player.release() must still be called on the player should it no longer be required.

Player.Listener will also be called to report this event along with other events that happen in the same message queue iteration.

Implementations of Player may pass an instance of a subclass of PlaybackException to this method in order to include more information about the error.

Parameters:

error: The error.

public void onPlayerErrorChanged(PlaybackException error)

Called when the PlaybackException returned by Player.getPlayerError() changes.

Player.Listener will also be called to report this event along with other events that happen in the same message queue iteration.

Implementations of Player may pass an instance of a subclass of PlaybackException to this method in order to include more information about the error.

Parameters:

error: The new error, or null if the error is being cleared.

public void onPositionDiscontinuity(int reason)

Deprecated: Use Player.Listener instead.

public void onPositionDiscontinuity(Player.PositionInfo oldPosition, Player.PositionInfo newPosition, int reason)

Called when a position discontinuity occurs.

A position discontinuity occurs when the playing period changes, the playback position jumps within the period currently being played, or when the playing period has been skipped or removed.

Player.Listener will also be called to report this event along with other events that happen in the same message queue iteration.

Parameters:

oldPosition: The position before the discontinuity.
newPosition: The position after the discontinuity.
reason: The Player.DiscontinuityReason responsible for the discontinuity.

public void onPlaybackParametersChanged(PlaybackParameters playbackParameters)

Called when the value of Player.getPlaybackParameters() changes. The playback parameters may change due to a call to Player.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).

Player.Listener will also be called to report this event along with other events that happen in the same message queue iteration.

Parameters:

playbackParameters: The playback parameters.

public void onSeekBackIncrementChanged(long seekBackIncrementMs)

Called when the value of Player.getSeekBackIncrement() changes.

Player.Listener will also be called to report this event along with other events that happen in the same message queue iteration.

Parameters:

seekBackIncrementMs: The Player.seekBack() increment, in milliseconds.

public void onSeekForwardIncrementChanged(long seekForwardIncrementMs)

Called when the value of Player.getSeekForwardIncrement() changes.

Player.Listener will also be called to report this event along with other events that happen in the same message queue iteration.

Parameters:

seekForwardIncrementMs: The Player.seekForward() increment, in milliseconds.

public void onMaxSeekToPreviousPositionChanged(long maxSeekToPreviousPositionMs)

Called when the value of Player.getMaxSeekToPreviousPosition() changes.

Player.Listener will also be called to report this event along with other events that happen in the same message queue iteration.

Parameters:

maxSeekToPreviousPositionMs: The maximum position for which Player.seekToPrevious() seeks to the previous position, in milliseconds.

public void onAudioSessionIdChanged(int audioSessionId)

Called when the audio session ID changes.

Player.Listener will also be called to report this event along with other events that happen in the same message queue iteration.

Parameters:

audioSessionId: The audio session ID.

public void onAudioAttributesChanged(AudioAttributes audioAttributes)

Called when the value of Player.getAudioAttributes() changes.

Player.Listener will also be called to report this event along with other events that happen in the same message queue iteration.

Parameters:

audioAttributes: The audio attributes.

public void onVolumeChanged(float volume)

Called when the value of Player.getVolume() changes.

Player.Listener will also be called to report this event along with other events that happen in the same message queue iteration.

Parameters:

volume: The new volume, with 0 being silence and 1 being unity gain.

public void onSkipSilenceEnabledChanged(boolean skipSilenceEnabled)

Called when skipping silences is enabled or disabled in the audio stream.

Player.Listener will also be called to report this event along with other events that happen in the same message queue iteration.

Parameters:

skipSilenceEnabled: Whether skipping silences in the audio stream is enabled.

public void onDeviceInfoChanged(DeviceInfo deviceInfo)

Called when the device information changes

Player.Listener will also be called to report this event along with other events that happen in the same message queue iteration.

Parameters:

deviceInfo: The new DeviceInfo.

public void onDeviceVolumeChanged(int volume, boolean muted)

Called when the value of Player.getDeviceVolume() or Player.isDeviceMuted() changes.

Player.Listener will also be called to report this event along with other events that happen in the same message queue iteration.

Parameters:

volume: The new device volume, with 0 being silence and 1 being unity gain.
muted: Whether the device is muted.

public void onVideoSizeChanged(VideoSize videoSize)

Called each time when Player.getVideoSize() changes.

Player.Listener will also be called to report this event along with other events that happen in the same message queue iteration.

Parameters:

videoSize: The new size of the video.

public void onSurfaceSizeChanged(int width, int height)

Called each time there's a change in the size of the surface onto which the video is being rendered.

Player.Listener will also be called to report this event along with other events that happen in the same message queue iteration.

Parameters:

width: The surface width in pixels. May be C.LENGTH_UNSET if unknown, or 0 if the video is not rendered onto a surface.
height: The surface height in pixels. May be C.LENGTH_UNSET if unknown, or 0 if the video is not rendered onto a surface.

public void onRenderedFirstFrame()

Called when a frame is rendered for the first time since setting the surface, or since the renderer was reset, or since the stream being rendered was changed.

Player.Listener will also be called to report this event along with other events that happen in the same message queue iteration.

public void onCues(java.util.List<Cue> cues)

Deprecated: Use Player.Listener.onCues(CueGroup) instead.

Called when the value of Player.getCurrentCues() changes.

Both this method and Player.Listener.onCues(CueGroup) are called when there is a change in the cues. You should only implement one or the other.

Player.Listener will also be called to report this event along with other events that happen in the same message queue iteration.

public void onCues(CueGroup cueGroup)

Called when the value of Player.getCurrentCues() changes.

Both this method and Player.Listener.onCues(List) are called when there is a change in the cues. You should only implement one or the other.

Player.Listener will also be called to report this event along with other events that happen in the same message queue iteration.

public void onMetadata(Metadata metadata)

Called when there is metadata associated with the current playback time.

Player.Listener will also be called to report this event along with other events that happen in the same message queue iteration.

Parameters:

metadata: The metadata.