Avoid creating empty playback metrics
In some cases we create empty playback metrics with no corresponding events (e.g. when an app seeks to a new media item and immediately releases the player). There is no benefit in having completely empty metrics entries, so it's cleaner to not report them in such cases. #minor-release PiperOrigin-RevId: 425609010
This commit is contained in:
parent
2848240a8c
commit
fc528ebed7
@ -134,6 +134,7 @@ public final class MediaMetricsListener
|
|||||||
private int droppedFrames;
|
private int droppedFrames;
|
||||||
private int playedFrames;
|
private int playedFrames;
|
||||||
private int audioUnderruns;
|
private int audioUnderruns;
|
||||||
|
private boolean reportedEventsForCurrentSession;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the listener.
|
* Creates the listener.
|
||||||
@ -359,6 +360,7 @@ public final class MediaMetricsListener
|
|||||||
.setSubErrorCode(errorInfo.subErrorCode)
|
.setSubErrorCode(errorInfo.subErrorCode)
|
||||||
.setException(error)
|
.setException(error)
|
||||||
.build());
|
.build());
|
||||||
|
reportedEventsForCurrentSession = true;
|
||||||
pendingPlayerError = null;
|
pendingPlayerError = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -429,6 +431,7 @@ public final class MediaMetricsListener
|
|||||||
int newPlaybackState = resolveNewPlaybackState(player);
|
int newPlaybackState = resolveNewPlaybackState(player);
|
||||||
if (currentPlaybackState != newPlaybackState) {
|
if (currentPlaybackState != newPlaybackState) {
|
||||||
currentPlaybackState = newPlaybackState;
|
currentPlaybackState = newPlaybackState;
|
||||||
|
reportedEventsForCurrentSession = true;
|
||||||
playbackSession.reportPlaybackStateEvent(
|
playbackSession.reportPlaybackStateEvent(
|
||||||
new PlaybackStateEvent.Builder()
|
new PlaybackStateEvent.Builder()
|
||||||
.setState(currentPlaybackState)
|
.setState(currentPlaybackState)
|
||||||
@ -561,6 +564,7 @@ public final class MediaMetricsListener
|
|||||||
} else {
|
} else {
|
||||||
builder.setTrackState(TrackChangeEvent.TRACK_STATE_OFF);
|
builder.setTrackState(TrackChangeEvent.TRACK_STATE_OFF);
|
||||||
}
|
}
|
||||||
|
reportedEventsForCurrentSession = true;
|
||||||
playbackSession.reportTrackChangeEvent(builder.build());
|
playbackSession.reportTrackChangeEvent(builder.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -586,12 +590,11 @@ public final class MediaMetricsListener
|
|||||||
}
|
}
|
||||||
metricsBuilder.setPlaybackType(
|
metricsBuilder.setPlaybackType(
|
||||||
window.isLive() ? PlaybackMetrics.PLAYBACK_TYPE_LIVE : PlaybackMetrics.PLAYBACK_TYPE_VOD);
|
window.isLive() ? PlaybackMetrics.PLAYBACK_TYPE_LIVE : PlaybackMetrics.PLAYBACK_TYPE_VOD);
|
||||||
|
reportedEventsForCurrentSession = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void finishCurrentSession() {
|
private void finishCurrentSession() {
|
||||||
if (metricsBuilder == null) {
|
if (metricsBuilder != null && reportedEventsForCurrentSession) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
metricsBuilder.setAudioUnderrunCount(audioUnderruns);
|
metricsBuilder.setAudioUnderrunCount(audioUnderruns);
|
||||||
metricsBuilder.setVideoFramesDropped(droppedFrames);
|
metricsBuilder.setVideoFramesDropped(droppedFrames);
|
||||||
metricsBuilder.setVideoFramesPlayed(playedFrames);
|
metricsBuilder.setVideoFramesPlayed(playedFrames);
|
||||||
@ -606,6 +609,7 @@ public final class MediaMetricsListener
|
|||||||
? PlaybackMetrics.STREAM_SOURCE_NETWORK
|
? PlaybackMetrics.STREAM_SOURCE_NETWORK
|
||||||
: PlaybackMetrics.STREAM_SOURCE_UNKNOWN);
|
: PlaybackMetrics.STREAM_SOURCE_UNKNOWN);
|
||||||
playbackSession.reportPlaybackMetrics(metricsBuilder.build());
|
playbackSession.reportPlaybackMetrics(metricsBuilder.build());
|
||||||
|
}
|
||||||
metricsBuilder = null;
|
metricsBuilder = null;
|
||||||
activeSessionId = null;
|
activeSessionId = null;
|
||||||
audioUnderruns = 0;
|
audioUnderruns = 0;
|
||||||
@ -614,6 +618,7 @@ public final class MediaMetricsListener
|
|||||||
currentVideoFormat = null;
|
currentVideoFormat = null;
|
||||||
currentAudioFormat = null;
|
currentAudioFormat = null;
|
||||||
currentTextFormat = null;
|
currentTextFormat = null;
|
||||||
|
reportedEventsForCurrentSession = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getTrackChangeReason(@C.SelectionReason int trackSelectionReason) {
|
private static int getTrackChangeReason(@C.SelectionReason int trackSelectionReason) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user