Player.Listener
interface Player.Listener
AnalyticsCollector |
Interface for data collectors that forward analytics events to |
ExoPlayerTestRunner |
Helper class to run an ExoPlayer test. |
WearUnsuitableOutputPlaybackSuppressionResolverListener |
A |
DefaultAnalyticsCollector |
Data collector that forwards analytics events to |
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 |
onAudioAttributesChanged(audioAttributes: AudioAttributes!)Called when the value of |
Unit |
@UnstableApiCalled when the audio session ID changes. |
Unit |
onAvailableCommandsChanged(availableCommands: Player.Commands!)Called when the value returned from |
Unit |
Called when the value of |
Unit |
@UnstableApiThis function is deprecated. Use |
Unit |
onDeviceInfoChanged(deviceInfo: DeviceInfo!)Called when the device information changes |
Unit |
onDeviceVolumeChanged(volume: Int, muted: Boolean)Called when the value of |
Unit |
onEvents(player: Player!, events: Player.Events!)Called when one or more player states changed. |
Unit |
onIsLoadingChanged(isLoading: Boolean)Called when the player starts or stops loading the source. |
Unit |
onIsPlayingChanged(isPlaying: Boolean)Called when the value of |
Unit |
@UnstableApiThis function is deprecated. Use |
Unit |
onMaxSeekToPreviousPositionChanged(maxSeekToPreviousPositionMs: Long)Called when the value of |
Unit |
onMediaItemTransition(Called when playback transitions to a media item or starts repeating a media item according to the current |
Unit |
onMediaMetadataChanged(mediaMetadata: MediaMetadata!)Called when the value of |
Unit |
@UnstableApiCalled when there is metadata associated with the current playback time. |
Unit |
onPlayWhenReadyChanged(Called when the value returned from |
Unit |
onPlaybackParametersChanged(playbackParameters: PlaybackParameters!)Called when the value of |
Unit |
onPlaybackStateChanged(@Player.State playbackState: Int)Called when the value returned from |
Unit |
onPlaybackSuppressionReasonChanged(Called when the value returned from |
Unit |
onPlayerError(error: PlaybackException!)Called when an error occurs. |
Unit |
onPlayerErrorChanged(error: PlaybackException?)Called when the |
Unit |
@UnstableApiThis function is deprecated. Use |
Unit |
onPlaylistMetadataChanged(mediaMetadata: MediaMetadata!)Called when the value of |
Unit |
This function is deprecated. Use |
Unit |
onPositionDiscontinuity(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 |
onRepeatModeChanged(@Player.RepeatMode repeatMode: Int)Called when the value of |
Unit |
onSeekBackIncrementChanged(seekBackIncrementMs: Long)Called when the value of |
Unit |
onSeekForwardIncrementChanged(seekForwardIncrementMs: Long)Called when the value of |
Unit |
onShuffleModeEnabledChanged(shuffleModeEnabled: Boolean)Called when the value of |
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(Called when the value of |
Unit |
onTrackSelectionParametersChanged(parameters: TrackSelectionParameters!)Called when the value returned from |
Unit |
onTracksChanged(tracks: Tracks!)Called when the value of |
Unit |
onVideoSizeChanged(videoSize: VideoSize!)Called each time when |
Unit |
onVolumeChanged(volume: Float)Called when the value of |
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 |
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
funonCues(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 |
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.
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:
- They intend to trigger the same logic for multiple events (e.g. when updating a UI for both
onPlaybackStateChangedandonPlayWhenReadyChanged). - They need access to the
Playerobject to trigger further events (e.g. to callseekToafter aonMediaItemTransition). - They intend to use multiple state values together or in combination with
Playergetter methods. For example usinggetCurrentMediaItemIndexwith thetimelineprovided inonTimelineChangedis only safe from within this method. - They are interested in events that logically happened together (e.g
onPlaybackStateChangedtoSTATE_BUFFERINGbecause ofonMediaItemTransition).
| Parameters | |
|---|---|
player: Player! |
The |
events: Player.Events! |
The |
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. |
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 |
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 |
@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 |
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 |
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 |
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 |
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
funonPlayerStateChanged(
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
funonPositionDiscontinuity(@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 |
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 |
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.
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 |
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 |
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 |
height: Int |
The surface height in pixels. May be |
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 |
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 |
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. |