Interface Player.Listener
-
- All Superinterfaces:
Player.EventListener
- All Known Implementing Classes:
AnalyticsCollector,DebugTextViewHelper,ExoPlayerTestRunner,ImaAdsLoader,SubtitleView
- Enclosing interface:
- Player
public static interface Player.Listener extends Player.EventListener
Listener of all changes in the Player.All methods have no-op default implementations to allow selective overrides.
-
-
Method Summary
All Methods Instance Methods Default Methods Modifier and Type Method Description default voidonAudioAttributesChanged(AudioAttributes audioAttributes)Called when the audio attributes change.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(List<Cue> cues)Called when there is a change in theCues.default voidonDeviceInfoChanged(DeviceInfo deviceInfo)Called when the device information changes.default voidonDeviceVolumeChanged(int volume, boolean muted)Called when the device volume or mute state 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 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 combinedMediaMetadatachanges.default voidonMetadata(Metadata metadata)Called when there is metadata associated with the current playback time.default voidonPlaybackParametersChanged(PlaybackParameters playbackParameters)Called when the current playback parameters change.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 voidonPlaylistMetadataChanged(MediaMetadata mediaMetadata)Called when the playlistMediaMetadatachanges.default voidonPlayWhenReadyChanged(boolean playWhenReady, @com.google.android.exoplayer2.Player.PlayWhenReadyChangeReason int reason)Called when the value returned fromPlayer.getPlayWhenReady()changes.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 timeline has been refreshed.default voidonTracksInfoChanged(TracksInfo tracksInfo)Called when the available or selected tracks change.default voidonVideoSizeChanged(VideoSize videoSize)Called each time there's a change in the size of the video being rendered.default voidonVolumeChanged(float volume)Called when the volume changes.-
Methods inherited from interface com.google.android.exoplayer2.Player.EventListener
onLoadingChanged, onMaxSeekToPreviousPositionChanged, onPlayerStateChanged, onPositionDiscontinuity, onSeekProcessed, onTracksChanged, onTrackSelectionParametersChanged
-
-
-
-
Method Detail
-
onTimelineChanged
default void onTimelineChanged(Timeline timeline, @TimelineChangeReason @com.google.android.exoplayer2.Player.TimelineChangeReason int reason)
Description copied from interface:Player.EventListenerCalled when the timeline has been refreshed.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 separatePlayer.EventListener.onPositionDiscontinuity(PositionInfo, PositionInfo, int)callback will be triggered.Player.EventListener.onEvents(Player, Events)will also be called to report this event along with other events that happen in the sameLoopermessage queue iteration.- Specified by:
onTimelineChangedin interfacePlayer.EventListener- 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)Description copied from interface:Player.EventListenerCalled 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 playlist becomes non-empty or empty as a consequence of a playlist change.
Player.EventListener.onEvents(Player, Events)will also be called to report this event along with other events that happen in the sameLoopermessage queue iteration.- Specified by:
onMediaItemTransitionin interfacePlayer.EventListener- Parameters:
mediaItem- TheMediaItem. May be null if the playlist becomes empty.reason- The reason for the transition.
-
onTracksInfoChanged
default void onTracksInfoChanged(TracksInfo tracksInfo)
Description copied from interface:Player.EventListenerCalled when the available or selected tracks change.Player.EventListener.onEvents(Player, Events)will also be called to report this event along with other events that happen in the sameLoopermessage queue iteration.- Specified by:
onTracksInfoChangedin interfacePlayer.EventListener- Parameters:
tracksInfo- The available tracks information. Never null, but may be of length zero.
-
onIsLoadingChanged
default void onIsLoadingChanged(boolean isLoading)
Description copied from interface:Player.EventListenerCalled when the player starts or stops loading the source.Player.EventListener.onEvents(Player, Events)will also be called to report this event along with other events that happen in the sameLoopermessage queue iteration.- Specified by:
onIsLoadingChangedin interfacePlayer.EventListener- Parameters:
isLoading- Whether the source is currently being loaded.
-
onAvailableCommandsChanged
default void onAvailableCommandsChanged(Player.Commands availableCommands)
Description copied from interface:Player.EventListenerCalled when the value returned fromPlayer.isCommandAvailable(int)changes for at least onePlayer.Command.Player.EventListener.onEvents(Player, Events)will also be called to report this event along with other events that happen in the sameLoopermessage queue iteration.- Specified by:
onAvailableCommandsChangedin interfacePlayer.EventListener- Parameters:
availableCommands- The availablePlayer.Commands.
-
onPlaybackStateChanged
default void onPlaybackStateChanged(@State @com.google.android.exoplayer2.Player.State int playbackState)
Description copied from interface:Player.EventListenerCalled when the value returned fromPlayer.getPlaybackState()changes.Player.EventListener.onEvents(Player, Events)will also be called to report this event along with other events that happen in the sameLoopermessage queue iteration.- Specified by:
onPlaybackStateChangedin interfacePlayer.EventListener- Parameters:
playbackState- The new playbackstate.
-
onPlayWhenReadyChanged
default void onPlayWhenReadyChanged(boolean playWhenReady, @PlayWhenReadyChangeReason @com.google.android.exoplayer2.Player.PlayWhenReadyChangeReason int reason)Description copied from interface:Player.EventListenerCalled when the value returned fromPlayer.getPlayWhenReady()changes.Player.EventListener.onEvents(Player, Events)will also be called to report this event along with other events that happen in the sameLoopermessage queue iteration.- Specified by:
onPlayWhenReadyChangedin interfacePlayer.EventListener- Parameters:
playWhenReady- Whether playback will proceed when ready.reason- Thereasonfor the change.
-
onPlaybackSuppressionReasonChanged
default void onPlaybackSuppressionReasonChanged(@PlaybackSuppressionReason @com.google.android.exoplayer2.Player.PlaybackSuppressionReason int playbackSuppressionReason)
Description copied from interface:Player.EventListenerCalled when the value returned fromPlayer.getPlaybackSuppressionReason()changes.Player.EventListener.onEvents(Player, Events)will also be called to report this event along with other events that happen in the sameLoopermessage queue iteration.- Specified by:
onPlaybackSuppressionReasonChangedin interfacePlayer.EventListener- Parameters:
playbackSuppressionReason- The currentPlayer.PlaybackSuppressionReason.
-
onIsPlayingChanged
default void onIsPlayingChanged(boolean isPlaying)
Description copied from interface:Player.EventListenerCalled when the value ofPlayer.isPlaying()changes.Player.EventListener.onEvents(Player, Events)will also be called to report this event along with other events that happen in the sameLoopermessage queue iteration.- Specified by:
onIsPlayingChangedin interfacePlayer.EventListener- Parameters:
isPlaying- Whether the player is playing.
-
onRepeatModeChanged
default void onRepeatModeChanged(@RepeatMode @com.google.android.exoplayer2.Player.RepeatMode int repeatMode)
Description copied from interface:Player.EventListenerCalled when the value ofPlayer.getRepeatMode()changes.Player.EventListener.onEvents(Player, Events)will also be called to report this event along with other events that happen in the sameLoopermessage queue iteration.- Specified by:
onRepeatModeChangedin interfacePlayer.EventListener- Parameters:
repeatMode- ThePlayer.RepeatModeused for playback.
-
onShuffleModeEnabledChanged
default void onShuffleModeEnabledChanged(boolean shuffleModeEnabled)
Description copied from interface:Player.EventListenerCalled when the value ofPlayer.getShuffleModeEnabled()changes.Player.EventListener.onEvents(Player, Events)will also be called to report this event along with other events that happen in the sameLoopermessage queue iteration.- Specified by:
onShuffleModeEnabledChangedin interfacePlayer.EventListener- Parameters:
shuffleModeEnabled- Whether shuffling ofmedia itemsis enabled.
-
onPlayerError
default void onPlayerError(PlaybackException error)
Description copied from interface:Player.EventListenerCalled 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.Player.EventListener.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.- Specified by:
onPlayerErrorin interfacePlayer.EventListener- Parameters:
error- The error.
-
onPlayerErrorChanged
default void onPlayerErrorChanged(@Nullable PlaybackException error)Description copied from interface:Player.EventListenerCalled when thePlaybackExceptionreturned byPlayer.getPlayerError()changes.Player.EventListener.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.- Specified by:
onPlayerErrorChangedin interfacePlayer.EventListener- Parameters:
error- The new error, or null if the error is being cleared.
-
onPositionDiscontinuity
default void onPositionDiscontinuity(Player.PositionInfo oldPosition, Player.PositionInfo newPosition, @DiscontinuityReason @com.google.android.exoplayer2.Player.DiscontinuityReason int reason)
Description copied from interface:Player.EventListenerCalled 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.EventListener.onEvents(Player, Events)will also be called to report this event along with other events that happen in the sameLoopermessage queue iteration.- Specified by:
onPositionDiscontinuityin interfacePlayer.EventListener- 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)
Description copied from interface:Player.EventListenerCalled when the current playback parameters change. 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).Player.EventListener.onEvents(Player, Events)will also be called to report this event along with other events that happen in the sameLoopermessage queue iteration.- Specified by:
onPlaybackParametersChangedin interfacePlayer.EventListener- Parameters:
playbackParameters- The playback parameters.
-
onSeekForwardIncrementChanged
default void onSeekForwardIncrementChanged(long seekForwardIncrementMs)
Description copied from interface:Player.EventListenerCalled when the value ofPlayer.getSeekForwardIncrement()changes.Player.EventListener.onEvents(Player, Events)will also be called to report this event along with other events that happen in the sameLoopermessage queue iteration.- Specified by:
onSeekForwardIncrementChangedin interfacePlayer.EventListener- Parameters:
seekForwardIncrementMs- ThePlayer.seekForward()increment, in milliseconds.
-
onSeekBackIncrementChanged
default void onSeekBackIncrementChanged(long seekBackIncrementMs)
Description copied from interface:Player.EventListenerCalled when the value ofPlayer.getSeekBackIncrement()changes.Player.EventListener.onEvents(Player, Events)will also be called to report this event along with other events that happen in the sameLoopermessage queue iteration.- Specified by:
onSeekBackIncrementChangedin interfacePlayer.EventListener- Parameters:
seekBackIncrementMs- ThePlayer.seekBack()increment, in milliseconds.
-
onAudioSessionIdChanged
default void onAudioSessionIdChanged(int audioSessionId)
Called when the audio session ID changes.- Parameters:
audioSessionId- The audio session ID.
-
onAudioAttributesChanged
default void onAudioAttributesChanged(AudioAttributes audioAttributes)
Called when the audio attributes change.- Parameters:
audioAttributes- The audio attributes.
-
onVolumeChanged
default void onVolumeChanged(float volume)
Called when the volume changes.- 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.- Parameters:
skipSilenceEnabled- Whether skipping silences in the audio stream is enabled.
-
onDeviceInfoChanged
default void onDeviceInfoChanged(DeviceInfo deviceInfo)
Called when the device information changes.
-
onDeviceVolumeChanged
default void onDeviceVolumeChanged(int volume, boolean muted)Called when the device volume or mute state changes.
-
onEvents
default void onEvents(Player player, Player.Events events)
Description copied from interface:Player.EventListenerCalled 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.Only state changes represented by
eventsare reported through this method.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
Player.EventListener.onPlaybackStateChanged(int)andPlayer.EventListener.onPlayWhenReadyChanged(boolean, int)). - They need access to the
Playerobject to trigger further events (e.g. to callPlayer.seekTo(long)after aPlayer.EventListener.onMediaItemTransition(MediaItem, int)). - They intend to use multiple state values together or in combination with
Playergetter methods. For example usingPlayer.getCurrentMediaItemIndex()with thetimelineprovided inPlayer.EventListener.onTimelineChanged(Timeline, int)is only safe from within this method. - They are interested in events that logically happened together (e.g
Player.EventListener.onPlaybackStateChanged(int)toPlayer.STATE_BUFFERINGbecause ofPlayer.EventListener.onMediaItemTransition(MediaItem, int)).
- Specified by:
onEventsin interfacePlayer.EventListener- 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
-
onVideoSizeChanged
default void onVideoSizeChanged(VideoSize videoSize)
Called each time there's a change in the size of the video being rendered.- 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.- 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.
-
onCues
default void onCues(List<Cue> cues)
Called when there is a change in theCues.cuesis in ascending order of priority. If any of the cue boxes overlap when displayed, theCuenearer the end of the list should be shown on top.- Parameters:
cues- TheCues. May be empty.
-
onMetadata
default void onMetadata(Metadata metadata)
Called when there is metadata associated with the current playback time.- Parameters:
metadata- The metadata.
-
onMediaMetadataChanged
default void onMediaMetadataChanged(MediaMetadata mediaMetadata)
Description copied from interface:Player.EventListenerCalled when the combinedMediaMetadatachanges.The provided
MediaMetadatais a combination of theMediaItem.mediaMetadataand the static and dynamic metadata from thetrack selections' formatsandonMetadata(Metadata). If a field is populated in theMediaItem.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.EventListener.onEvents(Player, Events)will also be called to report this event along with other events that happen in the sameLoopermessage queue iteration.- Specified by:
onMediaMetadataChangedin interfacePlayer.EventListener- Parameters:
mediaMetadata- The combinedMediaMetadata.
-
onPlaylistMetadataChanged
default void onPlaylistMetadataChanged(MediaMetadata mediaMetadata)
Description copied from interface:Player.EventListenerCalled when the playlistMediaMetadatachanges.- Specified by:
onPlaylistMetadataChangedin interfacePlayer.EventListener
-
-