Class FakeMultiPeriodLiveTimeline
- java.lang.Object
-
- com.google.android.exoplayer2.Timeline
-
- com.google.android.exoplayer2.testutil.FakeMultiPeriodLiveTimeline
-
- All Implemented Interfaces:
Bundleable
public class FakeMultiPeriodLiveTimeline extends Timeline
A fakeTimeline
that produces a live window with periods according to the available time range.The parameters passed to the constructor define the availability start time, the window size and
now
. UseadvanceNowUs(long)
to advance the live window of the timeline accordingly.The first available period with
ID
0 (zero) starts atavailabilityStartTimeUs
. Thelive window
starts atnow - liveWindowDurationUs
with the first period of the window having its ID relative to the first available period.Periods are either of type content or ad as defined by the ad sequence pattern. A period is an ad if
adSequencePattern[id % adSequencePattern.length]
evaluates to true. Ad periods have a duration ofAD_PERIOD_DURATION_MS
and content periods have a duration ofPERIOD_DURATION_MS
.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.google.android.exoplayer2.Timeline
Timeline.Period, Timeline.RemotableTimeline, Timeline.Window
-
Nested classes/interfaces inherited from interface com.google.android.exoplayer2.Bundleable
Bundleable.Creator<T extends Bundleable>
-
-
Field Summary
Fields Modifier and Type Field Description static long
AD_PERIOD_DURATION_MS
static long
PERIOD_DURATION_MS
-
Constructor Summary
Constructors Constructor Description FakeMultiPeriodLiveTimeline(long availabilityStartTimeMs, long liveWindowDurationUs, long nowUs, boolean[] adSequencePattern, long[] periodDurationMsPattern, boolean isContentTimeline, boolean populateAds, boolean playedAds)
Creates an instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
advanceNowUs(long durationUs)
Advances the live window by the given duration, in microseconds.int
getIndexOfPeriod(Object uid)
Returns the index of the period identified by its uniqueTimeline.Period.uid
, orC.INDEX_UNSET
if the period is not in the timeline.Timeline.Period
getPeriod(int periodIndex, Timeline.Period period, boolean setIds)
Populates aTimeline.Period
with data for the period at the specified index.int
getPeriodCount()
Returns the number of periods in the timeline.long
getPeriodStartTimeUs(int periodIndex)
Returns the period start time since Unix epoch, in microseconds.Object
getUidOfPeriod(int periodIndex)
Returns the unique id of the period identified by its index in the timeline.Timeline.Window
getWindow(int windowIndex, Timeline.Window window, long defaultPositionProjectionUs)
Populates aTimeline.Window
with data for the window at the specified index.int
getWindowCount()
Returns the number of windows in the timeline.long
getWindowStartTimeUs()
The window's start time in microseconds since the Unix epoch, orC.TIME_UNSET
if unknown or not applicable.-
Methods inherited from class com.google.android.exoplayer2.Timeline
equals, getFirstWindowIndex, getLastWindowIndex, getNextPeriodIndex, getNextWindowIndex, getPeriod, getPeriodByUid, getPeriodPosition, getPeriodPosition, getPeriodPositionUs, getPeriodPositionUs, getPreviousWindowIndex, getWindow, hashCode, isEmpty, isLastPeriod, toBundle, toBundleWithOneWindowOnly
-
-
-
-
Field Detail
-
AD_PERIOD_DURATION_MS
public static final long AD_PERIOD_DURATION_MS
- See Also:
- Constant Field Values
-
PERIOD_DURATION_MS
public static final long PERIOD_DURATION_MS
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
FakeMultiPeriodLiveTimeline
public FakeMultiPeriodLiveTimeline(long availabilityStartTimeMs, long liveWindowDurationUs, long nowUs, boolean[] adSequencePattern, long[] periodDurationMsPattern, boolean isContentTimeline, boolean populateAds, boolean playedAds)
Creates an instance.- Parameters:
availabilityStartTimeMs
- The start time of the available time range, UNIX epoch in milliseconds.liveWindowDurationUs
- The duration of the live window.nowUs
- The current time that determines the end of the live window.adSequencePattern
- The repeating pattern of periods starting atavailabilityStartTimeMs
. True is an ad period, and false a content period.periodDurationMsPattern
- The repeating pattern of periods durations starting atavailabilityStartTimeMs
, in milliseconds. Must have the same length asadSequencePattern
.isContentTimeline
- Whether the timeline is a content timeline withoutAdPlaybackState
s.populateAds
- Whether to populate ads in the same way if an ad event has been received.playedAds
- Whether ads should be marked as played if populated.
-
-
Method Detail
-
advanceNowUs
public void advanceNowUs(long durationUs)
Advances the live window by the given duration, in microseconds.
-
getWindowStartTimeUs
public long getWindowStartTimeUs()
The window's start time in microseconds since the Unix epoch, orC.TIME_UNSET
if unknown or not applicable.
-
getPeriodStartTimeUs
public long getPeriodStartTimeUs(int periodIndex)
Returns the period start time since Unix epoch, in microseconds.Note: The returned value has millisecond precision only, so the trailing 3 digits are always zeros.
-
getWindowCount
public int getWindowCount()
Description copied from class:Timeline
Returns the number of windows in the timeline.- Specified by:
getWindowCount
in classTimeline
-
getWindow
public Timeline.Window getWindow(int windowIndex, Timeline.Window window, long defaultPositionProjectionUs)
Description copied from class:Timeline
Populates aTimeline.Window
with data for the window at the specified index.- Specified by:
getWindow
in classTimeline
- Parameters:
windowIndex
- The index of the window.window
- TheTimeline.Window
to populate. Must not be null.defaultPositionProjectionUs
- A duration into the future that the populated window's default start position should be projected.- Returns:
- The populated
Timeline.Window
, for convenience.
-
getPeriodCount
public int getPeriodCount()
Description copied from class:Timeline
Returns the number of periods in the timeline.- Specified by:
getPeriodCount
in classTimeline
-
getPeriod
public Timeline.Period getPeriod(int periodIndex, Timeline.Period period, boolean setIds)
Description copied from class:Timeline
Populates aTimeline.Period
with data for the period at the specified index.- Specified by:
getPeriod
in classTimeline
- Parameters:
periodIndex
- The index of the period.period
- TheTimeline.Period
to populate. Must not be null.setIds
- WhetherTimeline.Period.id
andTimeline.Period.uid
should be populated. If false, the fields will be set to null. The caller should pass false for efficiency reasons unless the fields are required.- Returns:
- The populated
Timeline.Period
, for convenience.
-
getIndexOfPeriod
public int getIndexOfPeriod(Object uid)
Description copied from class:Timeline
Returns the index of the period identified by its uniqueTimeline.Period.uid
, orC.INDEX_UNSET
if the period is not in the timeline.- Specified by:
getIndexOfPeriod
in classTimeline
- Parameters:
uid
- A unique identifier for a period.- Returns:
- The index of the period, or
C.INDEX_UNSET
if the period was not found.
-
getUidOfPeriod
public Object getUidOfPeriod(int periodIndex)
Description copied from class:Timeline
Returns the unique id of the period identified by its index in the timeline.- Specified by:
getUidOfPeriod
in classTimeline
- Parameters:
periodIndex
- The index of the period.- Returns:
- The unique id of the period.
-
-