Player.Listener
public interface Player.Listener
AnalyticsCollector |
Interface for data collectors that forward analytics events to |
ExoPlayerTestRunner |
Helper class to run an ExoPlayer test. |
WearUnsuitableOutputPlaybackSuppressionResolverListener |
A |
DefaultAnalyticsCollector |
Data collector that forwards analytics events to |
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 |
onAudioAttributesChanged(AudioAttributes audioAttributes)Called when the value of |
default void |
@UnstableApiCalled when the audio session ID changes. |
default void |
onAvailableCommandsChanged(Player.Commands availableCommands)Called when the value returned from |
default void |
Called when the value of |
default void |
@UnstableApiThis method is deprecated. Use |
default void |
onDeviceInfoChanged(DeviceInfo deviceInfo)Called when the device information changes |
default void |
onDeviceVolumeChanged(int volume, boolean muted)Called when the value of |
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 |
default void |
@UnstableApiThis method is deprecated. Use |
default void |
onMaxSeekToPreviousPositionChanged(long maxSeekToPreviousPositionMs)Called when the value of |
default void |
onMediaItemTransition(Called when playback transitions to a media item or starts repeating a media item according to the current |
default void |
onMediaMetadataChanged(MediaMetadata mediaMetadata)Called when the value of |
default void |
@UnstableApiCalled when there is metadata associated with the current playback time. |
default void |
onPlayWhenReadyChanged(Called when the value returned from |
default void |
onPlaybackParametersChanged(PlaybackParameters playbackParameters)Called when the value of |
default void |
onPlaybackStateChanged(@Player.State int playbackState)Called when the value returned from |
default void |
onPlaybackSuppressionReasonChanged(Called when the value returned from |
default void |
onPlayerError(PlaybackException error)Called when an error occurs. |
default void |
Called when the |
default void |
@UnstableApiThis method is deprecated. Use |
default void |
onPlaylistMetadataChanged(MediaMetadata mediaMetadata)Called when the value of |
default void |
@UnstableApiThis method is deprecated. Use |
default void |
onPositionDiscontinuity(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 |
onRepeatModeChanged(@Player.RepeatMode int repeatMode)Called when the value of |
default void |
onSeekBackIncrementChanged(long seekBackIncrementMs)Called when the value of |
default void |
onSeekForwardIncrementChanged(long seekForwardIncrementMs)Called when the value of |
default void |
onShuffleModeEnabledChanged(boolean shuffleModeEnabled)Called when the value of |
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(Called when the value of |
default void |
Called when the value returned from |
default void |
onTracksChanged(Tracks tracks)Called when the value of |
default void |
onVideoSizeChanged(VideoSize videoSize)Called each time when |
default void |
onVolumeChanged(float volume)Called when the value of |
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 |
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 voidonCues(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 |
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:
- They intend to trigger the same logic for multiple events (e.g. when updating a UI for both
onPlaybackStateChangedandonPlayWhenReadyChanged). - They need access to the
Playerobject to trigger further events (e.g. to callseekToafter aonMediaItemTransition). - They intend to use multiple state values together or in combination with
Playergetter methods. For example usinggetCurrentMediaItemIndexwith thetimelineprovided inonTimelineChangedis only safe from within this method. - They are interested in events that logically happened together (e.g
onPlaybackStateChangedtoSTATE_BUFFERINGbecause ofonMediaItemTransition).
| Parameters | |
|---|---|
Player player |
The |
Player.Events events |
The |
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. |
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 |
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 |
@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 |
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 |
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 |
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 |
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 voidonPlayerStateChanged(
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 voidonPositionDiscontinuity(@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 |
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 |
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 |
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 |
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 |
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 |
int height |
The surface height in pixels. May be |
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 |
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 |
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. |