Interface Player.Listener
-
- All Known Subinterfaces:
AnalyticsCollector
- All Known Implementing Classes:
DefaultAnalyticsCollector,ExoPlayerTestRunner
- Enclosing interface:
- Player
public static interface Player.ListenerListener for changes in aPlayer.All methods have no-op default implementations to allow selective overrides.
If the return value of a
Playergetter changes due to a change in command availability, the corresponding listener method(s) will be invoked. If the return value of aPlayergetter 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 voidonAudioAttributesChanged(AudioAttributes audioAttributes)Called when the value ofPlayer.getAudioAttributes()changes.default voidonAudioSessionIdChanged(int audioSessionId)Called when the audio session ID changes.default voidonAvailableCommandsChanged(Player.Commands availableCommands)Called when the value returned fromPlayer.isCommandAvailable(int)changes for at least onePlayer.Command.default voidonCues(CueGroup cueGroup)Called when the value ofPlayer.getCurrentCues()changes.default voidonCues(List<Cue> cues)Deprecated.UseonCues(CueGroup)instead.default voidonDeviceInfoChanged(DeviceInfo deviceInfo)Called when the device information changesdefault voidonDeviceVolumeChanged(int volume, boolean muted)Called when the value ofPlayer.getDeviceVolume()orPlayer.isDeviceMuted()changes.default voidonEvents(Player player, Player.Events events)Called when one or more player states changed.default voidonIsLoadingChanged(boolean isLoading)Called when the player starts or stops loading the source.default voidonIsPlayingChanged(boolean isPlaying)Called when the value ofPlayer.isPlaying()changes.default voidonLoadingChanged(boolean isLoading)Deprecated.UseonIsLoadingChanged(boolean)instead.default voidonMaxSeekToPreviousPositionChanged(long maxSeekToPreviousPositionMs)Called when the value ofPlayer.getMaxSeekToPreviousPosition()changes.default voidonMediaItemTransition(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 voidonMediaMetadataChanged(MediaMetadata mediaMetadata)Called when the value ofPlayer.getMediaMetadata()changes.default voidonMetadata(Metadata metadata)Called when there is metadata associated with the current playback time.default voidonPlaybackParametersChanged(PlaybackParameters playbackParameters)Called when the value ofPlayer.getPlaybackParameters()changes.default voidonPlaybackStateChanged(@com.google.android.exoplayer2.Player.State int playbackState)Called when the value returned fromPlayer.getPlaybackState()changes.default voidonPlaybackSuppressionReasonChanged(@com.google.android.exoplayer2.Player.PlaybackSuppressionReason int playbackSuppressionReason)Called when the value returned fromPlayer.getPlaybackSuppressionReason()changes.default voidonPlayerError(PlaybackException error)Called when an error occurs.default voidonPlayerErrorChanged(PlaybackException error)Called when thePlaybackExceptionreturned byPlayer.getPlayerError()changes.default voidonPlayerStateChanged(boolean playWhenReady, @com.google.android.exoplayer2.Player.State int playbackState)Deprecated.UseonPlaybackStateChanged(int)andonPlayWhenReadyChanged(boolean, int)instead.default voidonPlaylistMetadataChanged(MediaMetadata mediaMetadata)Called when the value ofPlayer.getPlaylistMetadata()changes.default voidonPlayWhenReadyChanged(boolean playWhenReady, @com.google.android.exoplayer2.Player.PlayWhenReadyChangeReason int reason)Called when the value returned fromPlayer.getPlayWhenReady()changes.default voidonPositionDiscontinuity(@com.google.android.exoplayer2.Player.DiscontinuityReason int reason)Deprecated.default voidonPositionDiscontinuity(Player.PositionInfo oldPosition, Player.PositionInfo newPosition, @com.google.android.exoplayer2.Player.DiscontinuityReason int reason)Called when a position discontinuity occurs.default 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.default voidonRepeatModeChanged(@com.google.android.exoplayer2.Player.RepeatMode int repeatMode)Called when the value ofPlayer.getRepeatMode()changes.default voidonSeekBackIncrementChanged(long seekBackIncrementMs)Called when the value ofPlayer.getSeekBackIncrement()changes.default voidonSeekForwardIncrementChanged(long seekForwardIncrementMs)Called when the value ofPlayer.getSeekForwardIncrement()changes.default voidonShuffleModeEnabledChanged(boolean shuffleModeEnabled)Called when the value ofPlayer.getShuffleModeEnabled()changes.default voidonSkipSilenceEnabledChanged(boolean skipSilenceEnabled)Called when skipping silences is enabled or disabled in the audio stream.default 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.default voidonTimelineChanged(Timeline timeline, @com.google.android.exoplayer2.Player.TimelineChangeReason int reason)Called when the value ofPlayer.getCurrentTimeline()changes.default voidonTracksChanged(Tracks tracks)Called when the value ofPlayer.getCurrentTracks()changes.default voidonTrackSelectionParametersChanged(TrackSelectionParameters parameters)Called when the value returned fromPlayer.getTrackSelectionParameters()changes.default voidonVideoSizeChanged(VideoSize videoSize)Called each time whenPlayer.getVideoSize()changes.default voidonVolumeChanged(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
Loopermessage 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
Playerobject 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
Playergetter methods. For example usingPlayer.getCurrentMediaItemIndex()with thetimelineprovided 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_BUFFERINGbecause ofonMediaItemTransition(MediaItem, int)).
- Parameters:
player- ThePlayerwhose state changed. Use the getters to obtain the latest states.events- ThePlayer.Eventsthat 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
MediaItemor 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 sameLoopermessage queue iteration.- Parameters:
timeline- The latest timeline. Never null, but may be empty.reason- ThePlayer.TimelineChangeReasonresponsible 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 sameLoopermessage 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 sameLoopermessage 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 sameLoopermessage 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 sameLoopermessage 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 sameLoopermessage 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 sameLoopermessage 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 sameLoopermessage 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 sameLoopermessage 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 sameLoopermessage queue iteration.- Parameters:
playWhenReady- Whether playback will proceed when ready.reason- ThePlayer.PlayWhenReadyChangeReasonfor 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 sameLoopermessage 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 sameLoopermessage 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 sameLoopermessage queue iteration.- Parameters:
repeatMode- ThePlayer.RepeatModeused 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 sameLoopermessage 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_IDLEimmediately 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 sameLoopermessage queue iteration.Implementations of Player may pass an instance of a subclass of
PlaybackExceptionto this method in order to include more information about the error.- Parameters:
error- The error.
-
onPlayerErrorChanged
default void onPlayerErrorChanged(@Nullable PlaybackException error)Called when thePlaybackExceptionreturned byPlayer.getPlayerError()changes.onEvents(Player, Events)will also be called to report this event along with other events that happen in the sameLoopermessage queue iteration.Implementations of Player may pass an instance of a subclass of
PlaybackExceptionto 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 sameLoopermessage queue iteration.- Parameters:
oldPosition- The position before the discontinuity.newPosition- The position after the discontinuity.reason- ThePlayer.DiscontinuityReasonresponsible 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 sameLoopermessage 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 sameLoopermessage 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 sameLoopermessage 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 sameLoopermessage 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 sameLoopermessage 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 sameLoopermessage 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 sameLoopermessage 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 sameLoopermessage 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 sameLoopermessage 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 sameLoopermessage 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 sameLoopermessage 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 sameLoopermessage queue iteration.- Parameters:
width- The surface width in pixels. May beC.LENGTH_UNSETif unknown, or 0 if the video is not rendered onto a surface.height- The surface height in pixels. May beC.LENGTH_UNSETif 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 sameLoopermessage 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 sameLoopermessage 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 sameLoopermessage 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 sameLoopermessage queue iteration.- Parameters:
metadata- The metadata.
-
-