Interface Player.Listener

  • All Known Subinterfaces:
    AnalyticsCollector
    All Known Implementing Classes:
    DefaultAnalyticsCollector, ExoPlayerTestRunner
    Enclosing interface:
    Player

    public static interface Player.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 Detail

      • onMediaItemTransition

        default void onMediaItemTransition​(@Nullable
                                           MediaItem mediaItem,
                                           @MediaItemTransitionReason
                                           @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)
        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)
        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.
      • 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.
      • onPlaybackStateChanged

        default void onPlaybackStateChanged​(@State
                                            @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.
      • 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
                                         @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 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 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

        default void onPositionDiscontinuity​(Player.PositionInfo oldPosition,
                                             Player.PositionInfo newPosition,
                                             @DiscontinuityReason
                                             @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)
        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 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)
        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 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

        default void onCues​(CueGroup 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)
        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.