DefaultAnalyticsCollector


@UnstableApi
class DefaultAnalyticsCollector : AnalyticsCollector


Data collector that forwards analytics events to AnalyticsListeners.

Summary

Public constructors

Creates an analytics collector.

Public functions

Unit

Adds a listener for analytics events.

Unit

Notifies the analytics collector that a seek operation will start.

Unit

Called when the value of getAudioAttributes changes.

Unit
onAudioCodecError(audioCodecError: Exception!)

Called when an audio decoder encounters an error.

Unit
onAudioDecoderInitialized(
    decoderName: String!,
    initializedTimestampMs: Long,
    initializationDurationMs: Long
)

Called when a audio decoder is created.

Unit

Called when a audio decoder is released.

Unit

Called when the audio renderer is disabled.

Unit

Called when the audio renderer is enabled.

Unit
onAudioInputFormatChanged(
    format: Format!,
    decoderReuseEvaluation: DecoderReuseEvaluation?
)

Called when the format of the media being consumed by the audio renderer changes.

Unit
onAudioPositionAdvancing(playoutStartSystemTimeMs: Long)

Called when the audio position has increased for the first time since the last pause or position reset.

Unit
onAudioSessionIdChanged(audioSessionId: Int)

Called when the audio session ID changes.

Unit
onAudioSinkError(audioSinkError: Exception!)

Called when AudioSink has encountered an error.

Unit

Called when an AudioTrack has been initialized.

Unit

Called when an AudioTrack has been released.

Unit
onAudioUnderrun(
    bufferSize: Int,
    bufferSizeMs: Long,
    elapsedSinceLastFeedMs: Long
)

Called when an audio underrun occurs.

Unit

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

Unit
onBandwidthSample(
    elapsedMs: Int,
    bytesTransferred: Long,
    bitrateEstimate: Long
)

Called periodically to indicate that bytes have been transferred or the estimated bitrate has changed.

Unit
onCues(cueGroup: CueGroup!)

Called when the value of getCurrentCues changes.

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

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
onDownstreamFormatChanged(
    windowIndex: Int,
    mediaPeriodId: MediaSource.MediaPeriodId?,
    mediaLoadData: MediaLoadData!
)

Called when a downstream format change occurs (i.e. when the format of the media being read from one or more SampleStreams provided by the source changes).

Unit
onDrmKeysLoaded(
    windowIndex: Int,
    mediaPeriodId: MediaSource.MediaPeriodId?
)

Called each time keys are loaded.

Unit
onDrmKeysRemoved(
    windowIndex: Int,
    mediaPeriodId: MediaSource.MediaPeriodId?
)

Called each time offline keys are removed.

Unit
onDrmKeysRestored(
    windowIndex: Int,
    mediaPeriodId: MediaSource.MediaPeriodId?
)

Called each time offline keys are restored.

Unit
onDrmSessionAcquired(
    windowIndex: Int,
    mediaPeriodId: MediaSource.MediaPeriodId?,
    @DrmSession.State state: Int
)

Called each time a drm session is acquired.

Unit
onDrmSessionManagerError(
    windowIndex: Int,
    mediaPeriodId: MediaSource.MediaPeriodId?,
    error: Exception!
)

Called when a drm error occurs.

Unit
onDrmSessionReleased(
    windowIndex: Int,
    mediaPeriodId: MediaSource.MediaPeriodId?
)

Called each time a drm session is released.

Unit
onDroppedFrames(count: Int, elapsedMs: Long)

Called to report the number of frames dropped by the video renderer.

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
onLoadCanceled(
    windowIndex: Int,
    mediaPeriodId: MediaSource.MediaPeriodId?,
    loadEventInfo: LoadEventInfo!,
    mediaLoadData: MediaLoadData!
)

Called when a load is canceled.

Unit
onLoadCompleted(
    windowIndex: Int,
    mediaPeriodId: MediaSource.MediaPeriodId?,
    loadEventInfo: LoadEventInfo!,
    mediaLoadData: MediaLoadData!
)

Called when a load ends.

Unit
onLoadError(
    windowIndex: Int,
    mediaPeriodId: MediaSource.MediaPeriodId?,
    loadEventInfo: LoadEventInfo!,
    mediaLoadData: MediaLoadData!,
    error: IOException!,
    wasCanceled: Boolean
)

Called when a load error occurs.

Unit
onLoadStarted(
    windowIndex: Int,
    mediaPeriodId: MediaSource.MediaPeriodId?,
    loadEventInfo: LoadEventInfo!,
    mediaLoadData: MediaLoadData!
)

Called when a load begins.

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
onMetadata(metadata: Metadata!)

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
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
onRenderedFirstFrame(output: Any!, renderTimeMs: Long)

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.

Unit
onRendererReadyChanged(
    rendererIndex: Int,
    @C.TrackType rendererTrackType: Int,
    isRendererReady: Boolean
)

Called each time a renderer starts or stops allowing playback to be ready.

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
onUpstreamDiscarded(
    windowIndex: Int,
    mediaPeriodId: MediaSource.MediaPeriodId?,
    mediaLoadData: MediaLoadData!
)

Called when data is removed from the back of a media buffer, typically so that it can be re-buffered in a different format.

Unit
onVideoCodecError(videoCodecError: Exception!)

Called when a video decoder encounters an error.

Unit
onVideoDecoderInitialized(
    decoderName: String!,
    initializedTimestampMs: Long,
    initializationDurationMs: Long
)

Called when a video decoder is created.

Unit

Called when a video decoder is released.

Unit

Called when the video renderer is disabled.

Unit

Called when the video renderer is enabled.

Unit
onVideoFrameProcessingOffset(
    totalProcessingOffsetUs: Long,
    frameCount: Int
)

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

Unit
onVideoInputFormatChanged(
    format: Format!,
    decoderReuseEvaluation: DecoderReuseEvaluation?
)

Called when the format of the media being consumed by the video renderer changes.

Unit

Called each time when getVideoSize changes.

Unit

Called when the value of getVolume changes.

Unit

Releases the collector.

Unit

Removes a previously added analytics event listener.

Unit
@CallSuper
setPlayer(player: Player!, looper: Looper!)

Sets the player for which data will be collected.

Unit
setThrowsWhenUsingWrongThread(throwsWhenUsingWrongThread: Boolean)

This function is deprecated.

Do not use this method and ensure all calls are made from the correct thread.

Unit

Updates the playback queue information used for event association.

Protected functions

AnalyticsListener.EventTime!

Generates an EventTime for the currently playing item in the player.

AnalyticsListener.EventTime!
@RequiresNonNull(value = "player")
generateEventTime(
    timeline: Timeline!,
    windowIndex: Int,
    mediaPeriodId: MediaSource.MediaPeriodId?
)

Returns a new EventTime for the specified timeline, window and media period id.

Unit
sendEvent(
    eventTime: AnalyticsListener.EventTime!,
    eventFlag: Int,
    eventInvocation: ListenerSet.Event<AnalyticsListener!>!
)

Sends an event to registered listeners.

Public constructors

DefaultAnalyticsCollector

DefaultAnalyticsCollector(clock: Clock!)

Creates an analytics collector.

Parameters
clock: Clock!

A Clock used to generate timestamps.

Public functions

addListener

@CallSuper
fun addListener(listener: AnalyticsListener!): Unit

Adds a listener for analytics events.

Parameters
listener: AnalyticsListener!

The listener to add.

notifySeekStarted

fun notifySeekStarted(): Unit

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

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.

onAudioCodecError

fun onAudioCodecError(audioCodecError: Exception!): Unit

Called when an audio decoder encounters an error.

Parameters
audioCodecError: Exception!

The error. Typically a CodecException if the renderer uses MediaCodec, or a DecoderException if the renderer uses a software decoder.

onAudioDecoderInitialized

fun onAudioDecoderInitialized(
    decoderName: String!,
    initializedTimestampMs: Long,
    initializationDurationMs: Long
): Unit

Called when a audio decoder is created.

Parameters
decoderName: String!

The audio decoder that was created.

initializedTimestampMs: Long

elapsedRealtime when initialization finished.

initializationDurationMs: Long

The time taken to initialize the decoder in milliseconds.

onAudioDecoderReleased

fun onAudioDecoderReleased(decoderName: String!): Unit

Called when a audio decoder is released.

Parameters
decoderName: String!

The audio decoder that was released.

onAudioDisabled

fun onAudioDisabled(counters: DecoderCounters!): Unit

Called when the audio renderer is disabled.

Parameters
counters: DecoderCounters!

DecoderCounters that were updated by the audio renderer.

onAudioEnabled

fun onAudioEnabled(counters: DecoderCounters!): Unit

Called when the audio renderer is enabled.

Parameters
counters: DecoderCounters!

DecoderCounters that will be updated by the audio renderer for as long as it remains enabled.

onAudioInputFormatChanged

fun onAudioInputFormatChanged(
    format: Format!,
    decoderReuseEvaluation: DecoderReuseEvaluation?
): Unit

Called when the format of the media being consumed by the audio renderer changes.

Parameters
format: Format!

The new format.

decoderReuseEvaluation: 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

fun onAudioPositionAdvancing(playoutStartSystemTimeMs: Long): Unit

Called when the audio position has increased for the first time since the last pause or position reset.

Parameters
playoutStartSystemTimeMs: Long

The approximate derived currentTimeMillis at which playout started.

onAudioSessionIdChanged

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.

onAudioSinkError

fun onAudioSinkError(audioSinkError: Exception!): Unit

Called when AudioSink has encountered an error.

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

Parameters
audioSinkError: Exception!

The error that occurred. Typically an , a AudioSink.WriteException, or an .

onAudioTrackInitialized

fun onAudioTrackInitialized(audioTrackConfig: AudioSink.AudioTrackConfig!): Unit

Called when an AudioTrack has been initialized.

Parameters
audioTrackConfig: AudioSink.AudioTrackConfig!

The AudioSink.AudioTrackConfig of the initialized .

onAudioTrackReleased

fun onAudioTrackReleased(audioTrackConfig: AudioSink.AudioTrackConfig!): Unit

Called when an AudioTrack has been released.

Parameters
audioTrackConfig: AudioSink.AudioTrackConfig!

The AudioSink.AudioTrackConfig of the released .

onAudioUnderrun

fun onAudioUnderrun(
    bufferSize: Int,
    bufferSizeMs: Long,
    elapsedSinceLastFeedMs: Long
): Unit

Called when an audio underrun occurs.

Parameters
bufferSize: Int

The size of the audio output buffer, in bytes.

bufferSizeMs: Long

The size of the audio output buffer, in milliseconds, if it contains PCM encoded audio. TIME_UNSET if the output buffer contains non-PCM encoded audio.

elapsedSinceLastFeedMs: Long

The time since audio was last written to the output buffer.

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.

onBandwidthSample

fun onBandwidthSample(
    elapsedMs: Int,
    bytesTransferred: Long,
    bitrateEstimate: Long
): Unit

Called periodically to indicate that bytes have been transferred or the estimated bitrate has changed.

Note: The estimated bitrate is typically derived from more information than just bytesTransferred and elapsedMs.

Parameters
elapsedMs: Int

The time taken to transfer bytesTransferred, in milliseconds. This is at most the elapsed time since the last callback, but may be less if there were periods during which data was not being transferred.

bytesTransferred: Long

The number of bytes transferred since the last callback.

bitrateEstimate: Long

The estimated bitrate in bits/sec.

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

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.

onDownstreamFormatChanged

fun onDownstreamFormatChanged(
    windowIndex: Int,
    mediaPeriodId: MediaSource.MediaPeriodId?,
    mediaLoadData: MediaLoadData!
): Unit

Called when a downstream format change occurs (i.e. when the format of the media being read from one or more SampleStreams provided by the source changes).

Parameters
windowIndex: Int

The window index in the timeline of the media source this load belongs to.

mediaPeriodId: MediaSource.MediaPeriodId?

The MediaPeriodId the media belongs to.

mediaLoadData: MediaLoadData!

The MediaLoadData defining the newly selected downstream data.

onDrmKeysLoaded

fun onDrmKeysLoaded(
    windowIndex: Int,
    mediaPeriodId: MediaSource.MediaPeriodId?
): Unit

Called each time keys are loaded.

Parameters
windowIndex: Int

The window index in the timeline this media period belongs to.

mediaPeriodId: MediaSource.MediaPeriodId?

The MediaPeriodId associated with the drm session.

onDrmKeysRemoved

fun onDrmKeysRemoved(
    windowIndex: Int,
    mediaPeriodId: MediaSource.MediaPeriodId?
): Unit

Called each time offline keys are removed.

Parameters
windowIndex: Int

The window index in the timeline this media period belongs to.

mediaPeriodId: MediaSource.MediaPeriodId?

The MediaPeriodId associated with the drm session.

onDrmKeysRestored

fun onDrmKeysRestored(
    windowIndex: Int,
    mediaPeriodId: MediaSource.MediaPeriodId?
): Unit

Called each time offline keys are restored.

Parameters
windowIndex: Int

The window index in the timeline this media period belongs to.

mediaPeriodId: MediaSource.MediaPeriodId?

The MediaPeriodId associated with the drm session.

onDrmSessionAcquired

fun onDrmSessionAcquired(
    windowIndex: Int,
    mediaPeriodId: MediaSource.MediaPeriodId?,
    @DrmSession.State state: Int
): Unit

Called each time a drm session is acquired.

Parameters
windowIndex: Int

The window index in the timeline this media period belongs to.

mediaPeriodId: MediaSource.MediaPeriodId?

The MediaPeriodId associated with the drm session.

@DrmSession.State state: Int

The DrmSession.State of the session when the acquisition completed.

onDrmSessionManagerError

fun onDrmSessionManagerError(
    windowIndex: Int,
    mediaPeriodId: MediaSource.MediaPeriodId?,
    error: Exception!
): Unit

Called when a drm error occurs.

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 and continue. Hence applications should not implement this method to display a user visible error or initiate an application level retry (onPlayerError 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
windowIndex: Int

The window index in the timeline this media period belongs to.

mediaPeriodId: MediaSource.MediaPeriodId?

The MediaPeriodId associated with the drm session.

error: Exception!

The corresponding exception.

onDrmSessionReleased

fun onDrmSessionReleased(
    windowIndex: Int,
    mediaPeriodId: MediaSource.MediaPeriodId?
): Unit

Called each time a drm session is released.

Parameters
windowIndex: Int

The window index in the timeline this media period belongs to.

mediaPeriodId: MediaSource.MediaPeriodId?

The MediaPeriodId associated with the drm session.

onDroppedFrames

fun onDroppedFrames(count: Int, elapsedMs: Long): Unit

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: Int

The number of dropped frames.

elapsedMs: Long

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.

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.

onLoadCanceled

fun onLoadCanceled(
    windowIndex: Int,
    mediaPeriodId: MediaSource.MediaPeriodId?,
    loadEventInfo: LoadEventInfo!,
    mediaLoadData: MediaLoadData!
): Unit

Called when a load is canceled.

Parameters
windowIndex: Int

The window index in the timeline of the media source this load belongs to.

mediaPeriodId: MediaSource.MediaPeriodId?

The MediaPeriodId this load belongs to. Null if the load does not belong to a specific media period.

loadEventInfo: LoadEventInfo!

The LoadEventInfo corresponding to the event. The values of elapsedRealtimeMs and bytesLoaded are relative to the corresponding onLoadStarted event.

mediaLoadData: MediaLoadData!

The MediaLoadData defining the data being loaded.

onLoadCompleted

fun onLoadCompleted(
    windowIndex: Int,
    mediaPeriodId: MediaSource.MediaPeriodId?,
    loadEventInfo: LoadEventInfo!,
    mediaLoadData: MediaLoadData!
): Unit

Called when a load ends.

Parameters
windowIndex: Int

The window index in the timeline of the media source this load belongs to.

mediaPeriodId: MediaSource.MediaPeriodId?

The MediaPeriodId this load belongs to. Null if the load does not belong to a specific media period.

loadEventInfo: LoadEventInfo!

The LoadEventInfo corresponding to the event. The values of elapsedRealtimeMs and bytesLoaded are relative to the corresponding onLoadStarted event.

mediaLoadData: MediaLoadData!

The MediaLoadData defining the data being loaded.

onLoadError

fun onLoadError(
    windowIndex: Int,
    mediaPeriodId: MediaSource.MediaPeriodId?,
    loadEventInfo: LoadEventInfo!,
    mediaLoadData: MediaLoadData!,
    error: IOException!,
    wasCanceled: Boolean
): Unit

Called when a load error occurs.

The error may or may not have resulted in the load being canceled, as indicated by the wasCanceled parameter. If the load was canceled, onLoadCanceled will not be called in addition to this method.

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. onPlayerError 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
windowIndex: Int

The window index in the timeline of the media source this load belongs to.

mediaPeriodId: MediaSource.MediaPeriodId?

The MediaPeriodId this load belongs to. Null if the load does not belong to a specific media period.

loadEventInfo: LoadEventInfo!

The LoadEventInfo corresponding to the event. The values of elapsedRealtimeMs and bytesLoaded are relative to the corresponding onLoadStarted event.

mediaLoadData: MediaLoadData!

The MediaLoadData defining the data being loaded.

error: IOException!

The load error.

wasCanceled: Boolean

Whether the load was canceled as a result of the error.

onLoadStarted

fun onLoadStarted(
    windowIndex: Int,
    mediaPeriodId: MediaSource.MediaPeriodId?,
    loadEventInfo: LoadEventInfo!,
    mediaLoadData: MediaLoadData!
): Unit

Called when a load begins.

Parameters
windowIndex: Int

The window index in the timeline of the media source this load belongs to.

mediaPeriodId: MediaSource.MediaPeriodId?

The MediaPeriodId this load belongs to. Null if the load does not belong to a specific media period.

loadEventInfo: LoadEventInfo!

The LoadEventInfo corresponding to the event. The value of uri won't reflect potential redirection yet and responseHeaders will be empty.

mediaLoadData: MediaLoadData!

The MediaLoadData defining the data being loaded.

onLoadingChanged

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

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

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

onPlaylistMetadataChanged

fun onPlaylistMetadataChanged(playlistMetadata: 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

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.

onRenderedFirstFrame

fun onRenderedFirstFrame(output: Any!, renderTimeMs: Long): Unit

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: Any!

The output of the video renderer. Normally a Surface, however some video renderers may have other output types (e.g., a VideoDecoderOutputBufferRenderer).

renderTimeMs: Long

The elapsedRealtime when the frame was rendered.

onRendererReadyChanged

fun onRendererReadyChanged(
    rendererIndex: Int,
    @C.TrackType rendererTrackType: Int,
    isRendererReady: Boolean
): Unit

Called each time a renderer starts or stops allowing playback to be ready.

Parameters
rendererIndex: Int

The index of the renderer in the instance.

@C.TrackType rendererTrackType: Int

The C.TrackType of the renderer.

isRendererReady: Boolean

Whether the renderer allows playback to be ready.

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.

onUpstreamDiscarded

fun onUpstreamDiscarded(
    windowIndex: Int,
    mediaPeriodId: MediaSource.MediaPeriodId?,
    mediaLoadData: MediaLoadData!
): Unit

Called when data is removed from the back of a media buffer, typically so that it can be re-buffered in a different format.

Parameters
windowIndex: Int

The window index in the timeline of the media source this load belongs to.

mediaPeriodId: MediaSource.MediaPeriodId?

The MediaPeriodId the media belongs to.

mediaLoadData: MediaLoadData!

The MediaLoadData defining the media being discarded.

onVideoCodecError

fun onVideoCodecError(videoCodecError: Exception!): Unit

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. onPlayerError 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: Exception!

The error. Typically a CodecException if the renderer uses MediaCodec, or a DecoderException if the renderer uses a software decoder.

onVideoDecoderInitialized

fun onVideoDecoderInitialized(
    decoderName: String!,
    initializedTimestampMs: Long,
    initializationDurationMs: Long
): Unit

Called when a video decoder is created.

Parameters
decoderName: String!

The decoder that was created.

initializedTimestampMs: Long

elapsedRealtime when initialization finished.

initializationDurationMs: Long

The time taken to initialize the decoder in milliseconds.

onVideoDecoderReleased

fun onVideoDecoderReleased(decoderName: String!): Unit

Called when a video decoder is released.

Parameters
decoderName: String!

The video decoder that was released.

onVideoDisabled

fun onVideoDisabled(counters: DecoderCounters!): Unit

Called when the video renderer is disabled.

Parameters
counters: DecoderCounters!

DecoderCounters that were updated by the video renderer.

onVideoEnabled

fun onVideoEnabled(counters: DecoderCounters!): Unit

Called when the video renderer is enabled.

Parameters
counters: DecoderCounters!

DecoderCounters that will be updated by the video renderer for as long as it remains enabled.

onVideoFrameProcessingOffset

fun onVideoFrameProcessingOffset(
    totalProcessingOffsetUs: Long,
    frameCount: Int
): Unit

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: Long

The sum of all video frame processing offset samples for the video frames processed by the renderer in microseconds.

frameCount: Int

The number of samples included in the totalProcessingOffsetUs.

onVideoInputFormatChanged

fun onVideoInputFormatChanged(
    format: Format!,
    decoderReuseEvaluation: DecoderReuseEvaluation?
): Unit

Called when the format of the media being consumed by the video renderer changes.

Parameters
format: Format!

The new format.

decoderReuseEvaluation: 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.

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.

release

@CallSuper
fun release(): Unit

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

removeListener

@CallSuper
fun removeListener(listener: AnalyticsListener!): Unit

Removes a previously added analytics event listener.

Parameters
listener: AnalyticsListener!

The listener to remove.

setPlayer

@CallSuper
fun setPlayer(player: Player!, looper: Looper!): Unit

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: Player!

The Player for which data will be collected.

looper: Looper!

The Looper used for listener callbacks.

setThrowsWhenUsingWrongThread

fun setThrowsWhenUsingWrongThread(throwsWhenUsingWrongThread: Boolean): Unit

Sets whether methods throw when using the wrong thread.

Do not use this method unless to support legacy use cases.

Parameters
throwsWhenUsingWrongThread: Boolean

Whether to throw when using the wrong thread.

updateMediaPeriodQueueInfo

fun updateMediaPeriodQueueInfo(
    queue: (Mutable)List<MediaSource.MediaPeriodId!>!,
    readingPeriod: MediaSource.MediaPeriodId?
): Unit

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: (Mutable)List<MediaSource.MediaPeriodId!>!

The playback queue of media periods identified by their MediaPeriodId.

readingPeriod: MediaSource.MediaPeriodId?

The media period in the queue that is currently being read by renderers, or null if the queue is empty.

Protected functions

generateCurrentPlayerMediaPeriodEventTime

protected fun generateCurrentPlayerMediaPeriodEventTime(): AnalyticsListener.EventTime!

Generates an EventTime for the currently playing item in the player.

generateEventTime

@RequiresNonNull(value = "player")
protected fun generateEventTime(
    timeline: Timeline!,
    windowIndex: Int,
    mediaPeriodId: MediaSource.MediaPeriodId?
): AnalyticsListener.EventTime!

Returns a new EventTime for the specified timeline, window and media period id.

sendEvent

protected fun sendEvent(
    eventTime: AnalyticsListener.EventTime!,
    eventFlag: Int,
    eventInvocation: ListenerSet.Event<AnalyticsListener!>!
): Unit

Sends an event to registered listeners.

Parameters
eventTime: AnalyticsListener.EventTime!

The EventTime to report.

eventFlag: Int

An integer flag indicating the type of the event, or INDEX_UNSET to report this event without flag.

eventInvocation: ListenerSet.Event<AnalyticsListener!>!

The event.