mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Improve knowledge of last playing period in AnalyticsCollector.
We keep track of the last publicly known playing period to report it as part of events happening after the period has been released. In cases where a period briefly becomes the playing one and is released immediately afterwards, we currently don't save it as the "last known playing one". Improve that by saving an explicit reference. Issue:#5407 PiperOrigin-RevId: 259737218
This commit is contained in:
parent
59331c3c88
commit
074307dd4c
2 changed files with 10 additions and 11 deletions
|
|
@ -277,8 +277,8 @@ import com.google.android.exoplayer2.util.Assertions;
|
||||||
if (front != null) {
|
if (front != null) {
|
||||||
oldFrontPeriodUid = keepFrontPeriodUid ? front.uid : null;
|
oldFrontPeriodUid = keepFrontPeriodUid ? front.uid : null;
|
||||||
oldFrontPeriodWindowSequenceNumber = front.info.id.windowSequenceNumber;
|
oldFrontPeriodWindowSequenceNumber = front.info.id.windowSequenceNumber;
|
||||||
front.release();
|
|
||||||
removeAfter(front);
|
removeAfter(front);
|
||||||
|
front.release();
|
||||||
} else if (!keepFrontPeriodUid) {
|
} else if (!keepFrontPeriodUid) {
|
||||||
oldFrontPeriodUid = null;
|
oldFrontPeriodUid = null;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -686,6 +686,7 @@ public class AnalyticsCollector
|
||||||
private final HashMap<MediaPeriodId, MediaPeriodInfo> mediaPeriodIdToInfo;
|
private final HashMap<MediaPeriodId, MediaPeriodInfo> mediaPeriodIdToInfo;
|
||||||
private final Period period;
|
private final Period period;
|
||||||
|
|
||||||
|
@Nullable private MediaPeriodInfo lastPlayingMediaPeriod;
|
||||||
@Nullable private MediaPeriodInfo lastReportedPlayingMediaPeriod;
|
@Nullable private MediaPeriodInfo lastReportedPlayingMediaPeriod;
|
||||||
@Nullable private MediaPeriodInfo readingMediaPeriod;
|
@Nullable private MediaPeriodInfo readingMediaPeriod;
|
||||||
private Timeline timeline;
|
private Timeline timeline;
|
||||||
|
|
@ -780,7 +781,7 @@ public class AnalyticsCollector
|
||||||
|
|
||||||
/** Updates the queue with a reported position discontinuity . */
|
/** Updates the queue with a reported position discontinuity . */
|
||||||
public void onPositionDiscontinuity(@Player.DiscontinuityReason int reason) {
|
public void onPositionDiscontinuity(@Player.DiscontinuityReason int reason) {
|
||||||
updateLastReportedPlayingMediaPeriod();
|
lastReportedPlayingMediaPeriod = lastPlayingMediaPeriod;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Updates the queue with a reported timeline change. */
|
/** Updates the queue with a reported timeline change. */
|
||||||
|
|
@ -795,7 +796,7 @@ public class AnalyticsCollector
|
||||||
readingMediaPeriod = updateMediaPeriodInfoToNewTimeline(readingMediaPeriod, timeline);
|
readingMediaPeriod = updateMediaPeriodInfoToNewTimeline(readingMediaPeriod, timeline);
|
||||||
}
|
}
|
||||||
this.timeline = timeline;
|
this.timeline = timeline;
|
||||||
updateLastReportedPlayingMediaPeriod();
|
lastReportedPlayingMediaPeriod = lastPlayingMediaPeriod;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Updates the queue with a reported start of seek. */
|
/** Updates the queue with a reported start of seek. */
|
||||||
|
|
@ -806,7 +807,7 @@ public class AnalyticsCollector
|
||||||
/** Updates the queue with a reported processed seek. */
|
/** Updates the queue with a reported processed seek. */
|
||||||
public void onSeekProcessed() {
|
public void onSeekProcessed() {
|
||||||
isSeeking = false;
|
isSeeking = false;
|
||||||
updateLastReportedPlayingMediaPeriod();
|
lastReportedPlayingMediaPeriod = lastPlayingMediaPeriod;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Updates the queue with a newly created media period. */
|
/** Updates the queue with a newly created media period. */
|
||||||
|
|
@ -816,8 +817,9 @@ public class AnalyticsCollector
|
||||||
new MediaPeriodInfo(mediaPeriodId, isInTimeline ? timeline : Timeline.EMPTY, windowIndex);
|
new MediaPeriodInfo(mediaPeriodId, isInTimeline ? timeline : Timeline.EMPTY, windowIndex);
|
||||||
mediaPeriodInfoQueue.add(mediaPeriodInfo);
|
mediaPeriodInfoQueue.add(mediaPeriodInfo);
|
||||||
mediaPeriodIdToInfo.put(mediaPeriodId, mediaPeriodInfo);
|
mediaPeriodIdToInfo.put(mediaPeriodId, mediaPeriodInfo);
|
||||||
|
lastPlayingMediaPeriod = mediaPeriodInfoQueue.get(0);
|
||||||
if (mediaPeriodInfoQueue.size() == 1 && !timeline.isEmpty()) {
|
if (mediaPeriodInfoQueue.size() == 1 && !timeline.isEmpty()) {
|
||||||
updateLastReportedPlayingMediaPeriod();
|
lastReportedPlayingMediaPeriod = lastPlayingMediaPeriod;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -835,6 +837,9 @@ public class AnalyticsCollector
|
||||||
if (readingMediaPeriod != null && mediaPeriodId.equals(readingMediaPeriod.mediaPeriodId)) {
|
if (readingMediaPeriod != null && mediaPeriodId.equals(readingMediaPeriod.mediaPeriodId)) {
|
||||||
readingMediaPeriod = mediaPeriodInfoQueue.isEmpty() ? null : mediaPeriodInfoQueue.get(0);
|
readingMediaPeriod = mediaPeriodInfoQueue.isEmpty() ? null : mediaPeriodInfoQueue.get(0);
|
||||||
}
|
}
|
||||||
|
if (!mediaPeriodInfoQueue.isEmpty()) {
|
||||||
|
lastPlayingMediaPeriod = mediaPeriodInfoQueue.get(0);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -843,12 +848,6 @@ public class AnalyticsCollector
|
||||||
readingMediaPeriod = mediaPeriodIdToInfo.get(mediaPeriodId);
|
readingMediaPeriod = mediaPeriodIdToInfo.get(mediaPeriodId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateLastReportedPlayingMediaPeriod() {
|
|
||||||
if (!mediaPeriodInfoQueue.isEmpty()) {
|
|
||||||
lastReportedPlayingMediaPeriod = mediaPeriodInfoQueue.get(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private MediaPeriodInfo updateMediaPeriodInfoToNewTimeline(
|
private MediaPeriodInfo updateMediaPeriodInfoToNewTimeline(
|
||||||
MediaPeriodInfo info, Timeline newTimeline) {
|
MediaPeriodInfo info, Timeline newTimeline) {
|
||||||
int newPeriodIndex = newTimeline.getIndexOfPeriod(info.mediaPeriodId.periodUid);
|
int newPeriodIndex = newTimeline.getIndexOfPeriod(info.mediaPeriodId.periodUid);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue