Package com.google.android.exoplayer2

## Interface Player.Listener

- All Superinterfaces:
    `AudioListener`, `DeviceListener`, `MetadataOutput`, `Player.EventListener`, `TextOutput`, `VideoListener`
  All Known Implementing Classes:
    `AnalyticsCollector`, `DebugTextViewHelper`, `ExoPlayerTestRunner`, `ImaAdsLoader`
  Enclosing interface:
    Player

      public static interface Player.Listener
      extends VideoListener, AudioListener, TextOutput, MetadataOutput, DeviceListener, 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 void` | `onAudioAttributesChanged​(AudioAttributes audioAttributes)` | Called when the audio attributes change.
    `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​(List<Cue> cues)` | Called when there is a change in the `Cues`.
    `default void` | `onDeviceInfoChanged​(DeviceInfo deviceInfo)` | Called when the device information changes.
    `default void` | `onDeviceVolumeChanged​(int volume, boolean muted)` | Called when the device volume or mute state 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` | `onMediaItemTransition​(MediaItem mediaItem, 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 combined `MediaMetadata` changes.
    `default void` | `onMetadata​(Metadata metadata)` | Called when there is metadata associated with current playback time.
    `default void` | `onPlaybackParametersChanged​(PlaybackParameters playbackParameters)` | Called when the current playback parameters change.
    `default void` | `onPlaybackStateChanged​(int playbackState)` | Called when the value returned from `Player.getPlaybackState()` changes.
    `default void` | `onPlaybackSuppressionReasonChanged​(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` | `onPlaylistMetadataChanged​(MediaMetadata mediaMetadata)` | Called when the playlist `MediaMetadata` changes.
    `default void` | `onPlayWhenReadyChanged​(boolean playWhenReady, int reason)` | Called when the value returned from `Player.getPlayWhenReady()` changes.
    `default void` | `onPositionDiscontinuity​(Player.PositionInfo oldPosition, Player.PositionInfo newPosition, 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​(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, int reason)` | Called when the timeline has been refreshed.
    `default void` | `onTracksChanged​(TrackGroupArray trackGroups, TrackSelectionArray trackSelections)` | Called when the available or selected tracks change.
    `default void` | `onVideoSizeChanged​(VideoSize videoSize)` | Called each time there's a change in the size of the video being rendered.
    `default void` | `onVolumeChanged​(float volume)` | Called when the volume changes.

    - ### Methods inherited from interface com.google.android.exoplayer2.Player.EventListener

      `onLoadingChanged, onMaxSeekToPreviousPositionChanged, onPlayerStateChanged, onPositionDiscontinuity, onSeekProcessed, onStaticMetadataChanged`

    - ### Methods inherited from interface com.google.android.exoplayer2.video.VideoListener

      `onVideoSizeChanged`

- - ### Method Detail

    - #### onTimelineChanged

          default void onTimelineChanged​(Timeline timeline,
                                         @TimelineChangeReason
                                         int reason)

      Description copied from interface: `Player.EventListener`
      Called when the timeline has been refreshed.

      Note that the current window or period index may change as a result of a timeline change. If playback can't continue smoothly because of this timeline change, a separate `Player.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 same `Looper` message queue iteration.

      Specified by:
        `onTimelineChanged` in interface `Player.EventListener`
      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,
                                             @MediaItemTransitionReason
                                             int reason)

      Description copied from interface: `Player.EventListener`
      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 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 same `Looper` message queue iteration.

      Specified by:
        `onMediaItemTransition` in interface `Player.EventListener`
      Parameters:
        `mediaItem` - The `MediaItem`. May be null if the playlist becomes empty.
        `reason` - The reason for the transition.

    - #### onTracksChanged

          default void onTracksChanged​(TrackGroupArray trackGroups,
                                       TrackSelectionArray trackSelections)

      Description copied from interface: `Player.EventListener`
      Called 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 same `Looper` message queue iteration.

      Specified by:
        `onTracksChanged` in interface `Player.EventListener`
      Parameters:
        `trackGroups` - The available tracks. Never null, but may be of length zero.
        `trackSelections` - The selected tracks. Never null, but may contain null elements. A concrete implementation may include null elements if it has a fixed number of renderer components, wishes to report a TrackSelection for each of them, and has one or more renderer components that is not assigned any selected tracks.

    - #### onIsLoadingChanged

          default void onIsLoadingChanged​(boolean isLoading)

      Description copied from interface: `Player.EventListener`
      Called 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 same `Looper` message queue iteration.

      Specified by:
        `onIsLoadingChanged` in interface `Player.EventListener`
      Parameters:
        `isLoading` - Whether the source is currently being loaded.

    - #### onAvailableCommandsChanged

          default void onAvailableCommandsChanged​(Player.Commands availableCommands)

      Description copied from interface: `Player.EventListener`
      Called when the value returned from `Player.isCommandAvailable(int)` changes for at least one `Player.Command`.

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

      Specified by:
        `onAvailableCommandsChanged` in interface `Player.EventListener`
      Parameters:
        `availableCommands` - The available `Player.Commands`.

    - #### onPlaybackStateChanged

          default void onPlaybackStateChanged​(@State
                                              int playbackState)

      Description copied from interface: `Player.EventListener`
      Called when the value returned from `Player.getPlaybackState()` changes.

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

      Specified by:
        `onPlaybackStateChanged` in interface `Player.EventListener`
      Parameters:
        `playbackState` - The new playback `state`.

    - #### onPlayWhenReadyChanged

          default void onPlayWhenReadyChanged​(boolean playWhenReady,
                                              @PlayWhenReadyChangeReason
                                              int reason)

      Description copied from interface: `Player.EventListener`
      Called when the value returned from `Player.getPlayWhenReady()` changes.

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

      Specified by:
        `onPlayWhenReadyChanged` in interface `Player.EventListener`
      Parameters:
        `playWhenReady` - Whether playback will proceed when ready.
        `reason` - The `reason` for the change.

    - #### onPlaybackSuppressionReasonChanged

          default void onPlaybackSuppressionReasonChanged​(@PlaybackSuppressionReason
                                                          int playbackSuppressionReason)

      Description copied from interface: `Player.EventListener`
      Called when the value returned from `Player.getPlaybackSuppressionReason()` changes.

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

      Specified by:
        `onPlaybackSuppressionReasonChanged` in interface `Player.EventListener`
      Parameters:
        `playbackSuppressionReason` - The current `Player.PlaybackSuppressionReason`.

    - #### onIsPlayingChanged

          default void onIsPlayingChanged​(boolean isPlaying)

      Description copied from interface: `Player.EventListener`
      Called when the value of `Player.isPlaying()` changes.

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

      Specified by:
        `onIsPlayingChanged` in interface `Player.EventListener`
      Parameters:
        `isPlaying` - Whether the player is playing.

    - #### onRepeatModeChanged

          default void onRepeatModeChanged​(@RepeatMode
                                           int repeatMode)

      Description copied from interface: `Player.EventListener`
      Called when the value of `Player.getRepeatMode()` changes.

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

      Specified by:
        `onRepeatModeChanged` in interface `Player.EventListener`
      Parameters:
        `repeatMode` - The `Player.RepeatMode` used for playback.

    - #### onShuffleModeEnabledChanged

          default void onShuffleModeEnabledChanged​(boolean shuffleModeEnabled)

      Description copied from interface: `Player.EventListener`
      Called when the value of `Player.getShuffleModeEnabled()` changes.

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

      Specified by:
        `onShuffleModeEnabledChanged` in interface `Player.EventListener`
      Parameters:
        `shuffleModeEnabled` - Whether shuffling of windows is enabled.

    - #### onPlayerError

          default void onPlayerError​(PlaybackException error)

      Description copied from interface: `Player.EventListener`
      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.

      `Player.EventListener.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.

      Specified by:
        `onPlayerError` in interface `Player.EventListener`
      Parameters:
        `error` - The error.

    - #### onPlayerErrorChanged

          default void onPlayerErrorChanged​(@Nullable
                                            PlaybackException error)

      Description copied from interface: `Player.EventListener`
      Called when the `PlaybackException` returned by `Player.getPlayerError()` changes.

      `Player.EventListener.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.

      Specified by:
        `onPlayerErrorChanged` in interface `Player.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
                                               int reason)

      Description copied from interface: `Player.EventListener`
      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.

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

      Specified by:
        `onPositionDiscontinuity` in interface `Player.EventListener`
      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)

      Description copied from interface: `Player.EventListener`
      Called when the current playback parameters change. 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).

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

      Specified by:
        `onPlaybackParametersChanged` in interface `Player.EventListener`
      Parameters:
        `playbackParameters` - The playback parameters.

    - #### onSeekForwardIncrementChanged

          default void onSeekForwardIncrementChanged​(long seekForwardIncrementMs)

      Description copied from interface: `Player.EventListener`
      Called when the value of `Player.getSeekForwardIncrement()` changes.

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

      Specified by:
        `onSeekForwardIncrementChanged` in interface `Player.EventListener`
      Parameters:
        `seekForwardIncrementMs` - The `Player.seekForward()` increment, in milliseconds.

    - #### onSeekBackIncrementChanged

          default void onSeekBackIncrementChanged​(long seekBackIncrementMs)

      Description copied from interface: `Player.EventListener`
      Called when the value of `Player.getSeekBackIncrement()` changes.

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

      Specified by:
        `onSeekBackIncrementChanged` in interface `Player.EventListener`
      Parameters:
        `seekBackIncrementMs` - The `Player.seekBack()` increment, in milliseconds.

    - #### onAudioSessionIdChanged

          default void onAudioSessionIdChanged​(int audioSessionId)

      Description copied from interface: `AudioListener`
      Called when the audio session ID changes.
      Specified by:
        `onAudioSessionIdChanged` in interface `AudioListener`
      Parameters:
        `audioSessionId` - The audio session ID.

    - #### onAudioAttributesChanged

          default void onAudioAttributesChanged​(AudioAttributes audioAttributes)

      Description copied from interface: `AudioListener`
      Called when the audio attributes change.
      Specified by:
        `onAudioAttributesChanged` in interface `AudioListener`
      Parameters:
        `audioAttributes` - The audio attributes.

    - #### onVolumeChanged

          default void onVolumeChanged​(float volume)

      Description copied from interface: `AudioListener`
      Called when the volume changes.
      Specified by:
        `onVolumeChanged` in interface `AudioListener`
      Parameters:
        `volume` - The new volume, with 0 being silence and 1 being unity gain.

    - #### onSkipSilenceEnabledChanged

          default void onSkipSilenceEnabledChanged​(boolean skipSilenceEnabled)

      Description copied from interface: `AudioListener`
      Called when skipping silences is enabled or disabled in the audio stream.
      Specified by:
        `onSkipSilenceEnabledChanged` in interface `AudioListener`
      Parameters:
        `skipSilenceEnabled` - Whether skipping silences in the audio stream is enabled.

    - #### onDeviceInfoChanged

          default void onDeviceInfoChanged​(DeviceInfo deviceInfo)

      Description copied from interface: `DeviceListener`
      Called when the device information changes.
      Specified by:
        `onDeviceInfoChanged` in interface `DeviceListener`

    - #### onDeviceVolumeChanged

          default void onDeviceVolumeChanged​(int volume,
                                             boolean muted)

      Description copied from interface: `DeviceListener`
      Called when the device volume or mute state changes.
      Specified by:
        `onDeviceVolumeChanged` in interface `DeviceListener`

    - #### onEvents

          default void onEvents​(Player player,
                                Player.Events events)

      Description copied from interface: `Player.EventListener`
      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.

      Only state changes represented by `events` are 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)` and `Player.EventListener.onPlayWhenReadyChanged(boolean, int)`).
      - They need access to the `Player` object to trigger further events (e.g. to call `Player.seekTo(long)` after a `Player.EventListener.onMediaItemTransition(MediaItem, int)`).
      - They intend to use multiple state values together or in combination with `Player` getter methods. For example using `Player.getCurrentWindowIndex()` with the `timeline` provided in `Player.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)` to `Player.STATE_BUFFERING` because of `Player.EventListener.onMediaItemTransition(MediaItem, int)`).
      Specified by:
        `onEvents` in interface `Player.EventListener`
      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.

    - #### onVideoSizeChanged

          default void onVideoSizeChanged​(VideoSize videoSize)

      Description copied from interface: `VideoListener`
      Called each time there's a change in the size of the video being rendered.
      Specified by:
        `onVideoSizeChanged` in interface `VideoListener`
      Parameters:
        `videoSize` - The new size of the video.

    - #### onSurfaceSizeChanged

          default void onSurfaceSizeChanged​(int width,
                                            int height)

      Description copied from interface: `VideoListener`
      Called each time there's a change in the size of the surface onto which the video is being rendered.
      Specified by:
        `onSurfaceSizeChanged` in interface `VideoListener`
      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()

      Description copied from interface: `VideoListener`
      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.
      Specified by:
        `onRenderedFirstFrame` in interface `VideoListener`

    - #### onCues

          default void onCues​(List<Cue> cues)

      Description copied from interface: `TextOutput`
      Called when there is a change in the `Cues`.

      `cues` is in ascending order of priority. If any of the cue boxes overlap when displayed, the `Cue` nearer the end of the list should be shown on top.

      Specified by:
        `onCues` in interface `TextOutput`
      Parameters:
        `cues` - The `Cues`. May be empty.

    - #### onMetadata

          default void onMetadata​(Metadata metadata)

      Description copied from interface: `MetadataOutput`
      Called when there is metadata associated with current playback time.
      Specified by:
        `onMetadata` in interface `MetadataOutput`
      Parameters:
        `metadata` - The metadata.

    - #### onMediaMetadataChanged

          default void onMediaMetadataChanged​(MediaMetadata mediaMetadata)

      Description copied from interface: `Player.EventListener`
      Called when the combined `MediaMetadata` changes.

      The provided `MediaMetadata` is a combination of the `MediaItem.mediaMetadata` and the static and dynamic metadata from the `track selections' formats` and `MetadataOutput.onMetadata(Metadata)`.

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

      Specified by:
        `onMediaMetadataChanged` in interface `Player.EventListener`
      Parameters:
        `mediaMetadata` - The combined `MediaMetadata`.

    - #### onPlaylistMetadataChanged

          default void onPlaylistMetadataChanged​(MediaMetadata mediaMetadata)

      Description copied from interface: `Player.EventListener`
      Called when the playlist `MediaMetadata` changes.
      Specified by:
        `onPlaylistMetadataChanged` in interface `Player.EventListener`