Commit 714fa477 by tonihei Committed by Oliver Woodman

Add isLastInTimelineWindow to MediaPeriodInfo.

This information isn't easily available to the player at the moment (or it
would need to revaluate this every time), so add it to MediaPeriodInfo similar
to the existing isLastInTimelinePeriod.

The player needs to know whether a MediaPeriod is the last in its Timeline
window if we want to add an option to pause at the end of a window.

PiperOrigin-RevId: 294877628
parent 3d95f9a9
......@@ -53,6 +53,8 @@ import com.google.android.exoplayer2.util.Util;
* period corresponding to a timeline period without ads).
*/
public final boolean isLastInTimelinePeriod;
/** Whether this is the last media period in its timeline window. */
public final boolean isLastInTimelineWindow;
/**
* Whether this is the last media period in the entire timeline. If true, {@link
* #isLastInTimelinePeriod} will also be true.
......@@ -66,6 +68,7 @@ import com.google.android.exoplayer2.util.Util;
long endPositionUs,
long durationUs,
boolean isLastInTimelinePeriod,
boolean isLastInTimelineWindow,
boolean isFinal) {
this.id = id;
this.startPositionUs = startPositionUs;
......@@ -73,6 +76,7 @@ import com.google.android.exoplayer2.util.Util;
this.endPositionUs = endPositionUs;
this.durationUs = durationUs;
this.isLastInTimelinePeriod = isLastInTimelinePeriod;
this.isLastInTimelineWindow = isLastInTimelineWindow;
this.isFinal = isFinal;
}
......@@ -90,6 +94,7 @@ import com.google.android.exoplayer2.util.Util;
endPositionUs,
durationUs,
isLastInTimelinePeriod,
isLastInTimelineWindow,
isFinal);
}
......@@ -107,6 +112,7 @@ import com.google.android.exoplayer2.util.Util;
endPositionUs,
durationUs,
isLastInTimelinePeriod,
isLastInTimelineWindow,
isFinal);
}
......@@ -124,6 +130,7 @@ import com.google.android.exoplayer2.util.Util;
&& endPositionUs == that.endPositionUs
&& durationUs == that.durationUs
&& isLastInTimelinePeriod == that.isLastInTimelinePeriod
&& isLastInTimelineWindow == that.isLastInTimelineWindow
&& isFinal == that.isFinal
&& Util.areEqual(id, that.id);
}
......@@ -137,6 +144,7 @@ import com.google.android.exoplayer2.util.Util;
result = 31 * result + (int) endPositionUs;
result = 31 * result + (int) durationUs;
result = 31 * result + (isLastInTimelinePeriod ? 1 : 0);
result = 31 * result + (isLastInTimelineWindow ? 1 : 0);
result = 31 * result + (isFinal ? 1 : 0);
return result;
}
......
......@@ -353,6 +353,7 @@ import com.google.android.exoplayer2.util.Assertions;
public MediaPeriodInfo getUpdatedMediaPeriodInfo(Timeline timeline, MediaPeriodInfo info) {
MediaPeriodId id = info.id;
boolean isLastInPeriod = isLastInPeriod(id);
boolean isLastInWindow = isLastInWindow(timeline, id);
boolean isLastInTimeline = isLastInTimeline(timeline, id, isLastInPeriod);
timeline.getPeriodByUid(info.id.periodUid, period);
long durationUs =
......@@ -368,6 +369,7 @@ import com.google.android.exoplayer2.util.Assertions;
info.endPositionUs,
durationUs,
isLastInPeriod,
isLastInWindow,
isLastInTimeline);
}
......@@ -735,6 +737,7 @@ import com.google.android.exoplayer2.util.Assertions;
/* endPositionUs= */ C.TIME_UNSET,
durationUs,
/* isLastInTimelinePeriod= */ false,
/* isLastInTimelineWindow= */ false,
/* isFinal= */ false);
}
......@@ -748,6 +751,7 @@ import com.google.android.exoplayer2.util.Assertions;
int nextAdGroupIndex = period.getAdGroupIndexAfterPositionUs(startPositionUs);
MediaPeriodId id = new MediaPeriodId(periodUid, windowSequenceNumber, nextAdGroupIndex);
boolean isLastInPeriod = isLastInPeriod(id);
boolean isLastInWindow = isLastInWindow(timeline, id);
boolean isLastInTimeline = isLastInTimeline(timeline, id, isLastInPeriod);
long endPositionUs =
nextAdGroupIndex != C.INDEX_UNSET
......@@ -764,6 +768,7 @@ import com.google.android.exoplayer2.util.Assertions;
endPositionUs,
durationUs,
isLastInPeriod,
isLastInWindow,
isLastInTimeline);
}
......@@ -771,6 +776,15 @@ import com.google.android.exoplayer2.util.Assertions;
return !id.isAd() && id.nextAdGroupIndex == C.INDEX_UNSET;
}
private boolean isLastInWindow(Timeline timeline, MediaPeriodId id) {
if (!isLastInPeriod(id)) {
return false;
}
int windowIndex = timeline.getPeriodByUid(id.periodUid, period).windowIndex;
int periodIndex = timeline.getIndexOfPeriod(id.periodUid);
return timeline.getWindow(windowIndex, window).lastPeriodIndex == periodIndex;
}
private boolean isLastInTimeline(
Timeline timeline, MediaPeriodId id, boolean isLastMediaPeriodInPeriod) {
int periodIndex = timeline.getIndexOfPeriod(id.periodUid);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment