public interface

Player.Listener

 androidx.media3.common.Player.Listener

Subclasses:

DebugTextViewHelper, DefaultAnalyticsCollector, AnalyticsCollector, SubtitleView, ExoPlayerTestRunner

Overview

Listener of all changes in the Player.

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

Summary

Methods
public voidonAudioAttributesChanged(AudioAttributes audioAttributes)

Called when the audio attributes change.

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(java.util.List<Cue> cues)

Called when there is a change in the Cues.

public voidonDeviceInfoChanged(DeviceInfo deviceInfo)

Called when the device information changes

public voidonDeviceVolumeChanged(int volume, boolean muted)

Called when the device volume or mute state 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 combined MediaMetadata changes.

public voidonMetadata(Metadata metadata)

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

public voidonPlaybackParametersChanged(PlaybackParameters playbackParameters)

Called when the current playback parameters change.

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 playlist MediaMetadata 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 voidonSeekProcessed()

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 timeline has been refreshed.

public voidonTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections)

Called when the available or selected tracks change.

public voidonTrackSelectionParametersChanged(TrackSelectionParameters parameters)

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

public voidonTracksInfoChanged(TracksInfo tracksInfo)

Called when the available or selected tracks change.

public voidonVideoSizeChanged(VideoSize videoSize)

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

public voidonVolumeChanged(float volume)

Called when the volume 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.

Only state changes represented by events are reported through this method.

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 timeline has been refreshed.

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 playlist becomes non-empty or empty as a consequence of a playlist change.

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(TrackGroupArray trackGroups, TrackSelectionArray trackSelections)

Deprecated: Use Player.Listener.onTracksInfoChanged(TracksInfo) instead.

Called when the available or selected tracks change.

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

Parameters:

trackGroups: The available tracks. Never null, but may be of length zero.
trackSelections: The selected tracks. Never null, but may contain null elements. A concrete implementation may include null elements if it has a fixed number of renderer components, wishes to report a TrackSelection for each of them, and has one or more renderer components that is not assigned any selected tracks.

public void onTracksInfoChanged(TracksInfo tracksInfo)

Called when the available or selected tracks change.

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

Parameters:

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

public void onMediaMetadataChanged(MediaMetadata mediaMetadata)

Called when the combined MediaMetadata changes.

The provided MediaMetadata is a combination of the MediaItem.mediaMetadata and the static and dynamic metadata from the track selections' formats and Player.Listener.onMetadata(Metadata). If a field is populated in the MediaItem.mediaMetadata, it will be prioritised above the same field coming from static or dynamic metadata.

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 playlist MediaMetadata 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 state.

public void onPlayWhenReadyChanged(boolean playWhenReady, int reason)

Called when the value returned from Player.getPlayWhenReady() 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 reason 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 current playback parameters change. 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 onSeekProcessed()

Deprecated: Seeks are processed without delay. Listen to Player.Listener with reason Player.DISCONTINUITY_REASON_SEEK instead.

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 audio attributes change.

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 volume 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 device volume or mute state 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 there's a change in the size of the video 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:

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)

Called when there is a change in the Cues.

cues is in ascending order of priority. If any of the cue boxes overlap when displayed, the Cue nearer the end of the list should be shown on top.

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

Parameters:

cues: The Cues. May be empty.

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.