MediaMetricsListener
@UnstableApi
@RequiresApi(value = 31)
public final class MediaMetricsListener implements AnalyticsListener, PlaybackSessionManager.Listener
An AnalyticsListener that interacts with the Android MediaMetricsManager.
It listens to playback events and forwards them to a PlaybackSession. The LogSessionId of the playback session can be obtained with getLogSessionId.
Summary
Public methods |
|
|---|---|
static @Nullable MediaMetricsListener |
Creates a media metrics listener. |
LogSessionId |
Returns the |
void |
onAdPlaybackStarted(Called when a session is interrupted by ad playback. |
void |
onBandwidthEstimate(Called when the bandwidth estimate for the current data source has been updated. |
void |
onDownstreamFormatChanged(Called when the downstream format sent to the renderers changed. |
void |
onEvents(Player player, AnalyticsListener.Events events)Called after one or more events occurred. |
void |
onLoadError(Called when a media source loading error occurred. |
void |
onPlayerError(Called when a fatal player error occurred. |
void |
onPositionDiscontinuity(Called when a position discontinuity occurred. |
void |
onSessionActive(Called when a session becomes active, i.e. playing in the foreground. |
void |
onSessionCreated(Called when a new session is created as a result of |
void |
onSessionFinished(Called when a session is permanently finished. |
void |
onVideoDisabled(Called when a video renderer is disabled. |
void |
onVideoSizeChanged(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 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Inherited methods |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Public methods
create
public static @Nullable MediaMetricsListener create(Context context)
Creates a media metrics listener.
| Parameters | |
|---|---|
Context context |
A context. |
| Returns | |
|---|---|
@Nullable MediaMetricsListener |
The |
getLogSessionId
public LogSessionId getLogSessionId()
Returns the LogSessionId used by this listener.
onAdPlaybackStarted
public void onAdPlaybackStarted(
AnalyticsListener.EventTime eventTime,
String contentSessionId,
String adSessionId
)
Called when a session is interrupted by ad playback.
| Parameters | |
|---|---|
AnalyticsListener.EventTime eventTime |
The |
String contentSessionId |
The session identifier of the content session. |
String adSessionId |
The identifier of the ad session. |
onBandwidthEstimate
public void onBandwidthEstimate(
AnalyticsListener.EventTime eventTime,
int totalLoadTimeMs,
long totalBytesLoaded,
long bitrateEstimate
)
Called when the bandwidth estimate for the current data source has been updated.
| Parameters | |
|---|---|
AnalyticsListener.EventTime eventTime |
The event time. |
int totalLoadTimeMs |
The total time spend loading this update is based on, in milliseconds. |
long totalBytesLoaded |
The total bytes loaded this update is based on. |
long bitrateEstimate |
The bandwidth estimate, in bits per second. |
onDownstreamFormatChanged
public void onDownstreamFormatChanged(
AnalyticsListener.EventTime eventTime,
MediaLoadData mediaLoadData
)
Called when the downstream format sent to the renderers changed.
| Parameters | |
|---|---|
AnalyticsListener.EventTime eventTime |
The event time. |
MediaLoadData mediaLoadData |
The |
onEvents
public void onEvents(Player player, AnalyticsListener.Events events)
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:
- They intend to trigger the same logic for multiple events (e.g. when updating a UI for both
onPlaybackStateChangedandonPlayWhenReadyChanged). - They need access to the
Playerobject to trigger further events (e.g. to callseekToafter aonMediaItemTransition). - They intend to use multiple state values together or in combination with
Playergetter methods. For example usinggetCurrentMediaItemIndexwith thetimelineprovided inonTimelineChangedis only safe from within this method. - They are interested in events that logically happened together (e.g
onPlaybackStateChangedtoSTATE_BUFFERINGbecause ofonMediaItemTransition).
| Parameters | |
|---|---|
Player player |
The |
AnalyticsListener.Events events |
The |
onLoadError
public void onLoadError(
AnalyticsListener.EventTime eventTime,
LoadEventInfo loadEventInfo,
MediaLoadData mediaLoadData,
IOException error,
boolean wasCanceled
)
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 | |
|---|---|
AnalyticsListener.EventTime eventTime |
The event time. |
LoadEventInfo loadEventInfo |
The |
MediaLoadData mediaLoadData |
The |
IOException error |
The load error. |
boolean wasCanceled |
Whether the load was canceled as a result of the error. |
onPlayerError
public void onPlayerError(
AnalyticsListener.EventTime eventTime,
PlaybackException error
)
Called when a fatal player error occurred.
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 | |
|---|---|
AnalyticsListener.EventTime eventTime |
The event time. |
PlaybackException error |
The error. |
onPositionDiscontinuity
public void onPositionDiscontinuity(
AnalyticsListener.EventTime eventTime,
Player.PositionInfo oldPosition,
Player.PositionInfo newPosition,
@Player.DiscontinuityReason int reason
)
Called when a position discontinuity occurred.
| Parameters | |
|---|---|
AnalyticsListener.EventTime eventTime |
The event time. |
Player.PositionInfo oldPosition |
The position before the discontinuity. |
Player.PositionInfo newPosition |
The position after the discontinuity. |
@Player.DiscontinuityReason int reason |
The reason for the position discontinuity. |
onSessionActive
public void onSessionActive(
AnalyticsListener.EventTime eventTime,
String sessionId
)
Called when a session becomes active, i.e. playing in the foreground.
| Parameters | |
|---|---|
AnalyticsListener.EventTime eventTime |
The |
String sessionId |
The identifier of the session. |
onSessionCreated
public void onSessionCreated(
AnalyticsListener.EventTime eventTime,
String sessionId
)
Called when a new session is created as a result of updateSessions.
| Parameters | |
|---|---|
AnalyticsListener.EventTime eventTime |
The |
String sessionId |
The identifier of the new session. |
onSessionFinished
public void onSessionFinished(
AnalyticsListener.EventTime eventTime,
String sessionId,
boolean automaticTransitionToNextPlayback
)
Called when a session is permanently finished.
| Parameters | |
|---|---|
AnalyticsListener.EventTime eventTime |
The |
String sessionId |
The identifier of the finished session. |
boolean automaticTransitionToNextPlayback |
Whether the session finished because of an automatic transition to the next playback item. |
onVideoDisabled
public void onVideoDisabled(
AnalyticsListener.EventTime eventTime,
DecoderCounters decoderCounters
)
Called when a video renderer is disabled.
| Parameters | |
|---|---|
AnalyticsListener.EventTime eventTime |
The event time. |
DecoderCounters decoderCounters |
|
onVideoSizeChanged
public void onVideoSizeChanged(
AnalyticsListener.EventTime 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.
| Parameters | |
|---|---|
AnalyticsListener.EventTime eventTime |
The event time. |
VideoSize videoSize |
The new size of the video. |