Player.Listener


interface Player.Listener

Known direct subclasses
AnalyticsCollector

Interface for data collectors that forward analytics events to AnalyticsListeners.

ExoPlayerTestRunner

Helper class to run an ExoPlayer test.

WearUnsuitableOutputPlaybackSuppressionResolverListener

A Player.Listener that launches a system dialog in response to PLAYBACK_SUPPRESSION_REASON_UNSUITABLE_AUDIO_OUTPUT to allow the user to connect a suitable audio output.

Known indirect subclasses
DefaultAnalyticsCollector

Data collector that forwards analytics events to AnalyticsListeners.


Listener for changes in a Player.

All methods have no-op default implementations to allow selective overrides.

If the return value of a Player getter changes due to a change in command availability, the corresponding listener method(s) will be invoked. If the return value of a Player getter does not change because the corresponding command is not available, the corresponding listener method will not be invoked.

Summary

Public functions

Unit

Called when the value of getAudioAttributes changes.

Unit

Called when the audio session ID changes.

Unit

Called when the value returned from isCommandAvailable changes for at least one Command.

Unit
onCues(cueGroup: CueGroup!)

Called when the value of getCurrentCues changes.

Unit

This function is deprecated.

Use onCues instead.

Unit

Called when the device information changes

Unit
onDeviceVolumeChanged(volume: Int, muted: Boolean)

Called when the value of getDeviceVolume or isDeviceMuted changes.

Unit
onEvents(player: Player!, events: Player.Events!)

Called when one or more player states changed.

Unit

Called when the player starts or stops loading the source.

Unit

Called when the value of isPlaying changes.

Unit

This function is deprecated.

Use onIsLoadingChanged instead.

Unit
onMaxSeekToPreviousPositionChanged(maxSeekToPreviousPositionMs: Long)

Called when the value of getMaxSeekToPreviousPosition changes.

Unit

Called when playback transitions to a media item or starts repeating a media item according to the current repeat mode.

Unit

Called when the value of getMediaMetadata changes.

Unit

Called when there is metadata associated with the current playback time.

Unit
onPlayWhenReadyChanged(
    playWhenReady: Boolean,
    @Player.PlayWhenReadyChangeReason reason: Int
)

Called when the value returned from getPlayWhenReady changes.

Unit

Called when the value of getPlaybackParameters changes.

Unit

Called when the value returned from getPlaybackState changes.

Unit

Called when the value returned from getPlaybackSuppressionReason changes.

Unit

Called when an error occurs.

Unit

Called when the PlaybackException returned by getPlayerError changes.

Unit
@UnstableApi
onPlayerStateChanged(
    playWhenReady: Boolean,
    @Player.State playbackState: Int
)

This function is deprecated.

Use onPlaybackStateChanged and onPlayWhenReadyChanged instead.

Unit

Called when the value of getPlaylistMetadata changes.

Unit

This function is deprecated.

Use onPositionDiscontinuity instead.

Unit
onPositionDiscontinuity(
    oldPosition: Player.PositionInfo!,
    newPosition: Player.PositionInfo!,
    @Player.DiscontinuityReason reason: Int
)

Called when a position discontinuity occurs.

Unit

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.

Unit

Called when the value of getRepeatMode changes.

Unit
onSeekBackIncrementChanged(seekBackIncrementMs: Long)

Called when the value of getSeekBackIncrement changes.

Unit
onSeekForwardIncrementChanged(seekForwardIncrementMs: Long)

Called when the value of getSeekForwardIncrement changes.

Unit
onShuffleModeEnabledChanged(shuffleModeEnabled: Boolean)

Called when the value of getShuffleModeEnabled changes.

Unit
onSkipSilenceEnabledChanged(skipSilenceEnabled: Boolean)

Called when skipping silences is enabled or disabled in the audio stream.

Unit
onSurfaceSizeChanged(width: Int, height: Int)

Called each time there's a change in the size of the surface onto which the video is being rendered.

Unit
onTimelineChanged(
    timeline: Timeline!,
    @Player.TimelineChangeReason reason: Int
)

Called when the value of getCurrentTimeline changes.

Unit

Called when the value returned from getTrackSelectionParameters changes.

Unit

Called when the value of getCurrentTracks changes.

Unit

Called each time when getVideoSize changes.

Unit

Called when the value of getVolume changes.

Public functions

onAudioAttributesChanged

fun onAudioAttributesChanged(audioAttributes: AudioAttributes!): Unit

Called when the value of getAudioAttributes changes.

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

Parameters
audioAttributes: AudioAttributes!

The audio attributes.

onAudioSessionIdChanged

@UnstableApi
fun onAudioSessionIdChanged(audioSessionId: Int): Unit

Called when the audio session ID changes.

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

Parameters
audioSessionId: Int

The audio session ID.

onAvailableCommandsChanged

fun onAvailableCommandsChanged(availableCommands: Player.Commands!): Unit

Called when the value returned from isCommandAvailable changes for at least one Command.

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

Parameters
availableCommands: Player.Commands!

The available Commands.

onCues

fun onCues(cueGroup: CueGroup!): Unit

Called when the value of getCurrentCues changes.

Both this method and onCues are called when there is a change in the cues. You should only implement one or the other.

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

onCues

@UnstableApi
fun onCues(cues: (Mutable)List<Cue!>!): Unit

Called when the value of getCurrentCues changes.

Both this method and onCues are called when there is a change in the cues. You should only implement one or the other.

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

onDeviceInfoChanged

fun onDeviceInfoChanged(deviceInfo: DeviceInfo!): Unit

Called when the device information changes

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

Parameters
deviceInfo: DeviceInfo!

The new DeviceInfo.

onDeviceVolumeChanged

fun onDeviceVolumeChanged(volume: Int, muted: Boolean): Unit

Called when the value of getDeviceVolume or isDeviceMuted changes.

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

Parameters
volume: Int

The new device volume, with 0 being silence and 1 being unity gain.

muted: Boolean

Whether the device is muted.

onEvents

fun onEvents(player: Player!, events: Player.Events!): Unit

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:

Parameters
player: Player!

The Player whose state changed. Use the getters to obtain the latest states.

events: Player.Events!

The Events that happened in this iteration, indicating which player states changed.

onIsLoadingChanged

fun onIsLoadingChanged(isLoading: Boolean): Unit

Called when the player starts or stops loading the source.

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

Parameters
isLoading: Boolean

Whether the source is currently being loaded.

onIsPlayingChanged

fun onIsPlayingChanged(isPlaying: Boolean): Unit

Called when the value of isPlaying changes.

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

Parameters
isPlaying: Boolean

Whether the player is playing.

onLoadingChanged

@UnstableApi
fun onLoadingChanged(isLoading: Boolean): Unit

onMaxSeekToPreviousPositionChanged

fun onMaxSeekToPreviousPositionChanged(maxSeekToPreviousPositionMs: Long): Unit

Called when the value of getMaxSeekToPreviousPosition changes.

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

Parameters
maxSeekToPreviousPositionMs: Long

The maximum position for which seekToPrevious seeks to the previous position, in milliseconds.

onMediaItemTransition

fun onMediaItemTransition(
    mediaItem: MediaItem?,
    @Player.MediaItemTransitionReason reason: Int
): Unit

Called when playback transitions to a media item or starts repeating a media item according to the current repeat mode.

Note that this callback is also called when the value of getCurrentTimeline becomes non-empty or empty.

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

Parameters
mediaItem: MediaItem?

The MediaItem. May be null if the playlist becomes empty.

@Player.MediaItemTransitionReason reason: Int

The reason for the transition.

onMediaMetadataChanged

fun onMediaMetadataChanged(mediaMetadata: MediaMetadata!): Unit

Called when the value of getMediaMetadata changes.

This method may be called multiple times in quick succession.

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

Parameters
mediaMetadata: MediaMetadata!

The combined MediaMetadata.

onMetadata

@UnstableApi
fun onMetadata(metadata: Metadata!): Unit

Called when there is metadata associated with the current playback time.

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

Parameters
metadata: Metadata!

The metadata.

onPlayWhenReadyChanged

fun onPlayWhenReadyChanged(
    playWhenReady: Boolean,
    @Player.PlayWhenReadyChangeReason reason: Int
): Unit

Called when the value returned from getPlayWhenReady changes.

The current playWhenReady value may be re-reported if the reason for this value changes.

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

Parameters
playWhenReady: Boolean

Whether playback will proceed when ready.

@Player.PlayWhenReadyChangeReason reason: Int

The PlayWhenReadyChangeReason for the change.

onPlaybackParametersChanged

fun onPlaybackParametersChanged(playbackParameters: PlaybackParameters!): Unit

Called when the value of getPlaybackParameters changes. The playback parameters may change due to a call to setPlaybackParameters, or the player itself may change them (for example, if audio playback switches to passthrough or offload mode, where speed adjustment is no longer possible).

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

Parameters
playbackParameters: PlaybackParameters!

The playback parameters.

onPlaybackStateChanged

fun onPlaybackStateChanged(@Player.State playbackState: Int): Unit

Called when the value returned from getPlaybackState changes.

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

Parameters
@Player.State playbackState: Int

The new playback State.

onPlaybackSuppressionReasonChanged

fun onPlaybackSuppressionReasonChanged(
    @Player.PlaybackSuppressionReason playbackSuppressionReason: Int
): Unit

Called when the value returned from getPlaybackSuppressionReason changes.

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

Parameters
@Player.PlaybackSuppressionReason playbackSuppressionReason: Int

The current PlaybackSuppressionReason.

onPlayerError

fun onPlayerError(error: PlaybackException!): Unit

Called when an error occurs. The playback state will transition to STATE_IDLE immediately after this method is called. The player instance can still be used, and release must still be called on the player should it no longer be required.

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

Implementations of Player may pass an instance of a subclass of PlaybackException to this method in order to include more information about the error.

Parameters
error: PlaybackException!

The error.

onPlayerErrorChanged

fun onPlayerErrorChanged(error: PlaybackException?): Unit

Called when the PlaybackException returned by getPlayerError changes.

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

Implementations of Player may pass an instance of a subclass of PlaybackException to this method in order to include more information about the error.

Parameters
error: PlaybackException?

The new error, or null if the error is being cleared.

onPlayerStateChanged

@UnstableApi
fun onPlayerStateChanged(
    playWhenReady: Boolean,
    @Player.State playbackState: Int
): Unit

onPlaylistMetadataChanged

fun onPlaylistMetadataChanged(mediaMetadata: MediaMetadata!): Unit

Called when the value of getPlaylistMetadata changes.

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

onPositionDiscontinuity

@UnstableApi
fun onPositionDiscontinuity(@Player.DiscontinuityReason reason: Int): Unit

onPositionDiscontinuity

fun onPositionDiscontinuity(
    oldPosition: Player.PositionInfo!,
    newPosition: Player.PositionInfo!,
    @Player.DiscontinuityReason reason: Int
): Unit

Called when a position discontinuity occurs.

A position discontinuity occurs when the playing period changes, the playback position jumps within the period currently being played, or when the playing period has been skipped or removed.

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

Parameters
oldPosition: Player.PositionInfo!

The position before the discontinuity.

newPosition: Player.PositionInfo!

The position after the discontinuity.

@Player.DiscontinuityReason reason: Int

The DiscontinuityReason responsible for the discontinuity.

onRenderedFirstFrame

fun onRenderedFirstFrame(): Unit

Called when a frame is rendered for the first time since setting the surface, or since the renderer was reset, or since the stream being rendered was changed.

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

onRepeatModeChanged

fun onRepeatModeChanged(@Player.RepeatMode repeatMode: Int): Unit

Called when the value of getRepeatMode changes.

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

Parameters
@Player.RepeatMode repeatMode: Int

The RepeatMode used for playback.

onSeekBackIncrementChanged

fun onSeekBackIncrementChanged(seekBackIncrementMs: Long): Unit

Called when the value of getSeekBackIncrement changes.

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

Parameters
seekBackIncrementMs: Long

The seekBack increment, in milliseconds.

onSeekForwardIncrementChanged

fun onSeekForwardIncrementChanged(seekForwardIncrementMs: Long): Unit

Called when the value of getSeekForwardIncrement changes.

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

Parameters
seekForwardIncrementMs: Long

The seekForward increment, in milliseconds.

onShuffleModeEnabledChanged

fun onShuffleModeEnabledChanged(shuffleModeEnabled: Boolean): Unit

Called when the value of getShuffleModeEnabled changes.

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

Parameters
shuffleModeEnabled: Boolean

Whether shuffling of media items is enabled.

onSkipSilenceEnabledChanged

fun onSkipSilenceEnabledChanged(skipSilenceEnabled: Boolean): Unit

Called when skipping silences is enabled or disabled in the audio stream.

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

Parameters
skipSilenceEnabled: Boolean

Whether skipping silences in the audio stream is enabled.

onSurfaceSizeChanged

fun onSurfaceSizeChanged(width: Int, height: Int): Unit

Called each time there's a change in the size of the surface onto which the video is being rendered.

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

Parameters
width: Int

The surface width in pixels. May be LENGTH_UNSET if unknown, or 0 if the video is not rendered onto a surface.

height: Int

The surface height in pixels. May be LENGTH_UNSET if unknown, or 0 if the video is not rendered onto a surface.

onTimelineChanged

fun onTimelineChanged(
    timeline: Timeline!,
    @Player.TimelineChangeReason reason: Int
): Unit

Called when the value of getCurrentTimeline changes.

Note that the current MediaItem or playback position may change as a result of a timeline change. If playback can't continue smoothly because of this timeline change, a separate onPositionDiscontinuity callback will be triggered.

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

Parameters
timeline: Timeline!

The latest timeline. Never null, but may be empty.

@Player.TimelineChangeReason reason: Int

The TimelineChangeReason responsible for this timeline change.

onTrackSelectionParametersChanged

fun onTrackSelectionParametersChanged(parameters: TrackSelectionParameters!): Unit

Called when the value returned from getTrackSelectionParameters changes.

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

Parameters
parameters: TrackSelectionParameters!

The new TrackSelectionParameters.

onTracksChanged

fun onTracksChanged(tracks: Tracks!): Unit

Called when the value of getCurrentTracks changes.

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

Parameters
tracks: Tracks!

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

onVideoSizeChanged

fun onVideoSizeChanged(videoSize: VideoSize!): Unit

Called each time when getVideoSize changes.

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

Parameters
videoSize: VideoSize!

The new size of the video.

onVolumeChanged

fun onVolumeChanged(volume: Float): Unit

Called when the value of getVolume changes.

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

Parameters
volume: Float

The new volume, with 0 being silence and 1 being unity gain.