mirror of
https://github.com/samsonjs/media.git
synced 2026-04-05 11:15:46 +00:00
Avoid ending session early if an unrelated other session is finished
Currently, we always end the current session if onSessionFinished is called. However, the finished session may not be the active one (for example when discarding prebuffered items in a playlist). To make this code more robust, we can save the active session id explicitly and only end this session. PiperOrigin-RevId: 422788542
This commit is contained in:
parent
dbc4dcf0f2
commit
d15350ab01
1 changed files with 8 additions and 4 deletions
|
|
@ -16,6 +16,7 @@
|
|||
package com.google.android.exoplayer2.analytics;
|
||||
|
||||
import static com.google.android.exoplayer2.util.Assertions.checkNotNull;
|
||||
import static com.google.android.exoplayer2.util.Assertions.checkState;
|
||||
import static com.google.android.exoplayer2.util.Util.castNonNull;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
|
|
@ -113,6 +114,7 @@ public final class MediaMetricsListener
|
|||
private final Timeline.Window window;
|
||||
private final Timeline.Period period;
|
||||
|
||||
@Nullable private String activeSessionId;
|
||||
@Nullable private PlaybackMetrics.Builder metricsBuilder;
|
||||
@Player.DiscontinuityReason private int discontinuityReason;
|
||||
private int currentPlaybackState;
|
||||
|
|
@ -167,7 +169,8 @@ public final class MediaMetricsListener
|
|||
// Ignore ad sessions.
|
||||
return;
|
||||
}
|
||||
finishCurrentSession();
|
||||
checkState(activeSessionId == null);
|
||||
activeSessionId = sessionId;
|
||||
metricsBuilder =
|
||||
new PlaybackMetrics.Builder()
|
||||
.setPlayerName(ExoPlayerLibraryInfo.TAG)
|
||||
|
|
@ -182,9 +185,9 @@ public final class MediaMetricsListener
|
|||
@Override
|
||||
public void onSessionFinished(
|
||||
EventTime eventTime, String sessionId, boolean automaticTransitionToNextPlayback) {
|
||||
if (eventTime.mediaPeriodId != null && eventTime.mediaPeriodId.isAd()) {
|
||||
// Ignore ad sessions.
|
||||
return;
|
||||
if ((eventTime.mediaPeriodId != null && eventTime.mediaPeriodId.isAd())
|
||||
|| !sessionId.equals(activeSessionId)) {
|
||||
// Ignore ad sessions and other sessions that are finished before becoming active.
|
||||
}
|
||||
finishCurrentSession();
|
||||
}
|
||||
|
|
@ -588,6 +591,7 @@ public final class MediaMetricsListener
|
|||
: PlaybackMetrics.STREAM_SOURCE_UNKNOWN);
|
||||
playbackSession.reportPlaybackMetrics(metricsBuilder.build());
|
||||
metricsBuilder = null;
|
||||
activeSessionId = null;
|
||||
}
|
||||
|
||||
private static int getTrackChangeReason(@C.SelectionReason int trackSelectionReason) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue