Back to Exoplayer

Player.Listener (ExoPlayer library)

docs/doc/reference/com/google/android/exoplayer2/Player.Listener.html

latest39.5 KB
Original Source

Package com.google.android.exoplayer2

Interface Player.Listener

  • All Known Subinterfaces:AnalyticsCollectorAll Known Implementing Classes:DefaultAnalyticsCollector, ExoPlayerTestRunnerEnclosing interface:Player

public static interfacePlayer.Listener

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.

Method Summary

All Methods Instance Methods Default Methods Deprecated Methods | Modifier and Type | Method | Description | | --- | --- | --- | | default void | onAudioAttributesChanged​(AudioAttributes audioAttributes) | Called when the value of Player.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 from Player.isCommandAvailable(int) changes for at least one Player.Command. | | default void | onCues​(CueGroup cueGroup) | Called when the value of Player.getCurrentCues() changes. | | default void | onCues​(List<Cue> cues) | Deprecated. Use onCues(CueGroup) instead.

| | default void | onDeviceInfoChanged​(DeviceInfo deviceInfo) | Called when the device information changes | | default void | onDeviceVolumeChanged​(int volume, boolean muted) | Called when the value of Player.getDeviceVolume() or Player.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 Player.isPlaying() changes. | | default void | onLoadingChanged​(boolean isLoading) | Deprecated. Use onIsLoadingChanged(boolean) instead.

| | default void | onMaxSeekToPreviousPositionChanged​(long maxSeekToPreviousPositionMs) | Called when the value of Player.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 current repeat mode. | | default void | onMediaMetadataChanged​(MediaMetadata mediaMetadata) | Called when the value of Player.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 of Player.getPlaybackParameters() changes. | | default void | onPlaybackStateChanged​(@com.google.android.exoplayer2.Player.State int playbackState) | Called when the value returned from Player.getPlaybackState() changes. | | default void | onPlaybackSuppressionReasonChanged​(@com.google.android.exoplayer2.Player.PlaybackSuppressionReason int playbackSuppressionReason) | Called when the value returned from Player.getPlaybackSuppressionReason() changes. | | default void | onPlayerError​(PlaybackException error) | Called when an error occurs. | | default void | onPlayerErrorChanged​(PlaybackException error) | Called when the PlaybackException returned by Player.getPlayerError() changes. | | default void | onPlayerStateChanged​(boolean playWhenReady, @com.google.android.exoplayer2.Player.State int playbackState) | Deprecated. Use onPlaybackStateChanged(int) and onPlayWhenReadyChanged(boolean, int) instead.

| | default void | onPlaylistMetadataChanged​(MediaMetadata mediaMetadata) | Called when the value of Player.getPlaylistMetadata() changes. | | default void | onPlayWhenReadyChanged​(boolean playWhenReady, @com.google.android.exoplayer2.Player.PlayWhenReadyChangeReason int reason) | Called when the value returned from Player.getPlayWhenReady() changes. | | default void | onPositionDiscontinuity​(@com.google.android.exoplayer2.Player.DiscontinuityReason int reason) | Deprecated. Use onPositionDiscontinuity(PositionInfo, PositionInfo, int) instead.

| | 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 of Player.getRepeatMode() changes. | | default void | onSeekBackIncrementChanged​(long seekBackIncrementMs) | Called when the value of Player.getSeekBackIncrement() changes. | | default void | onSeekForwardIncrementChanged​(long seekForwardIncrementMs) | Called when the value of Player.getSeekForwardIncrement() changes. | | default void | onShuffleModeEnabledChanged​(boolean shuffleModeEnabled) | Called when the value of Player.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 of Player.getCurrentTimeline() changes. | | default void | onTracksChanged​(Tracks tracks) | Called when the value of Player.getCurrentTracks() changes. | | default void | onTrackSelectionParametersChanged​(TrackSelectionParameters parameters) | Called when the value returned from Player.getTrackSelectionParameters() changes. | | default void | onVideoSizeChanged​(VideoSize videoSize) | Called each time when Player.getVideoSize() changes. | | default void | onVolumeChanged​(float volume) | Called when the value of Player.getVolume() changes. |

Method Detail

- 

onEvents

default void onEvents​([Player](Player.html "interface in com.google.android.exoplayer2")player,[Player.Events](Player.Events.html "class in com.google.android.exoplayer2")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)`](#onPlaybackStateChanged(@com.google.android.exoplayer2.Player.Stateint)) and [`onPlayWhenReadyChanged(boolean,
   int)`](#onPlayWhenReadyChanged(boolean,@com.google.android.exoplayer2.Player.PlayWhenReadyChangeReasonint))). 
  - They need access to the [`Player`](Player.html "interface in com.google.android.exoplayer2") object to trigger further events (e.g. to call [`Player.seekTo(long)`](Player.html#seekTo(long)) after a [`onMediaItemTransition(MediaItem, int)`](#onMediaItemTransition(com.google.android.exoplayer2.MediaItem,@com.google.android.exoplayer2.Player.MediaItemTransitionReasonint))). 
  - They intend to use multiple state values together or in combination with [`Player`](Player.html "interface in com.google.android.exoplayer2") getter methods. For example using [`Player.getCurrentMediaItemIndex()`](Player.html#getCurrentMediaItemIndex()) with the `
   timeline` provided in [`onTimelineChanged(Timeline, int)`](#onTimelineChanged(com.google.android.exoplayer2.Timeline,@com.google.android.exoplayer2.Player.TimelineChangeReasonint)) is only safe from within this method. 
  - They are interested in events that logically happened together (e.g [`onPlaybackStateChanged(int)`](#onPlaybackStateChanged(@com.google.android.exoplayer2.Player.Stateint)) to [`Player.STATE_BUFFERING`](Player.html#STATE_BUFFERING) because of [`onMediaItemTransition(MediaItem, int)`](#onMediaItemTransition(com.google.android.exoplayer2.MediaItem,@com.google.android.exoplayer2.Player.MediaItemTransitionReasonint))). 

Parameters:player - The Player whose state changed. Use the getters to obtain the latest states.events - The Player.Events that happened in this iteration, indicating which player states changed.

- 

onTimelineChanged

default void onTimelineChanged​([Timeline](Timeline.html "class in com.google.android.exoplayer2")timeline,[@TimelineChangeReason](Player.TimelineChangeReason.html "annotation in com.google.android.exoplayer2")@com.google.android.exoplayer2.Player.TimelineChangeReason int reason)

Called when the value of Player.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(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 same Looper message queue iteration.

Parameters:timeline - The latest timeline. Never null, but may be empty.reason - The Player.TimelineChangeReason responsible for this timeline change.

- 

onMediaItemTransition

default void onMediaItemTransition​(@Nullable[MediaItem](MediaItem.html "class in com.google.android.exoplayer2")mediaItem,[@MediaItemTransitionReason](Player.MediaItemTransitionReason.html "annotation in com.google.android.exoplayer2")@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 current repeat 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 same Looper message queue iteration.

Parameters:mediaItem - The MediaItem. May be null if the playlist becomes empty.reason - The reason for the transition.

- 

onTracksChanged

default void onTracksChanged​([Tracks](Tracks.html "class in com.google.android.exoplayer2")tracks)

Called when the value of Player.getCurrentTracks() changes.

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

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

- 

onMediaMetadataChanged

default void onMediaMetadataChanged​([MediaMetadata](MediaMetadata.html "class in com.google.android.exoplayer2")mediaMetadata)

Called when the value of Player.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 same Looper message queue iteration.

Parameters:mediaMetadata - The combined MediaMetadata.

- 

onPlaylistMetadataChanged

default void onPlaylistMetadataChanged​([MediaMetadata](MediaMetadata.html "class in com.google.android.exoplayer2")mediaMetadata)

Called when the value of Player.getPlaylistMetadata() changes.

onEvents(Player, Events) will also be called to report this event along with other events that happen in the same Looper 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 same Looper message queue iteration.

Parameters:isLoading - Whether the source is currently being loaded.

- 

onLoadingChanged

[@Deprecated](https://developer.android.com/reference/java/lang/Deprecated.html "class or interface in java.lang")default void onLoadingChanged​(boolean isLoading)

Deprecated. Use onIsLoadingChanged(boolean) instead.

- 

onAvailableCommandsChanged

default void onAvailableCommandsChanged​([Player.Commands](Player.Commands.html "class in com.google.android.exoplayer2")availableCommands)

Called when the value returned from Player.isCommandAvailable(int) changes for at least one Player.Command.

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

Parameters:availableCommands - The available Player.Commands.

- 

onTrackSelectionParametersChanged

default void onTrackSelectionParametersChanged​([TrackSelectionParameters](trackselection/TrackSelectionParameters.html "class in com.google.android.exoplayer2.trackselection")parameters)

Called when the value returned from Player.getTrackSelectionParameters() changes.

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

Parameters:parameters - The new TrackSelectionParameters.

- 

onPlayerStateChanged

[@Deprecated](https://developer.android.com/reference/java/lang/Deprecated.html "class or interface in java.lang")default void onPlayerStateChanged​(boolean playWhenReady,[@State](Player.State.html "annotation in com.google.android.exoplayer2")@com.google.android.exoplayer2.Player.State int playbackState)

Deprecated. Use onPlaybackStateChanged(int) and onPlayWhenReadyChanged(boolean, int) instead.

- 

onPlaybackStateChanged

default void onPlaybackStateChanged​([@State](Player.State.html "annotation in com.google.android.exoplayer2")@com.google.android.exoplayer2.Player.State int playbackState)

Called when the value returned from Player.getPlaybackState() changes.

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

Parameters:playbackState - The new playback Player.State.

- 

onPlayWhenReadyChanged

default void onPlayWhenReadyChanged​(boolean playWhenReady,[@PlayWhenReadyChangeReason](Player.PlayWhenReadyChangeReason.html "annotation in com.google.android.exoplayer2")@com.google.android.exoplayer2.Player.PlayWhenReadyChangeReason int reason)

Called when the value returned from Player.getPlayWhenReady() changes.

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

Parameters:playWhenReady - Whether playback will proceed when ready.reason - The Player.PlayWhenReadyChangeReason for the change.

- 

onPlaybackSuppressionReasonChanged

default void onPlaybackSuppressionReasonChanged​([@PlaybackSuppressionReason](Player.PlaybackSuppressionReason.html "annotation in com.google.android.exoplayer2")@com.google.android.exoplayer2.Player.PlaybackSuppressionReason int playbackSuppressionReason)

Called when the value returned from Player.getPlaybackSuppressionReason() changes.

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

Parameters:playbackSuppressionReason - The current Player.PlaybackSuppressionReason.

- 

onIsPlayingChanged

default void onIsPlayingChanged​(boolean isPlaying)

Called when the value of Player.isPlaying() changes.

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

Parameters:isPlaying - Whether the player is playing.

- 

onRepeatModeChanged

default void onRepeatModeChanged​([@RepeatMode](Player.RepeatMode.html "annotation in com.google.android.exoplayer2")@com.google.android.exoplayer2.Player.RepeatMode int repeatMode)

Called when the value of Player.getRepeatMode() changes.

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

Parameters:repeatMode - The Player.RepeatMode used for playback.

- 

onShuffleModeEnabledChanged

default void onShuffleModeEnabledChanged​(boolean shuffleModeEnabled)

Called when the value of Player.getShuffleModeEnabled() changes.

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

Parameters:shuffleModeEnabled - Whether shuffling of media items is enabled.

- 

onPlayerError

default void onPlayerError​([PlaybackException](PlaybackException.html "class in com.google.android.exoplayer2")error)

Called when an error occurs. The playback state will transition to Player.STATE_IDLE immediately after this method is called. The player instance can still be used, and Player.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 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:error - The error.

- 

onPlayerErrorChanged

default void onPlayerErrorChanged​(@Nullable[PlaybackException](PlaybackException.html "class in com.google.android.exoplayer2")error)

Called when the PlaybackException returned by Player.getPlayerError() changes.

onEvents(Player, Events) 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:error - The new error, or null if the error is being cleared.

- 

onPositionDiscontinuity

[@Deprecated](https://developer.android.com/reference/java/lang/Deprecated.html "class or interface in java.lang")default void onPositionDiscontinuity​([@DiscontinuityReason](Player.DiscontinuityReason.html "annotation in com.google.android.exoplayer2")@com.google.android.exoplayer2.Player.DiscontinuityReason int reason)

Deprecated. Use onPositionDiscontinuity(PositionInfo, PositionInfo, int) instead.

- 

onPositionDiscontinuity

default void onPositionDiscontinuity​([Player.PositionInfo](Player.PositionInfo.html "class in com.google.android.exoplayer2")oldPosition,[Player.PositionInfo](Player.PositionInfo.html "class in com.google.android.exoplayer2")newPosition,[@DiscontinuityReason](Player.DiscontinuityReason.html "annotation in com.google.android.exoplayer2")@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 same Looper message queue iteration.

Parameters:oldPosition - The position before the discontinuity.newPosition - The position after the discontinuity.reason - The Player.DiscontinuityReason responsible for the discontinuity.

- 

onPlaybackParametersChanged

default void onPlaybackParametersChanged​([PlaybackParameters](PlaybackParameters.html "class in com.google.android.exoplayer2")playbackParameters)

Called when the value of Player.getPlaybackParameters() changes. The playback parameters may change due to a call to Player.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 same Looper message queue iteration.

Parameters:playbackParameters - The playback parameters.

- 

onSeekBackIncrementChanged

default void onSeekBackIncrementChanged​(long seekBackIncrementMs)

Called when the value of Player.getSeekBackIncrement() changes.

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

Parameters:seekBackIncrementMs - The Player.seekBack() increment, in milliseconds.

- 

onSeekForwardIncrementChanged

default void onSeekForwardIncrementChanged​(long seekForwardIncrementMs)

Called when the value of Player.getSeekForwardIncrement() changes.

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

Parameters:seekForwardIncrementMs - The Player.seekForward() increment, in milliseconds.

- 

onMaxSeekToPreviousPositionChanged

default void onMaxSeekToPreviousPositionChanged​(long maxSeekToPreviousPositionMs)

Called when the value of Player.getMaxSeekToPreviousPosition() changes.

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

Parameters:maxSeekToPreviousPositionMs - The maximum position for which Player.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 same Looper message queue iteration.

Parameters:audioSessionId - The audio session ID.

- 

onAudioAttributesChanged

default void onAudioAttributesChanged​([AudioAttributes](audio/AudioAttributes.html "class in com.google.android.exoplayer2.audio")audioAttributes)

Called when the value of Player.getAudioAttributes() changes.

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

Parameters:audioAttributes - The audio attributes.

- 

onVolumeChanged

default void onVolumeChanged​(float volume)

Called when the value of Player.getVolume() changes.

onEvents(Player, Events) will also be called to report this event along with other events that happen in the same Looper 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 same Looper message queue iteration.

Parameters:skipSilenceEnabled - Whether skipping silences in the audio stream is enabled.

- 

onDeviceInfoChanged

default void onDeviceInfoChanged​([DeviceInfo](DeviceInfo.html "class in com.google.android.exoplayer2")deviceInfo)

Called when the device information changes

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

Parameters:deviceInfo - The new DeviceInfo.

- 

onDeviceVolumeChanged

default void onDeviceVolumeChanged​(int volume,
                                   boolean muted)

Called when the value of Player.getDeviceVolume() or Player.isDeviceMuted() changes.

onEvents(Player, Events) will also be called to report this event along with other events that happen in the same Looper 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](video/VideoSize.html "class in com.google.android.exoplayer2.video")videoSize)

Called each time when Player.getVideoSize() changes.

onEvents(Player, Events) will also be called to report this event along with other events that happen in the same Looper 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 same Looper message queue iteration.

Parameters:width - The surface width in pixels. May be C.LENGTH_UNSET if unknown, or 0 if the video is not rendered onto a surface.height - The surface height in pixels. May be C.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 same Looper message queue iteration.

- 

onCues

[@Deprecated](https://developer.android.com/reference/java/lang/Deprecated.html "class or interface in java.lang")default void onCues​([List](https://developer.android.com/reference/java/util/List.html "class or interface in java.util")<[Cue](text/Cue.html "class in com.google.android.exoplayer2.text")> cues)

Deprecated. Use onCues(CueGroup) instead.

Called when the value of Player.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 same Looper message queue iteration.

- 

onCues

default void onCues​([CueGroup](text/CueGroup.html "class in com.google.android.exoplayer2.text")cueGroup)

Called when the value of Player.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 same Looper message queue iteration.

- 

onMetadata

default void onMetadata​([Metadata](metadata/Metadata.html "class in com.google.android.exoplayer2.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 same Looper message queue iteration.

Parameters:metadata - The metadata.