Package com.google.android.exoplayer2.analytics

## Interface AnalyticsCollector

- All Superinterfaces:
    `BandwidthMeter.EventListener`, `DrmSessionEventListener`, `MediaSourceEventListener`, `Player.Listener`
  All Known Implementing Classes:
    `DefaultAnalyticsCollector`

      public interface AnalyticsCollector
      extends Player.Listener, MediaSourceEventListener, BandwidthMeter.EventListener, DrmSessionEventListener

  Interface for data collectors that forward analytics events to `AnalyticsListeners`.

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from interface com.google.android.exoplayer2.upstream.BandwidthMeter.EventListener

      `BandwidthMeter.EventListener.EventDispatcher`

    - ### Nested classes/interfaces inherited from interface com.google.android.exoplayer2.drm.DrmSessionEventListener

      `DrmSessionEventListener.EventDispatcher`

    - ### Nested classes/interfaces inherited from interface com.google.android.exoplayer2.source.MediaSourceEventListener

      `MediaSourceEventListener.EventDispatcher`

  - ### Method Summary

    All Methods Instance Methods Abstract Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `void` | `addListener​(AnalyticsListener listener)` | Adds a listener for analytics events.
    `void` | `notifySeekStarted()` | Notify analytics collector that a seek operation will start.
    `void` | `onAudioCodecError​(Exception audioCodecError)` | Called when an audio decoder encounters an error.
    `void` | `onAudioDecoderInitialized​(String decoderName, long initializedTimestampMs, long initializationDurationMs)` | Called when a audio decoder is created.
    `void` | `onAudioDecoderReleased​(String decoderName)` | Called when a audio decoder is released.
    `void` | `onAudioDisabled​(DecoderCounters counters)` | Called when the audio renderer is disabled.
    `void` | `onAudioEnabled​(DecoderCounters counters)` | Called when the audio renderer is enabled.
    `void` | `onAudioInputFormatChanged​(Format format, DecoderReuseEvaluation decoderReuseEvaluation)` | Called when the format of the media being consumed by the audio renderer changes.
    `void` | `onAudioPositionAdvancing​(long playoutStartSystemTimeMs)` | Called when the audio position has increased for the first time since the last pause or position reset.
    `void` | `onAudioSinkError​(Exception audioSinkError)` | Called when `AudioSink` has encountered an error.
    `void` | `onAudioUnderrun​(int bufferSize, long bufferSizeMs, long elapsedSinceLastFeedMs)` | Called when an audio underrun occurs.
    `void` | `onDroppedFrames​(int count, long elapsedMs)` | Called to report the number of frames dropped by the video renderer.
    `void` | `onRenderedFirstFrame​(Object output, long renderTimeMs)` | Called when a frame is rendered for the first time since setting the output, or since the renderer was reset, or since the stream being rendered was changed.
    `void` | `onVideoCodecError​(Exception videoCodecError)` | Called when a video decoder encounters an error.
    `void` | `onVideoDecoderInitialized​(String decoderName, long initializedTimestampMs, long initializationDurationMs)` | Called when a video decoder is created.
    `void` | `onVideoDecoderReleased​(String decoderName)` | Called when a video decoder is released.
    `void` | `onVideoDisabled​(DecoderCounters counters)` | Called when the video renderer is disabled.
    `void` | `onVideoEnabled​(DecoderCounters counters)` | Called when the video renderer is enabled.
    `void` | `onVideoFrameProcessingOffset​(long totalProcessingOffsetUs, int frameCount)` | Called to report the video processing offset of video frames processed by the video renderer.
    `void` | `onVideoInputFormatChanged​(Format format, DecoderReuseEvaluation decoderReuseEvaluation)` | Called when the format of the media being consumed by the video renderer changes.
    `void` | `release()` | Releases the collector.
    `void` | `removeListener​(AnalyticsListener listener)` | Removes a previously added analytics event listener.
    `void` | `setPlayer​(Player player, Looper looper)` | Sets the player for which data will be collected.
    `void` | `updateMediaPeriodQueueInfo​(List<MediaSource.MediaPeriodId> queue, MediaSource.MediaPeriodId readingPeriod)` | Updates the playback queue information used for event association.

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

      `onBandwidthSample`

    - ### Methods inherited from interface com.google.android.exoplayer2.drm.DrmSessionEventListener

      `onDrmKeysLoaded, onDrmKeysRemoved, onDrmKeysRestored, onDrmSessionAcquired, onDrmSessionAcquired, onDrmSessionManagerError, onDrmSessionReleased`

    - ### Methods inherited from interface com.google.android.exoplayer2.source.MediaSourceEventListener

      `onDownstreamFormatChanged, onLoadCanceled, onLoadCompleted, onLoadError, onLoadStarted, onUpstreamDiscarded`

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

      `onAudioAttributesChanged, onAudioSessionIdChanged, onAvailableCommandsChanged, onCues, onCues, onDeviceInfoChanged, onDeviceVolumeChanged, onEvents, onIsLoadingChanged, onIsPlayingChanged, onLoadingChanged, onMaxSeekToPreviousPositionChanged, onMediaItemTransition, onMediaMetadataChanged, onMetadata, onPlaybackParametersChanged, onPlaybackStateChanged, onPlaybackSuppressionReasonChanged, onPlayerError, onPlayerErrorChanged, onPlayerStateChanged, onPlaylistMetadataChanged, onPlayWhenReadyChanged, onPositionDiscontinuity, onPositionDiscontinuity, onRenderedFirstFrame, onRepeatModeChanged, onSeekBackIncrementChanged, onSeekForwardIncrementChanged, onSeekProcessed, onShuffleModeEnabledChanged, onSkipSilenceEnabledChanged, onSurfaceSizeChanged, onTimelineChanged, onTracksChanged, onTrackSelectionParametersChanged, onVideoSizeChanged, onVolumeChanged`

- - ### Method Detail

    - #### addListener

          void addListener​(AnalyticsListener listener)

      Adds a listener for analytics events.
      Parameters:
        `listener` - The listener to add.

    - #### removeListener

          void removeListener​(AnalyticsListener listener)

      Removes a previously added analytics event listener.
      Parameters:
        `listener` - The listener to remove.

    - #### setPlayer

          void setPlayer​(Player player,
                         Looper looper)

      Sets the player for which data will be collected. Must only be called if no player has been set yet or the current player is idle.
      Parameters:
        `player` - The `Player` for which data will be collected.
        `looper` - The `Looper` used for listener callbacks.

    - #### release

          void release()

      Releases the collector. Must be called after the player for which data is collected has been released.

    - #### updateMediaPeriodQueueInfo

          void updateMediaPeriodQueueInfo​(List<MediaSource.MediaPeriodId> queue,
                                          @Nullable
                                          MediaSource.MediaPeriodId readingPeriod)

      Updates the playback queue information used for event association.

      Should only be called by the player controlling the queue and not from app code.

      Parameters:
        `queue` - The playback queue of media periods identified by their `MediaSource.MediaPeriodId`.
        `readingPeriod` - The media period in the queue that is currently being read by renderers, or null if the queue is empty.

    - #### notifySeekStarted

          void notifySeekStarted()

      Notify analytics collector that a seek operation will start. Should be called before the player adjusts its state and position to the seek.

    - #### onAudioEnabled

          void onAudioEnabled​(DecoderCounters counters)

      Called when the audio renderer is enabled.
      Parameters:
        `counters` - `DecoderCounters` that will be updated by the audio renderer for as long as it remains enabled.

    - #### onAudioDecoderInitialized

          void onAudioDecoderInitialized​(String decoderName,
                                         long initializedTimestampMs,
                                         long initializationDurationMs)

      Called when a audio decoder is created.
      Parameters:
        `decoderName` - The audio decoder that was created.
        `initializedTimestampMs` - `SystemClock.elapsedRealtime()` when initialization finished.
        `initializationDurationMs` - The time taken to initialize the decoder in milliseconds.

    - #### onAudioInputFormatChanged

          void onAudioInputFormatChanged​(Format format,
                                         @Nullable
                                         DecoderReuseEvaluation decoderReuseEvaluation)

      Called when the format of the media being consumed by the audio renderer changes.
      Parameters:
        `format` - The new format.
        `decoderReuseEvaluation` - The result of the evaluation to determine whether an existing decoder instance can be reused for the new format, or `null` if the renderer did not have a decoder.

    - #### onAudioPositionAdvancing

          void onAudioPositionAdvancing​(long playoutStartSystemTimeMs)

      Called when the audio position has increased for the first time since the last pause or position reset.
      Parameters:
        `playoutStartSystemTimeMs` - The approximate derived `System.currentTimeMillis()` at which playout started.

    - #### onAudioUnderrun

          void onAudioUnderrun​(int bufferSize,
                               long bufferSizeMs,
                               long elapsedSinceLastFeedMs)

      Called when an audio underrun occurs.
      Parameters:
        `bufferSize` - The size of the audio output buffer, in bytes.
        `bufferSizeMs` - The size of the audio output buffer, in milliseconds, if it contains PCM encoded audio. `C.TIME_UNSET` if the output buffer contains non-PCM encoded audio.
        `elapsedSinceLastFeedMs` - The time since audio was last written to the output buffer.

    - #### onAudioDecoderReleased

          void onAudioDecoderReleased​(String decoderName)

      Called when a audio decoder is released.
      Parameters:
        `decoderName` - The audio decoder that was released.

    - #### onAudioDisabled

          void onAudioDisabled​(DecoderCounters counters)

      Called when the audio renderer is disabled.
      Parameters:
        `counters` - `DecoderCounters` that were updated by the audio renderer.

    - #### onAudioSinkError

          void onAudioSinkError​(Exception audioSinkError)

      Called when `AudioSink` has encountered an error.

      If the sink writes to a platform `AudioTrack`, this will be called for all `AudioTrack` errors.

      Parameters:
        `audioSinkError` - The error that occurred. Typically an `AudioSink.InitializationException`, a `AudioSink.WriteException`, or an `AudioSink.UnexpectedDiscontinuityException`.

    - #### onAudioCodecError

          void onAudioCodecError​(Exception audioCodecError)

      Called when an audio decoder encounters an error.
      Parameters:
        `audioCodecError` - The error. Typically a `MediaCodec.CodecException` if the renderer uses `MediaCodec`, or a `DecoderException` if the renderer uses a software decoder.

    - #### onVideoEnabled

          void onVideoEnabled​(DecoderCounters counters)

      Called when the video renderer is enabled.
      Parameters:
        `counters` - `DecoderCounters` that will be updated by the video renderer for as long as it remains enabled.

    - #### onVideoDecoderInitialized

          void onVideoDecoderInitialized​(String decoderName,
                                         long initializedTimestampMs,
                                         long initializationDurationMs)

      Called when a video decoder is created.
      Parameters:
        `decoderName` - The decoder that was created.
        `initializedTimestampMs` - `SystemClock.elapsedRealtime()` when initialization finished.
        `initializationDurationMs` - The time taken to initialize the decoder in milliseconds.

    - #### onVideoInputFormatChanged

          void onVideoInputFormatChanged​(Format format,
                                         @Nullable
                                         DecoderReuseEvaluation decoderReuseEvaluation)

      Called when the format of the media being consumed by the video renderer changes.
      Parameters:
        `format` - The new format.
        `decoderReuseEvaluation` - The result of the evaluation to determine whether an existing decoder instance can be reused for the new format, or `null` if the renderer did not have a decoder.

    - #### onDroppedFrames

          void onDroppedFrames​(int count,
                               long elapsedMs)

      Called to report the number of frames dropped by the video renderer. Dropped frames are reported whenever the renderer is stopped having dropped frames, and optionally, whenever the count reaches a specified threshold whilst the renderer is started.
      Parameters:
        `count` - The number of dropped frames.
        `elapsedMs` - The duration in milliseconds over which the frames were dropped. This duration is timed from when the renderer was started or from when dropped frames were last reported (whichever was more recent), and not from when the first of the reported drops occurred.

    - #### onVideoDecoderReleased

          void onVideoDecoderReleased​(String decoderName)

      Called when a video decoder is released.
      Parameters:
        `decoderName` - The video decoder that was released.

    - #### onVideoDisabled

          void onVideoDisabled​(DecoderCounters counters)

      Called when the video renderer is disabled.
      Parameters:
        `counters` - `DecoderCounters` that were updated by the video renderer.

    - #### onRenderedFirstFrame

          void onRenderedFirstFrame​(Object output,
                                    long renderTimeMs)

      Called when a frame is rendered for the first time since setting the output, or since the renderer was reset, or since the stream being rendered was changed.
      Parameters:
        `output` - The output of the video renderer. Normally a `Surface`, however some video renderers may have other output types (e.g., a `VideoDecoderOutputBufferRenderer`).
        `renderTimeMs` - The `SystemClock.elapsedRealtime()` when the frame was rendered.

    - #### onVideoFrameProcessingOffset

          void onVideoFrameProcessingOffset​(long totalProcessingOffsetUs,
                                            int frameCount)

      Called to report the video processing offset of video frames processed by the video renderer.

      Video processing offset represents how early a video frame is processed compared to the player's current position. For each video frame, the offset is calculated as Pvf - Ppl where Pvf is the presentation timestamp of the video frame and Ppl is the current position of the player. Positive values indicate the frame was processed early enough whereas negative values indicate that the player's position had progressed beyond the frame's timestamp when the frame was processed (and the frame was probably dropped).

      The renderer reports the sum of video processing offset samples (one sample per processed video frame: dropped, skipped or rendered) and the total number of samples.

      Parameters:
        `totalProcessingOffsetUs` - The sum of all video frame processing offset samples for the video frames processed by the renderer in microseconds.
        `frameCount` - The number of samples included in the `totalProcessingOffsetUs`.

    - #### onVideoCodecError

          void onVideoCodecError​(Exception videoCodecError)

      Called when a video decoder encounters an error.

      This method being called does not indicate that playback has failed, or that it will fail. The player may be able to recover from the error. Hence applications should not implement this method to display a user visible error or initiate an application level retry. `Player.Listener.onPlayerError(com.google.android.exoplayer2.PlaybackException)` is the appropriate place to implement such behavior. This method is called to provide the application with an opportunity to log the error if it wishes to do so.

      Parameters:
        `videoCodecError` - The error. Typically a `MediaCodec.CodecException` if the renderer uses `MediaCodec`, or a `DecoderException` if the renderer uses a software decoder.