MediaMetricsListener


@UnstableApi
@RequiresApi(value = 31)
class MediaMetricsListener : AnalyticsListener, PlaybackSessionManager.Listener


An AnalyticsListener that interacts with the Android MediaMetricsManager.

It listens to playback events and forwards them to a PlaybackSession. The of the playback session can be obtained with getLogSessionId.

Summary

Public functions

java-static MediaMetricsListener?
create(context: Context!)

Creates a media metrics listener.

LogSessionId!

Returns the LogSessionId used by this listener.

Unit
onAdPlaybackStarted(
    eventTime: AnalyticsListener.EventTime!,
    contentSessionId: String!,
    adSessionId: String!
)

Called when a session is interrupted by ad playback.

Unit
onBandwidthEstimate(
    eventTime: AnalyticsListener.EventTime!,
    totalLoadTimeMs: Int,
    totalBytesLoaded: Long,
    bitrateEstimate: Long
)

Called when the bandwidth estimate for the current data source has been updated.

Unit
onDownstreamFormatChanged(
    eventTime: AnalyticsListener.EventTime!,
    mediaLoadData: MediaLoadData!
)

Called when the downstream format sent to the renderers changed.

Unit

Called after one or more events occurred.

Unit
onLoadError(
    eventTime: AnalyticsListener.EventTime!,
    loadEventInfo: LoadEventInfo!,
    mediaLoadData: MediaLoadData!,
    error: IOException!,
    wasCanceled: Boolean
)

Called when a media source loading error occurred.

Unit
onPlayerError(
    eventTime: AnalyticsListener.EventTime!,
    error: PlaybackException!
)

Called when a fatal player error occurred.

Unit
onPositionDiscontinuity(
    eventTime: AnalyticsListener.EventTime!,
    oldPosition: Player.PositionInfo!,
    newPosition: Player.PositionInfo!,
    @Player.DiscontinuityReason reason: Int
)

Called when a position discontinuity occurred.

Unit
onSessionActive(
    eventTime: AnalyticsListener.EventTime!,
    sessionId: String!
)

Called when a session becomes active, i.e. playing in the foreground.

Unit
onSessionCreated(
    eventTime: AnalyticsListener.EventTime!,
    sessionId: String!
)

Called when a new session is created as a result of updateSessions.

Unit
onSessionFinished(
    eventTime: AnalyticsListener.EventTime!,
    sessionId: String!,
    automaticTransitionToNextPlayback: Boolean
)

Called when a session is permanently finished.

Unit
onVideoDisabled(
    eventTime: AnalyticsListener.EventTime!,
    decoderCounters: DecoderCounters!
)

Called when a video renderer is disabled.

Unit
onVideoSizeChanged(
    eventTime: AnalyticsListener.EventTime!,
    videoSize: VideoSize!
)

Called before a frame is rendered for the first time since setting the surface, and each time there's a change in the size or pixel aspect ratio of the video being rendered.

Inherited Constants

From androidx.media3.exoplayer.analytics.AnalyticsListener
const Int

Audio attributes changed.

const Int

The audio codec encountered an error.

const Int

An audio renderer created a decoder.

const Int

An audio renderer released a decoder.

const Int

An audio renderer was disabled.

const Int

An audio renderer was enabled.

const Int

The format consumed by an audio renderer changed.

const Int

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

const Int

An audio session id was set.

const Int

The audio sink encountered a non-fatal error.

const Int

An audio track has been initialized.

const Int

An audio track has been released.

const Int

An audio underrun occurred.

const Int

getAvailableCommands changed.

const Int

The bandwidth estimate has been updated.

const Int

getCurrentCues changed.

const Int

getDeviceInfo changed.

const Int

getDeviceVolume changed.

const Int

The downstream format sent to renderers changed.

const Int

DRM keys were loaded.

const Int

DRM keys were removed.

const Int

DRM keys were restored.

const Int

A DRM session has been acquired.

const Int

A non-fatal DRM session manager error occurred.

const Int

A DRM session has been released.

const Int

Video frames have been dropped.

const Int

isLoading ()} changed.

const Int

isPlaying changed.

const Int

A source canceled loading data.

const Int

A source started completed loading data.

const Int

A source had a non-fatal error loading data.

const Int

A source started loading data.

const Int

getMaxSeekToPreviousPosition changed.

const Int

getCurrentMediaItem changed or the player started repeating the current item.

const Int

getMediaMetadata changed.

const Int

Metadata associated with the current playback time was reported.

const Int

getPlaybackParameters changed.

const Int

getPlaybackState changed.

const Int

getPlaybackSuppressionReason changed.

const Int

getPlayerError changed.

const Int

The player was released.

const Int

getPlaylistMetadata changed.

const Int

getPlayWhenReady changed.

const Int

A position discontinuity occurred.

const Int

The first frame has been rendered since setting the surface, since the renderer was reset or since the stream changed.

const Int

A renderer changed its readiness for playback.

const Int

getRepeatMode changed.

const Int

getSeekBackIncrement changed.

const Int

getSeekForwardIncrement changed.

const Int

getShuffleModeEnabled changed.

const Int

Skipping silences was enabled or disabled in the audio stream.

const Int

The surface size changed.

const Int

getCurrentTimeline changed.

const Int

getCurrentTracks changed.

const Int

getTrackSelectionParameters changed.

const Int

Data was removed from the end of the media buffer.

const Int

The video codec encountered an error.

const Int

A video renderer created a decoder.

const Int

A video renderer released a decoder.

const Int

A video renderer was disabled.

const Int

A video renderer was enabled.

const Int

Video frame processing offset data has been reported.

const Int

The format consumed by a video renderer changed.

const Int

The video size changed.

const Int

The volume changed.

Inherited functions

From androidx.media3.exoplayer.analytics.AnalyticsListener
Unit
@UnstableApi
onAudioAttributesChanged(
    eventTime: AnalyticsListener.EventTime!,
    audioAttributes: AudioAttributes!
)

Called when the audio attributes change.

Unit
@UnstableApi
onAudioCodecError(
    eventTime: AnalyticsListener.EventTime!,
    audioCodecError: Exception!
)

Called when an audio decoder encounters an error.

Unit
@UnstableApi
onAudioDecoderInitialized(
    eventTime: AnalyticsListener.EventTime!,
    decoderName: String!,
    initializationDurationMs: Long
)

This function is deprecated.

Use onAudioDecoderInitialized.

Unit
@UnstableApi
onAudioDecoderInitialized(
    eventTime: AnalyticsListener.EventTime!,
    decoderName: String!,
    initializedTimestampMs: Long,
    initializationDurationMs: Long
)

Called when an audio renderer creates a decoder.

Unit
@UnstableApi
onAudioDecoderReleased(
    eventTime: AnalyticsListener.EventTime!,
    decoderName: String!
)

Called when an audio renderer releases a decoder.

Unit
@UnstableApi
onAudioDisabled(
    eventTime: AnalyticsListener.EventTime!,
    decoderCounters: DecoderCounters!
)

Called when an audio renderer is disabled.

Unit
@UnstableApi
onAudioEnabled(
    eventTime: AnalyticsListener.EventTime!,
    decoderCounters: DecoderCounters!
)

Called when an audio renderer is enabled.

Unit
@UnstableApi
onAudioInputFormatChanged(
    eventTime: AnalyticsListener.EventTime!,
    format: Format!,
    decoderReuseEvaluation: DecoderReuseEvaluation?
)

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

Unit
@UnstableApi
onAudioPositionAdvancing(
    eventTime: AnalyticsListener.EventTime!,
    playoutStartSystemTimeMs: Long
)

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

Unit
@UnstableApi
onAudioSessionIdChanged(
    eventTime: AnalyticsListener.EventTime!,
    audioSessionId: Int
)

Called when the audio session ID changes.

Unit
@UnstableApi
onAudioSinkError(
    eventTime: AnalyticsListener.EventTime!,
    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
@UnstableApi
onAudioUnderrun(
    eventTime: AnalyticsListener.EventTime!,
    bufferSize: Int,
    bufferSizeMs: Long,
    elapsedSinceLastFeedMs: Long
)

Called when an audio underrun occurs.

Unit
@UnstableApi
onAvailableCommandsChanged(
    eventTime: AnalyticsListener.EventTime!,
    availableCommands: Player.Commands!
)

Called when the player's available commands changed.

Unit

Called when there is a change in the CueGroup.

Unit

This function is deprecated.

Use onCues instead.

Unit
@UnstableApi
onDeviceInfoChanged(
    eventTime: AnalyticsListener.EventTime!,
    deviceInfo: DeviceInfo!
)

Called when the device information changes

Unit
@UnstableApi
onDeviceVolumeChanged(
    eventTime: AnalyticsListener.EventTime!,
    volume: Int,
    muted: Boolean
)

Called when the device volume or mute state changes.

Unit

Called each time drm keys are loaded.

Unit

Called each time offline drm keys are removed.

Unit

Called each time offline drm keys are restored.

Unit

This function is deprecated.

Implement onDrmSessionAcquired instead.

Unit

Called each time a drm session is acquired.

Unit

Called when a drm error occurs.

Unit

Called each time a drm session is released.

Unit
@UnstableApi
onDroppedVideoFrames(
    eventTime: AnalyticsListener.EventTime!,
    droppedFrames: Int,
    elapsedMs: Long
)

Called after video frames have been dropped.

Unit
@UnstableApi
onIsLoadingChanged(
    eventTime: AnalyticsListener.EventTime!,
    isLoading: Boolean
)

Called when the player starts or stops loading data from a source.

Unit
@UnstableApi
onIsPlayingChanged(
    eventTime: AnalyticsListener.EventTime!,
    isPlaying: Boolean
)

Called when the player starts or stops playing.

Unit
@UnstableApi
onLoadCanceled(
    eventTime: AnalyticsListener.EventTime!,
    loadEventInfo: LoadEventInfo!,
    mediaLoadData: MediaLoadData!
)

Called when a media source canceled loading data.

Unit
@UnstableApi
onLoadCompleted(
    eventTime: AnalyticsListener.EventTime!,
    loadEventInfo: LoadEventInfo!,
    mediaLoadData: MediaLoadData!
)

Called when a media source completed loading data.

Unit
@UnstableApi
onLoadStarted(
    eventTime: AnalyticsListener.EventTime!,
    loadEventInfo: LoadEventInfo!,
    mediaLoadData: MediaLoadData!
)

Called when a media source started loading data.

Unit
@UnstableApi
onLoadingChanged(
    eventTime: AnalyticsListener.EventTime!,
    isLoading: Boolean
)

This function is deprecated.

Use onIsLoadingChanged instead.

Unit
@UnstableApi
onMaxSeekToPreviousPositionChanged(
    eventTime: AnalyticsListener.EventTime!,
    maxSeekToPreviousPositionMs: Long
)

Called when the maximum position for which seekToPrevious seeks to the previous window changes.

Unit

Called when playback transitions to a different media item.

Unit
@UnstableApi
onMediaMetadataChanged(
    eventTime: AnalyticsListener.EventTime!,
    mediaMetadata: MediaMetadata!
)

Called when the combined MediaMetadata changes.

Unit

Called when there is Metadata associated with the current playback time.

Unit
@UnstableApi
onPlayWhenReadyChanged(
    eventTime: AnalyticsListener.EventTime!,
    playWhenReady: Boolean,
    @Player.PlayWhenReadyChangeReason reason: Int
)

Called when the value changed that indicates whether playback will proceed when ready.

Unit

Called when the playback parameters changed.

Unit

Called when the playback state changed.

Unit

Called when playback suppression reason changed.

Unit

Called when the PlaybackException returned by getPlayerError changes.

Unit

Called when the Player is released.

Unit
@UnstableApi
onPlayerStateChanged(
    eventTime: AnalyticsListener.EventTime!,
    playWhenReady: Boolean,
    @Player.State playbackState: Int
)

This function is deprecated.

Use onPlaybackStateChanged and onPlayWhenReadyChanged instead.

Unit
@UnstableApi
onPlaylistMetadataChanged(
    eventTime: AnalyticsListener.EventTime!,
    playlistMetadata: MediaMetadata!
)

Called when the playlist MediaMetadata changes.

Unit

This function is deprecated.

Use onPositionDiscontinuity instead.

Unit
@UnstableApi
onRenderedFirstFrame(
    eventTime: AnalyticsListener.EventTime!,
    output: Any!,
    renderTimeMs: Long
)

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
@UnstableApi
onRendererReadyChanged(
    eventTime: AnalyticsListener.EventTime!,
    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 repeat mode changed.

Unit
@UnstableApi
onSeekBackIncrementChanged(
    eventTime: AnalyticsListener.EventTime!,
    seekBackIncrementMs: Long
)

Called when the seek back increment changed.

Unit
@UnstableApi
onSeekForwardIncrementChanged(
    eventTime: AnalyticsListener.EventTime!,
    seekForwardIncrementMs: Long
)

Called when the seek forward increment changed.

Unit

This function is deprecated.

Use onPositionDiscontinuity instead, listening to changes with DISCONTINUITY_REASON_SEEK.

Unit
@UnstableApi
onShuffleModeChanged(
    eventTime: AnalyticsListener.EventTime!,
    shuffleModeEnabled: Boolean
)

Called when the shuffle mode changed.

Unit
@UnstableApi
onSkipSilenceEnabledChanged(
    eventTime: AnalyticsListener.EventTime!,
    skipSilenceEnabled: Boolean
)

Called when skipping silences is enabled or disabled in the audio stream.

Unit
@UnstableApi
onSurfaceSizeChanged(
    eventTime: AnalyticsListener.EventTime!,
    width: Int,
    height: Int
)

Called when the output surface size changed.

Unit

Called when the timeline changed.

Unit

Called when track selection parameters change.

Unit

Called when the tracks change.

Unit
@UnstableApi
onUpstreamDiscarded(
    eventTime: AnalyticsListener.EventTime!,
    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
@UnstableApi
onVideoCodecError(
    eventTime: AnalyticsListener.EventTime!,
    videoCodecError: Exception!
)

Called when a video decoder encounters an error.

Unit
@UnstableApi
onVideoDecoderInitialized(
    eventTime: AnalyticsListener.EventTime!,
    decoderName: String!,
    initializationDurationMs: Long
)

This function is deprecated.

Use onVideoDecoderInitialized.

Unit
@UnstableApi
onVideoDecoderInitialized(
    eventTime: AnalyticsListener.EventTime!,
    decoderName: String!,
    initializedTimestampMs: Long,
    initializationDurationMs: Long
)

Called when a video renderer creates a decoder.

Unit
@UnstableApi
onVideoDecoderReleased(
    eventTime: AnalyticsListener.EventTime!,
    decoderName: String!
)

Called when a video renderer releases a decoder.

Unit
@UnstableApi
onVideoEnabled(
    eventTime: AnalyticsListener.EventTime!,
    decoderCounters: DecoderCounters!
)

Called when a video renderer is enabled.

Unit
@UnstableApi
onVideoFrameProcessingOffset(
    eventTime: AnalyticsListener.EventTime!,
    totalProcessingOffsetUs: Long,
    frameCount: Int
)

Called when there is an update to the video frame processing offset reported by a video renderer.

Unit
@UnstableApi
onVideoInputFormatChanged(
    eventTime: AnalyticsListener.EventTime!,
    format: Format!,
    decoderReuseEvaluation: DecoderReuseEvaluation?
)

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

Unit
@UnstableApi
onVideoSizeChanged(
    eventTime: AnalyticsListener.EventTime!,
    width: Int,
    height: Int,
    unappliedRotationDegrees: Int,
    pixelWidthHeightRatio: Float
)

This function is deprecated.

Implement onVideoSizeChanged instead.

Unit

Called when the volume changes.

Public functions

create

java-static fun create(context: Context!): MediaMetricsListener?

Creates a media metrics listener.

Parameters
context: Context!

A context.

Returns
MediaMetricsListener?

The MediaMetricsListener, or null if the media metrics service isn't available.

getLogSessionId

fun getLogSessionId(): LogSessionId!

Returns the LogSessionId used by this listener.

onAdPlaybackStarted

fun onAdPlaybackStarted(
    eventTime: AnalyticsListener.EventTime!,
    contentSessionId: String!,
    adSessionId: String!
): Unit

Called when a session is interrupted by ad playback.

Parameters
eventTime: AnalyticsListener.EventTime!

The EventTime at which the ad playback starts.

contentSessionId: String!

The session identifier of the content session.

adSessionId: String!

The identifier of the ad session.

onBandwidthEstimate

fun onBandwidthEstimate(
    eventTime: AnalyticsListener.EventTime!,
    totalLoadTimeMs: Int,
    totalBytesLoaded: Long,
    bitrateEstimate: Long
): Unit

Called when the bandwidth estimate for the current data source has been updated.

Parameters
eventTime: AnalyticsListener.EventTime!

The event time.

totalLoadTimeMs: Int

The total time spend loading this update is based on, in milliseconds.

totalBytesLoaded: Long

The total bytes loaded this update is based on.

bitrateEstimate: Long

The bandwidth estimate, in bits per second.

onDownstreamFormatChanged

fun onDownstreamFormatChanged(
    eventTime: AnalyticsListener.EventTime!,
    mediaLoadData: MediaLoadData!
): Unit

Called when the downstream format sent to the renderers changed.

Parameters
eventTime: AnalyticsListener.EventTime!

The event time.

mediaLoadData: MediaLoadData!

The MediaLoadData defining the newly selected media data.

onEvents

fun onEvents(player: Player!, events: AnalyticsListener.Events!): Unit

Called after one or more events occurred.

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.

events: AnalyticsListener.Events!

The Events that occurred in this iteration.

onLoadError

fun onLoadError(
    eventTime: AnalyticsListener.EventTime!,
    loadEventInfo: LoadEventInfo!,
    mediaLoadData: MediaLoadData!,
    error: IOException!,
    wasCanceled: Boolean
): Unit

Called when a media source loading error occurred.

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
eventTime: AnalyticsListener.EventTime!

The event time.

loadEventInfo: LoadEventInfo!

The LoadEventInfo defining the load 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.

onPlayerError

fun onPlayerError(
    eventTime: AnalyticsListener.EventTime!,
    error: PlaybackException!
): Unit

Called when a fatal player error occurred.

Implementations of Player may pass an instance of a subclass of to this method in order to include more information about the error.

Parameters
eventTime: AnalyticsListener.EventTime!

The event time.

error: PlaybackException!

The error.

onPositionDiscontinuity

fun onPositionDiscontinuity(
    eventTime: AnalyticsListener.EventTime!,
    oldPosition: Player.PositionInfo!,
    newPosition: Player.PositionInfo!,
    @Player.DiscontinuityReason reason: Int
): Unit

Called when a position discontinuity occurred.

Parameters
eventTime: AnalyticsListener.EventTime!

The event time.

oldPosition: Player.PositionInfo!

The position before the discontinuity.

newPosition: Player.PositionInfo!

The position after the discontinuity.

@Player.DiscontinuityReason reason: Int

The reason for the position discontinuity.

onSessionActive

fun onSessionActive(
    eventTime: AnalyticsListener.EventTime!,
    sessionId: String!
): Unit

Called when a session becomes active, i.e. playing in the foreground.

Parameters
eventTime: AnalyticsListener.EventTime!

The EventTime at which the session becomes active.

sessionId: String!

The identifier of the session.

onSessionCreated

fun onSessionCreated(
    eventTime: AnalyticsListener.EventTime!,
    sessionId: String!
): Unit

Called when a new session is created as a result of updateSessions.

Parameters
eventTime: AnalyticsListener.EventTime!

The EventTime at which the session is created.

sessionId: String!

The identifier of the new session.

onSessionFinished

fun onSessionFinished(
    eventTime: AnalyticsListener.EventTime!,
    sessionId: String!,
    automaticTransitionToNextPlayback: Boolean
): Unit

Called when a session is permanently finished.

Parameters
eventTime: AnalyticsListener.EventTime!

The EventTime at which the session finished.

sessionId: String!

The identifier of the finished session.

automaticTransitionToNextPlayback: Boolean

Whether the session finished because of an automatic transition to the next playback item.

onVideoDisabled

fun onVideoDisabled(
    eventTime: AnalyticsListener.EventTime!,
    decoderCounters: DecoderCounters!
): Unit

Called when a video renderer is disabled.

Parameters
eventTime: AnalyticsListener.EventTime!

The event time.

decoderCounters: DecoderCounters!

DecoderCounters that were updated by the renderer.

onVideoSizeChanged

fun onVideoSizeChanged(
    eventTime: AnalyticsListener.EventTime!,
    videoSize: VideoSize!
): Unit

Called before a frame is rendered for the first time since setting the surface, and each time there's a change in the size or pixel aspect ratio of the video being rendered.

Parameters
eventTime: AnalyticsListener.EventTime!

The event time.

videoSize: VideoSize!

The new size of the video.