Interface Player.Listener
-
- All Known Subinterfaces:
AnalyticsCollector
- All Known Implementing Classes:
DefaultAnalyticsCollector
,ExoPlayerTestRunner
- Enclosing interface:
- Player
public static interface Player.Listener
Listener for changes in aPlayer
.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 aPlayer
getter does not change because the corresponding command is not available, the corresponding listener method will not be invoked.
-
-
Method Summary
All Methods Instance Methods Default Methods Deprecated Methods Modifier and Type Method Description default void
onAudioAttributesChanged(AudioAttributes audioAttributes)
Called when the value ofPlayer.getAudioAttributes()
changes.default void
onAudioSessionIdChanged(int audioSessionId)
Called when the audio session ID changes.default void
onAvailableCommandsChanged(Player.Commands availableCommands)
Called when the value returned fromPlayer.isCommandAvailable(int)
changes for at least onePlayer.Command
.default void
onCues(CueGroup cueGroup)
Called when the value ofPlayer.getCurrentCues()
changes.default void
onCues(List<Cue> cues)
Deprecated.UseonCues(CueGroup)
instead.default void
onDeviceInfoChanged(DeviceInfo deviceInfo)
Called when the device information changesdefault void
onDeviceVolumeChanged(int volume, boolean muted)
Called when the value ofPlayer.getDeviceVolume()
orPlayer.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 ofPlayer.isPlaying()
changes.default void
onLoadingChanged(boolean isLoading)
Deprecated.UseonIsLoadingChanged(boolean)
instead.default void
onMaxSeekToPreviousPositionChanged(long maxSeekToPreviousPositionMs)
Called when the value ofPlayer.getMaxSeekToPreviousPosition()
changes.default void
onMediaItemTransition(MediaItem mediaItem, @com.google.android.exoplayer2.Player.MediaItemTransitionReason int reason)
Called when playback transitions to a media item or starts repeating a media item according to the currentrepeat mode
.default void
onMediaMetadataChanged(MediaMetadata mediaMetadata)
Called when the value ofPlayer.getMediaMetadata()
changes.default void
onMetadata(Metadata metadata)
Called when there is metadata associated with the current playback time.default void
onPlaybackParametersChanged(PlaybackParameters playbackParameters)
Called when the value ofPlayer.getPlaybackParameters()
changes.default void
onPlaybackStateChanged(@com.google.android.exoplayer2.Player.State int playbackState)
Called when the value returned fromPlayer.getPlaybackState()
changes.default void
onPlaybackSuppressionReasonChanged(@com.google.android.exoplayer2.Player.PlaybackSuppressionReason int playbackSuppressionReason)
Called when the value returned fromPlayer.getPlaybackSuppressionReason()
changes.default void
onPlayerError(PlaybackException error)
Called when an error occurs.default void
onPlayerErrorChanged(PlaybackException error)
Called when thePlaybackException
returned byPlayer.getPlayerError()
changes.default void
onPlayerStateChanged(boolean playWhenReady, @com.google.android.exoplayer2.Player.State int playbackState)
Deprecated.UseonPlaybackStateChanged(int)
andonPlayWhenReadyChanged(boolean, int)
instead.default void
onPlaylistMetadataChanged(MediaMetadata mediaMetadata)
Called when the value ofPlayer.getPlaylistMetadata()
changes.default void
onPlayWhenReadyChanged(boolean playWhenReady, @com.google.android.exoplayer2.Player.PlayWhenReadyChangeReason int reason)
Called when the value returned fromPlayer.getPlayWhenReady()
changes.default void
onPositionDiscontinuity(@com.google.android.exoplayer2.Player.DiscontinuityReason int reason)
Deprecated.default void
onPositionDiscontinuity(Player.PositionInfo oldPosition, Player.PositionInfo newPosition, @com.google.android.exoplayer2.Player.DiscontinuityReason int reason)
Called when a position discontinuity occurs.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.default void
onRepeatModeChanged(@com.google.android.exoplayer2.Player.RepeatMode int repeatMode)
Called when the value ofPlayer.getRepeatMode()
changes.default void
onSeekBackIncrementChanged(long seekBackIncrementMs)
Called when the value ofPlayer.getSeekBackIncrement()
changes.default void
onSeekForwardIncrementChanged(long seekForwardIncrementMs)
Called when the value ofPlayer.getSeekForwardIncrement()
changes.default void
onShuffleModeEnabledChanged(boolean shuffleModeEnabled)
Called when the value ofPlayer.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, @com.google.android.exoplayer2.Player.TimelineChangeReason int reason)
Called when the value ofPlayer.getCurrentTimeline()
changes.default void
onTracksChanged(Tracks tracks)
Called when the value ofPlayer.getCurrentTracks()
changes.default void
onTrackSelectionParametersChanged(TrackSelectionParameters parameters)
Called when the value returned fromPlayer.getTrackSelectionParameters()
changes.default void
onVideoSizeChanged(VideoSize videoSize)
Called each time whenPlayer.getVideoSize()
changes.default void
onVolumeChanged(float volume)
Called when the value ofPlayer.getVolume()
changes.
-
-
-
Method Detail
-
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
onPlaybackStateChanged(int)
andonPlayWhenReadyChanged(boolean, int)
). - They need access to the
Player
object to trigger further events (e.g. to callPlayer.seekTo(long)
after aonMediaItemTransition(MediaItem, int)
). - They intend to use multiple state values together or in combination with
Player
getter methods. For example usingPlayer.getCurrentMediaItemIndex()
with thetimeline
provided inonTimelineChanged(Timeline, int)
is only safe from within this method. - They are interested in events that logically happened together (e.g
onPlaybackStateChanged(int)
toPlayer.STATE_BUFFERING
because ofonMediaItemTransition(MediaItem, int)
).
- Parameters:
player
- ThePlayer
whose state changed. Use the getters to obtain the latest states.events
- ThePlayer.Events
that happened in this iteration, indicating which player states changed.
- They intend to trigger the same logic for multiple events (e.g. when updating a UI for
both
-
onTimelineChanged
default void onTimelineChanged(Timeline timeline, @TimelineChangeReason @com.google.android.exoplayer2.Player.TimelineChangeReason int reason)
Called when the value ofPlayer.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 separateonPositionDiscontinuity(PositionInfo, PositionInfo, int)
callback will be triggered.onEvents(Player, Events)
will also be called to report this event along with other events that happen in the sameLooper
message queue iteration.- Parameters:
timeline
- The latest timeline. Never null, but may be empty.reason
- ThePlayer.TimelineChangeReason
responsible for this timeline change.
-
onMediaItemTransition
default void onMediaItemTransition(@Nullable MediaItem mediaItem, @MediaItemTransitionReason @com.google.android.exoplayer2.Player.MediaItemTransitionReason int reason)
Called when playback transitions to a media item or starts repeating a media item according to the currentrepeat mode
.Note that this callback is also called when the value of
Player.getCurrentTimeline()
becomes non-empty or empty.onEvents(Player, Events)
will also be called to report this event along with other events that happen in the sameLooper
message queue iteration.- Parameters:
mediaItem
- TheMediaItem
. May be null if the playlist becomes empty.reason
- The reason for the transition.
-
onTracksChanged
default void onTracksChanged(Tracks tracks)
Called when the value ofPlayer.getCurrentTracks()
changes.onEvents(Player, Events)
will also be called to report this event along with other events that happen in the sameLooper
message queue iteration.- Parameters:
tracks
- The available tracks information. Never null, but may be of length zero.
-
onMediaMetadataChanged
default void onMediaMetadataChanged(MediaMetadata mediaMetadata)
Called when the value ofPlayer.getMediaMetadata()
changes.This method may be called multiple times in quick succession.
onEvents(Player, Events)
will also be called to report this event along with other events that happen in the sameLooper
message queue iteration.- Parameters:
mediaMetadata
- The combinedMediaMetadata
.
-
onPlaylistMetadataChanged
default void onPlaylistMetadataChanged(MediaMetadata mediaMetadata)
Called when the value ofPlayer.getPlaylistMetadata()
changes.onEvents(Player, Events)
will also be called to report this event along with other events that happen in the sameLooper
message queue iteration.
-
onIsLoadingChanged
default void onIsLoadingChanged(boolean isLoading)
Called when the player starts or stops loading the source.onEvents(Player, Events)
will also be called to report this event along with other events that happen in the sameLooper
message queue iteration.- Parameters:
isLoading
- Whether the source is currently being loaded.
-
onLoadingChanged
@Deprecated default void onLoadingChanged(boolean isLoading)
Deprecated.UseonIsLoadingChanged(boolean)
instead.
-
onAvailableCommandsChanged
default void onAvailableCommandsChanged(Player.Commands availableCommands)
Called when the value returned fromPlayer.isCommandAvailable(int)
changes for at least onePlayer.Command
.onEvents(Player, Events)
will also be called to report this event along with other events that happen in the sameLooper
message queue iteration.- Parameters:
availableCommands
- The availablePlayer.Commands
.
-
onTrackSelectionParametersChanged
default void onTrackSelectionParametersChanged(TrackSelectionParameters parameters)
Called when the value returned fromPlayer.getTrackSelectionParameters()
changes.onEvents(Player, Events)
will also be called to report this event along with other events that happen in the sameLooper
message queue iteration.- Parameters:
parameters
- The newTrackSelectionParameters
.
-
onPlayerStateChanged
@Deprecated default void onPlayerStateChanged(boolean playWhenReady, @State @com.google.android.exoplayer2.Player.State int playbackState)
Deprecated.UseonPlaybackStateChanged(int)
andonPlayWhenReadyChanged(boolean, int)
instead.
-
onPlaybackStateChanged
default void onPlaybackStateChanged(@State @com.google.android.exoplayer2.Player.State int playbackState)
Called when the value returned fromPlayer.getPlaybackState()
changes.onEvents(Player, Events)
will also be called to report this event along with other events that happen in the sameLooper
message queue iteration.- Parameters:
playbackState
- The new playbackPlayer.State
.
-
onPlayWhenReadyChanged
default void onPlayWhenReadyChanged(boolean playWhenReady, @PlayWhenReadyChangeReason @com.google.android.exoplayer2.Player.PlayWhenReadyChangeReason int reason)
Called when the value returned fromPlayer.getPlayWhenReady()
changes.onEvents(Player, Events)
will also be called to report this event along with other events that happen in the sameLooper
message queue iteration.- Parameters:
playWhenReady
- Whether playback will proceed when ready.reason
- ThePlayer.PlayWhenReadyChangeReason
for the change.
-
onPlaybackSuppressionReasonChanged
default void onPlaybackSuppressionReasonChanged(@PlaybackSuppressionReason @com.google.android.exoplayer2.Player.PlaybackSuppressionReason int playbackSuppressionReason)
Called when the value returned fromPlayer.getPlaybackSuppressionReason()
changes.onEvents(Player, Events)
will also be called to report this event along with other events that happen in the sameLooper
message queue iteration.- Parameters:
playbackSuppressionReason
- The currentPlayer.PlaybackSuppressionReason
.
-
onIsPlayingChanged
default void onIsPlayingChanged(boolean isPlaying)
Called when the value ofPlayer.isPlaying()
changes.onEvents(Player, Events)
will also be called to report this event along with other events that happen in the sameLooper
message queue iteration.- Parameters:
isPlaying
- Whether the player is playing.
-
onRepeatModeChanged
default void onRepeatModeChanged(@RepeatMode @com.google.android.exoplayer2.Player.RepeatMode int repeatMode)
Called when the value ofPlayer.getRepeatMode()
changes.onEvents(Player, Events)
will also be called to report this event along with other events that happen in the sameLooper
message queue iteration.- Parameters:
repeatMode
- ThePlayer.RepeatMode
used for playback.
-
onShuffleModeEnabledChanged
default void onShuffleModeEnabledChanged(boolean shuffleModeEnabled)
Called when the value ofPlayer.getShuffleModeEnabled()
changes.onEvents(Player, Events)
will also be called to report this event along with other events that happen in the sameLooper
message queue iteration.- Parameters:
shuffleModeEnabled
- Whether shuffling of media items is enabled.
-
onPlayerError
default void onPlayerError(PlaybackException error)
Called when an error occurs. The playback state will transition toPlayer.STATE_IDLE
immediately after this method is called. The player instance can still be used, andPlayer.release()
must still be called on the player should it no longer be required.onEvents(Player, Events)
will also be called to report this event along with other events that happen in the sameLooper
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.
-
onPlayerErrorChanged
default void onPlayerErrorChanged(@Nullable PlaybackException error)
Called when thePlaybackException
returned byPlayer.getPlayerError()
changes.onEvents(Player, Events)
will also be called to report this event along with other events that happen in the sameLooper
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.
-
onPositionDiscontinuity
@Deprecated default void onPositionDiscontinuity(@DiscontinuityReason @com.google.android.exoplayer2.Player.DiscontinuityReason int reason)
Deprecated.
-
onPositionDiscontinuity
default void onPositionDiscontinuity(Player.PositionInfo oldPosition, Player.PositionInfo newPosition, @DiscontinuityReason @com.google.android.exoplayer2.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(Player, Events)
will also be called to report this event along with other events that happen in the sameLooper
message queue iteration.- Parameters:
oldPosition
- The position before the discontinuity.newPosition
- The position after the discontinuity.reason
- ThePlayer.DiscontinuityReason
responsible for the discontinuity.
-
onPlaybackParametersChanged
default void onPlaybackParametersChanged(PlaybackParameters playbackParameters)
Called when the value ofPlayer.getPlaybackParameters()
changes. The playback parameters may change due to a call toPlayer.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).onEvents(Player, Events)
will also be called to report this event along with other events that happen in the sameLooper
message queue iteration.- Parameters:
playbackParameters
- The playback parameters.
-
onSeekBackIncrementChanged
default void onSeekBackIncrementChanged(long seekBackIncrementMs)
Called when the value ofPlayer.getSeekBackIncrement()
changes.onEvents(Player, Events)
will also be called to report this event along with other events that happen in the sameLooper
message queue iteration.- Parameters:
seekBackIncrementMs
- ThePlayer.seekBack()
increment, in milliseconds.
-
onSeekForwardIncrementChanged
default void onSeekForwardIncrementChanged(long seekForwardIncrementMs)
Called when the value ofPlayer.getSeekForwardIncrement()
changes.onEvents(Player, Events)
will also be called to report this event along with other events that happen in the sameLooper
message queue iteration.- Parameters:
seekForwardIncrementMs
- ThePlayer.seekForward()
increment, in milliseconds.
-
onMaxSeekToPreviousPositionChanged
default void onMaxSeekToPreviousPositionChanged(long maxSeekToPreviousPositionMs)
Called when the value ofPlayer.getMaxSeekToPreviousPosition()
changes.onEvents(Player, Events)
will also be called to report this event along with other events that happen in the sameLooper
message queue iteration.- Parameters:
maxSeekToPreviousPositionMs
- The maximum position for whichPlayer.seekToPrevious()
seeks to the previous position, in milliseconds.
-
onAudioSessionIdChanged
default void onAudioSessionIdChanged(int audioSessionId)
Called when the audio session ID changes.onEvents(Player, Events)
will also be called to report this event along with other events that happen in the sameLooper
message queue iteration.- Parameters:
audioSessionId
- The audio session ID.
-
onAudioAttributesChanged
default void onAudioAttributesChanged(AudioAttributes audioAttributes)
Called when the value ofPlayer.getAudioAttributes()
changes.onEvents(Player, Events)
will also be called to report this event along with other events that happen in the sameLooper
message queue iteration.- Parameters:
audioAttributes
- The audio attributes.
-
onVolumeChanged
default void onVolumeChanged(float volume)
Called when the value ofPlayer.getVolume()
changes.onEvents(Player, Events)
will also be called to report this event along with other events that happen in the sameLooper
message queue iteration.- Parameters:
volume
- The new volume, with 0 being silence and 1 being unity gain.
-
onSkipSilenceEnabledChanged
default void onSkipSilenceEnabledChanged(boolean skipSilenceEnabled)
Called when skipping silences is enabled or disabled in the audio stream.onEvents(Player, Events)
will also be called to report this event along with other events that happen in the sameLooper
message queue iteration.- Parameters:
skipSilenceEnabled
- Whether skipping silences in the audio stream is enabled.
-
onDeviceInfoChanged
default void onDeviceInfoChanged(DeviceInfo deviceInfo)
Called when the device information changesonEvents(Player, Events)
will also be called to report this event along with other events that happen in the sameLooper
message queue iteration.- Parameters:
deviceInfo
- The newDeviceInfo
.
-
onDeviceVolumeChanged
default void onDeviceVolumeChanged(int volume, boolean muted)
Called when the value ofPlayer.getDeviceVolume()
orPlayer.isDeviceMuted()
changes.onEvents(Player, Events)
will also be called to report this event along with other events that happen in the sameLooper
message queue iteration.- Parameters:
volume
- The new device volume, with 0 being silence and 1 being unity gain.muted
- Whether the device is muted.
-
onVideoSizeChanged
default void onVideoSizeChanged(VideoSize videoSize)
Called each time whenPlayer.getVideoSize()
changes.onEvents(Player, Events)
will also be called to report this event along with other events that happen in the sameLooper
message queue iteration.- Parameters:
videoSize
- The new size of the video.
-
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(Player, Events)
will also be called to report this event along with other events that happen in the sameLooper
message queue iteration.- Parameters:
width
- The surface width in pixels. May beC.LENGTH_UNSET
if unknown, or 0 if the video is not rendered onto a surface.height
- The surface height in pixels. May beC.LENGTH_UNSET
if unknown, or 0 if the video is not rendered onto a surface.
-
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(Player, Events)
will also be called to report this event along with other events that happen in the sameLooper
message queue iteration.
-
onCues
@Deprecated default void onCues(List<Cue> cues)
Deprecated.UseonCues(CueGroup)
instead.Called when the value ofPlayer.getCurrentCues()
changes.Both this method and
onCues(CueGroup)
are called when there is a change in the cues. You should only implement one or the other.onEvents(Player, Events)
will also be called to report this event along with other events that happen in the sameLooper
message queue iteration.
-
onCues
default void onCues(CueGroup cueGroup)
Called when the value ofPlayer.getCurrentCues()
changes.Both this method and
onCues(List)
are called when there is a change in the cues. You should only implement one or the other.onEvents(Player, Events)
will also be called to report this event along with other events that happen in the sameLooper
message queue iteration.
-
onMetadata
default void onMetadata(Metadata metadata)
Called when there is metadata associated with the current playback time.onEvents(Player, Events)
will also be called to report this event along with other events that happen in the sameLooper
message queue iteration.- Parameters:
metadata
- The metadata.
-
-