Player.Listener


public interface Player.Listener

Known direct subclasses
AnalyticsCollector

Interface for data collectors that forward analytics events to AnalyticsListeners.

ExoPlayerTestRunner

Helper class to run an ExoPlayer test.

WearUnsuitableOutputPlaybackSuppressionResolverListener

A Player.Listener that launches a system dialog in response to PLAYBACK_SUPPRESSION_REASON_UNSUITABLE_AUDIO_OUTPUT to allow the user to connect a suitable audio output.

Known indirect subclasses
DefaultAnalyticsCollector

Data collector that forwards analytics events to AnalyticsListeners.


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

Public methods

default void

Called when the value of getAudioAttributes changes.

default void

Called when the audio session ID changes.

default void

Called when the value returned from isCommandAvailable changes for at least one Command.

default void
onCues(CueGroup cueGroup)

Called when the value of getCurrentCues changes.

default void

This method is deprecated.

Use onCues instead.

default void

Called when the device information changes

default void
onDeviceVolumeChanged(int volume, boolean muted)

Called when the value of getDeviceVolume or isDeviceMuted changes.

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

Called when one or more player states changed.

default void
onIsLoadingChanged(boolean isLoading)

Called when the player starts or stops loading the source.

default void
onIsPlayingChanged(boolean isPlaying)

Called when the value of isPlaying changes.

default void
@UnstableApi
onLoadingChanged(boolean isLoading)

This method is deprecated.

Use onIsLoadingChanged instead.

default void
onMaxSeekToPreviousPositionChanged(long maxSeekToPreviousPositionMs)

Called when the value of getMaxSeekToPreviousPosition changes.

default void

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

default void

Called when the value of getMediaMetadata changes.

default void

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

default void
onPlayWhenReadyChanged(
    boolean playWhenReady,
    @Player.PlayWhenReadyChangeReason int reason
)

Called when the value returned from getPlayWhenReady changes.

default void

Called when the value of getPlaybackParameters changes.

default void

Called when the value returned from getPlaybackState changes.

default void

Called when the value returned from getPlaybackSuppressionReason changes.

default void

Called when an error occurs.

default void

Called when the PlaybackException returned by getPlayerError changes.

default void
@UnstableApi
onPlayerStateChanged(
    boolean playWhenReady,
    @Player.State int playbackState
)

This method is deprecated.

Use onPlaybackStateChanged and onPlayWhenReadyChanged instead.

default void

Called when the value of getPlaylistMetadata changes.

default void

This method is deprecated.

Use onPositionDiscontinuity instead.

default void
onPositionDiscontinuity(
    Player.PositionInfo oldPosition,
    Player.PositionInfo newPosition,
    @Player.DiscontinuityReason int reason
)

Called when a position discontinuity occurs.

default void

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.

default void

Called when the value of getRepeatMode changes.

default void
onSeekBackIncrementChanged(long seekBackIncrementMs)

Called when the value of getSeekBackIncrement changes.

default void
onSeekForwardIncrementChanged(long seekForwardIncrementMs)

Called when the value of getSeekForwardIncrement changes.

default void
onShuffleModeEnabledChanged(boolean shuffleModeEnabled)

Called when the value of getShuffleModeEnabled changes.

default void
onSkipSilenceEnabledChanged(boolean skipSilenceEnabled)

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

default 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.

default void
onTimelineChanged(
    Timeline timeline,
    @Player.TimelineChangeReason int reason
)

Called when the value of getCurrentTimeline changes.

default void

Called when the value returned from getTrackSelectionParameters changes.

default void

Called when the value of getCurrentTracks changes.

default void

Called each time when getVideoSize changes.

default void
onVolumeChanged(float volume)

Called when the value of getVolume changes.

Public methods

onAudioAttributesChanged

default void onAudioAttributesChanged(AudioAttributes audioAttributes)

Called when the value of getAudioAttributes changes.

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

Parameters
AudioAttributes audioAttributes

The audio attributes.

onAudioSessionIdChanged

@UnstableApi
default void onAudioSessionIdChanged(int audioSessionId)

Called when the audio session ID changes.

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

Parameters
int audioSessionId

The audio session ID.

onAvailableCommandsChanged

default void onAvailableCommandsChanged(Player.Commands availableCommands)

Called when the value returned from isCommandAvailable changes for at least one Command.

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

Parameters
Player.Commands availableCommands

The available Commands.

onCues

default void onCues(CueGroup cueGroup)

Called when the value of getCurrentCues changes.

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

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

onCues

@UnstableApi
default void onCues(List<Cue> cues)

Called when the value of getCurrentCues changes.

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

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

onDeviceInfoChanged

default void onDeviceInfoChanged(DeviceInfo deviceInfo)

Called when the device information changes

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

Parameters
DeviceInfo deviceInfo

The new DeviceInfo.

onDeviceVolumeChanged

default void onDeviceVolumeChanged(int volume, boolean muted)

Called when the value of getDeviceVolume or isDeviceMuted changes.

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

Parameters
int volume

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

boolean muted

Whether the device is muted.

onEvents

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

Called when one or more player states changed.

State changes and events that happen within one Looper 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 player

The Player whose state changed. Use the getters to obtain the latest states.

Player.Events events

The Events that happened in this iteration, indicating which player states changed.

onIsLoadingChanged

default void onIsLoadingChanged(boolean isLoading)

Called when the player starts or stops loading the source.

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

Parameters
boolean isLoading

Whether the source is currently being loaded.

onIsPlayingChanged

default void onIsPlayingChanged(boolean isPlaying)

Called when the value of isPlaying changes.

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

Parameters
boolean isPlaying

Whether the player is playing.

onLoadingChanged

@UnstableApi
default void onLoadingChanged(boolean isLoading)

onMaxSeekToPreviousPositionChanged

default void onMaxSeekToPreviousPositionChanged(long maxSeekToPreviousPositionMs)

Called when the value of getMaxSeekToPreviousPosition changes.

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

Parameters
long maxSeekToPreviousPositionMs

The maximum position for which seekToPrevious seeks to the previous position, in milliseconds.

onMediaItemTransition

default void onMediaItemTransition(
    @Nullable MediaItem mediaItem,
    @Player.MediaItemTransitionReason 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 getCurrentTimeline becomes non-empty or empty.

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

Parameters
@Nullable MediaItem mediaItem

The MediaItem. May be null if the playlist becomes empty.

@Player.MediaItemTransitionReason int reason

The reason for the transition.

onMediaMetadataChanged

default void onMediaMetadataChanged(MediaMetadata mediaMetadata)

Called when the value of getMediaMetadata changes.

This method may be called multiple times in quick succession.

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

Parameters
MediaMetadata mediaMetadata

The combined MediaMetadata.

onMetadata

@UnstableApi
default void onMetadata(Metadata metadata)

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

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

Parameters
Metadata metadata

The metadata.

onPlayWhenReadyChanged

default void onPlayWhenReadyChanged(
    boolean playWhenReady,
    @Player.PlayWhenReadyChangeReason int reason
)

Called when the value returned from getPlayWhenReady changes.

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

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

Parameters
boolean playWhenReady

Whether playback will proceed when ready.

@Player.PlayWhenReadyChangeReason int reason

The PlayWhenReadyChangeReason for the change.

onPlaybackParametersChanged

default void onPlaybackParametersChanged(PlaybackParameters playbackParameters)

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

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

Parameters
PlaybackParameters playbackParameters

The playback parameters.

onPlaybackStateChanged

default void onPlaybackStateChanged(@Player.State int playbackState)

Called when the value returned from getPlaybackState changes.

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

Parameters
@Player.State int playbackState

The new playback State.

onPlaybackSuppressionReasonChanged

default void onPlaybackSuppressionReasonChanged(
    @Player.PlaybackSuppressionReason int playbackSuppressionReason
)

Called when the value returned from getPlaybackSuppressionReason changes.

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

Parameters
@Player.PlaybackSuppressionReason int playbackSuppressionReason

The current PlaybackSuppressionReason.

onPlayerError

default void onPlayerError(PlaybackException error)

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

onEvents will also be called to report this event along with other events that happen in the same Looper 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
PlaybackException error

The error.

onPlayerErrorChanged

default void onPlayerErrorChanged(@Nullable PlaybackException error)

Called when the PlaybackException returned by getPlayerError changes.

onEvents will also be called to report this event along with other events that happen in the same Looper 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
@Nullable PlaybackException error

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

onPlayerStateChanged

@UnstableApi
default void onPlayerStateChanged(
    boolean playWhenReady,
    @Player.State int playbackState
)

onPlaylistMetadataChanged

default void onPlaylistMetadataChanged(MediaMetadata mediaMetadata)

Called when the value of getPlaylistMetadata changes.

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

onPositionDiscontinuity

@UnstableApi
default void onPositionDiscontinuity(@Player.DiscontinuityReason int reason)

onPositionDiscontinuity

default void onPositionDiscontinuity(
    Player.PositionInfo oldPosition,
    Player.PositionInfo newPosition,
    @Player.DiscontinuityReason 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.

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

Parameters
Player.PositionInfo oldPosition

The position before the discontinuity.

Player.PositionInfo newPosition

The position after the discontinuity.

@Player.DiscontinuityReason int reason

The DiscontinuityReason responsible for the discontinuity.

onRenderedFirstFrame

default 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.

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

onRepeatModeChanged

default void onRepeatModeChanged(@Player.RepeatMode int repeatMode)

Called when the value of getRepeatMode changes.

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

Parameters
@Player.RepeatMode int repeatMode

The RepeatMode used for playback.

onSeekBackIncrementChanged

default void onSeekBackIncrementChanged(long seekBackIncrementMs)

Called when the value of getSeekBackIncrement changes.

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

Parameters
long seekBackIncrementMs

The seekBack increment, in milliseconds.

onSeekForwardIncrementChanged

default void onSeekForwardIncrementChanged(long seekForwardIncrementMs)

Called when the value of getSeekForwardIncrement changes.

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

Parameters
long seekForwardIncrementMs

The seekForward increment, in milliseconds.

onShuffleModeEnabledChanged

default void onShuffleModeEnabledChanged(boolean shuffleModeEnabled)

Called when the value of getShuffleModeEnabled changes.

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

Parameters
boolean shuffleModeEnabled

Whether shuffling of media items is enabled.

onSkipSilenceEnabledChanged

default void onSkipSilenceEnabledChanged(boolean skipSilenceEnabled)

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

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

Parameters
boolean skipSilenceEnabled

Whether skipping silences in the audio stream is enabled.

onSurfaceSizeChanged

default 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.

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

Parameters
int width

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

int height

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

onTimelineChanged

default void onTimelineChanged(
    Timeline timeline,
    @Player.TimelineChangeReason int reason
)

Called when the value of 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 onPositionDiscontinuity callback will be triggered.

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

Parameters
Timeline timeline

The latest timeline. Never null, but may be empty.

@Player.TimelineChangeReason int reason

The TimelineChangeReason responsible for this timeline change.

onTrackSelectionParametersChanged

default void onTrackSelectionParametersChanged(TrackSelectionParameters parameters)

Called when the value returned from getTrackSelectionParameters changes.

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

Parameters
TrackSelectionParameters parameters

The new TrackSelectionParameters.

onTracksChanged

default void onTracksChanged(Tracks tracks)

Called when the value of getCurrentTracks changes.

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

Parameters
Tracks tracks

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

onVideoSizeChanged

default void onVideoSizeChanged(VideoSize videoSize)

Called each time when getVideoSize changes.

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

Parameters
VideoSize videoSize

The new size of the video.

onVolumeChanged

default void onVolumeChanged(float volume)

Called when the value of getVolume changes.

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

Parameters
float volume

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