PlaybackStatsListener
@UnstableApi
public final class PlaybackStatsListener implements AnalyticsListener, PlaybackSessionManager.Listener
AnalyticsListener to gather PlaybackStats from the player.
For accurate measurements, the listener should be added to the player before loading media, i.e., getPlaybackState should be STATE_IDLE.
Playback stats are gathered separately for each playback session, i.e. each window in the Timeline and each single ad.
Summary
Nested types |
|---|
public interface PlaybackStatsListener.CallbackA listener for |
Public constructors |
|---|
PlaybackStatsListener(Creates listener for playback stats. |
Public methods |
|
|---|---|
PlaybackStats |
Returns the combined |
@Nullable PlaybackStats |
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 |
onDrmSessionManagerError(Called when a drm error occurs. |
void |
onDroppedVideoFrames(Called after video frames have been dropped. |
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 |
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 |
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 constructors
PlaybackStatsListener
public PlaybackStatsListener(
boolean keepHistory,
@Nullable PlaybackStatsListener.Callback callback
)
Creates listener for playback stats.
| Parameters | |
|---|---|
boolean keepHistory |
Whether the reported |
@Nullable PlaybackStatsListener.Callback callback |
An optional callback for finished |
Public methods
getCombinedPlaybackStats
public PlaybackStats getCombinedPlaybackStats()
Returns the combined PlaybackStats for all playback sessions this listener was and is listening to.
Note that these PlaybackStats will not contain the full history of events.
| Returns | |
|---|---|
PlaybackStats |
The combined |
getPlaybackStats
public @Nullable PlaybackStats getPlaybackStats()
Returns the PlaybackStats for the currently playback session, or null if no session is active.
| Returns | |
|---|---|
@Nullable PlaybackStats |
|
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 |
onDrmSessionManagerError
public void onDrmSessionManagerError(
AnalyticsListener.EventTime eventTime,
Exception error
)
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. 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. |
Exception error |
The error. |
onDroppedVideoFrames
public void onDroppedVideoFrames(
AnalyticsListener.EventTime eventTime,
int droppedFrames,
long elapsedMs
)
Called after video frames have been dropped.
| Parameters | |
|---|---|
AnalyticsListener.EventTime eventTime |
The event time. |
int droppedFrames |
The number of dropped frames since the last call to this method. |
long 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. |
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. |
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. |
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. |