updateQueuedPeriods(): If known duration changed for a media period, remove all media periods after

PiperOrigin-RevId: 223603915
This commit is contained in:
olly 2018-12-01 02:01:20 +00:00 committed by Oliver Woodman
parent ffbb0da893
commit 24f2cbb215

View File

@ -307,7 +307,11 @@ import com.google.android.exoplayer2.util.Assertions;
MediaPeriodHolder periodHolder = getFrontPeriod();
while (periodHolder != null) {
if (previousPeriodHolder == null) {
long previousDurationUs = periodHolder.info.durationUs;
periodHolder.info = getUpdatedMediaPeriodInfo(periodHolder.info);
if (!canKeepAfterMediaPeriodHolder(periodHolder, previousDurationUs)) {
return !removeAfter(periodHolder);
}
} else {
// Check this period holder still follows the previous one, based on the new timeline.
if (periodIndex == C.INDEX_UNSET
@ -326,6 +330,8 @@ import com.google.android.exoplayer2.util.Assertions;
// Check the media period information matches the new timeline.
if (!canKeepMediaPeriodHolder(periodHolder, periodInfo)) {
return !removeAfter(previousPeriodHolder);
} else if (!canKeepAfterMediaPeriodHolder(periodHolder, periodInfo.durationUs)) {
return !removeAfter(periodHolder);
}
}
@ -468,6 +474,15 @@ import com.google.android.exoplayer2.util.Assertions;
&& periodHolderInfo.id.equals(info.id);
}
/**
* Returns whether periods after {@code periodHolder} can be kept for playing given its previous
* duration.
*/
private boolean canKeepAfterMediaPeriodHolder(
MediaPeriodHolder periodHolder, long previousDurationUs) {
return previousDurationUs == C.TIME_UNSET || previousDurationUs == periodHolder.info.durationUs;
}
/**
* Updates the queue for any playback mode change, and returns whether the change was fully
* handled. If not, it is necessary to seek to the current playback position.