public abstract class Timeline extends Object
A timeline consists of related Timeline.Periods and Timeline.Windows. A period defines a single
logical piece of media, for example a media file. It may also define groups of ads inserted into
the media, along with information about whether those ads have been loaded and played. A window
spans one or more periods, defining the region within those periods that's currently available
for playback along with additional information such as whether seeking is supported within the
window. Each window defines a default position, which is the position from which playback will
start when the player starts playing the window. The following examples illustrate timelines for
various use cases.
Timeline.Window.isDynamic set to true if
the stream is still live. Its default position is typically near to the live edge (indicated by
the black dot in the figure above).
| Modifier and Type | Class and Description |
|---|---|
static class |
Timeline.Period
Holds information about a period in a
Timeline. |
static class |
Timeline.Window
Holds information about a window in a
Timeline. |
| Modifier and Type | Field and Description |
|---|---|
static Timeline |
EMPTY
An empty timeline.
|
| Constructor and Description |
|---|
Timeline() |
| Modifier and Type | Method and Description |
|---|---|
abstract int |
getIndexOfPeriod(Object uid)
Returns the index of the period identified by its unique
id, or C.INDEX_UNSET
if the period is not in the timeline. |
int |
getNextPeriodIndex(int periodIndex,
Timeline.Period period,
Timeline.Window window,
int repeatMode)
Returns the index of the period after the period at index
periodIndex depending on the
repeatMode. |
int |
getNextWindowIndex(int windowIndex,
int repeatMode)
Returns the index of the window after the window at index
windowIndex depending on the
repeatMode. |
Timeline.Period |
getPeriod(int periodIndex,
Timeline.Period period)
Populates a
Timeline.Period with data for the period at the specified index. |
abstract Timeline.Period |
getPeriod(int periodIndex,
Timeline.Period period,
boolean setIds)
Populates a
Timeline.Period with data for the period at the specified index. |
abstract int |
getPeriodCount()
Returns the number of periods in the timeline.
|
Pair<Integer,Long> |
getPeriodPosition(Timeline.Window window,
Timeline.Period period,
int windowIndex,
long windowPositionUs)
Calls
getPeriodPosition(Window, Period, int, long, long) with a zero default position
projection. |
Pair<Integer,Long> |
getPeriodPosition(Timeline.Window window,
Timeline.Period period,
int windowIndex,
long windowPositionUs,
long defaultPositionProjectionUs)
Converts (windowIndex, windowPositionUs) to the corresponding (periodIndex, periodPositionUs).
|
int |
getPreviousWindowIndex(int windowIndex,
int repeatMode)
Returns the index of the window before the window at index
windowIndex depending on the
repeatMode. |
Timeline.Window |
getWindow(int windowIndex,
Timeline.Window window)
Populates a
Timeline.Window with data for the window at the specified index. |
Timeline.Window |
getWindow(int windowIndex,
Timeline.Window window,
boolean setIds)
Populates a
Timeline.Window with data for the window at the specified index. |
abstract Timeline.Window |
getWindow(int windowIndex,
Timeline.Window window,
boolean setIds,
long defaultPositionProjectionUs)
Populates a
Timeline.Window with data for the window at the specified index. |
abstract int |
getWindowCount()
Returns the number of windows in the timeline.
|
boolean |
isEmpty()
Returns whether the timeline is empty.
|
boolean |
isFirstWindow(int windowIndex,
int repeatMode)
Returns whether the given window is the first window of the timeline depending on the
repeatMode. |
boolean |
isLastPeriod(int periodIndex,
Timeline.Period period,
Timeline.Window window,
int repeatMode)
Returns whether the given period is the last period of the timeline depending on the
repeatMode. |
boolean |
isLastWindow(int windowIndex,
int repeatMode)
Returns whether the given window is the last window of the timeline depending on the
repeatMode. |
public static final Timeline EMPTY
public final boolean isEmpty()
public abstract int getWindowCount()
public int getNextWindowIndex(int windowIndex,
int repeatMode)
windowIndex depending on the
repeatMode.windowIndex - Index of a window in the timeline.repeatMode - A repeat mode.C.INDEX_UNSET if this is the last window.public int getPreviousWindowIndex(int windowIndex,
int repeatMode)
windowIndex depending on the
repeatMode.windowIndex - Index of a window in the timeline.repeatMode - A repeat mode.C.INDEX_UNSET if this is the first window.public final boolean isLastWindow(int windowIndex,
int repeatMode)
repeatMode.windowIndex - A window index.repeatMode - A repeat mode.public final boolean isFirstWindow(int windowIndex,
int repeatMode)
repeatMode.windowIndex - A window index.repeatMode - A repeat mode.public final Timeline.Window getWindow(int windowIndex, Timeline.Window window)
Timeline.Window with data for the window at the specified index. Does not populate
Timeline.Window.id.windowIndex - The index of the window.window - The Timeline.Window to populate. Must not be null.Timeline.Window, for convenience.public Timeline.Window getWindow(int windowIndex, Timeline.Window window, boolean setIds)
Timeline.Window with data for the window at the specified index.windowIndex - The index of the window.window - The Timeline.Window to populate. Must not be null.setIds - Whether Timeline.Window.id should be populated. If false, the field will be set to
null. The caller should pass false for efficiency reasons unless the field is required.Timeline.Window, for convenience.public abstract Timeline.Window getWindow(int windowIndex, Timeline.Window window, boolean setIds, long defaultPositionProjectionUs)
Timeline.Window with data for the window at the specified index.windowIndex - The index of the window.window - The Timeline.Window to populate. Must not be null.setIds - Whether Timeline.Window.id should be populated. If false, the field will be set to
null. The caller should pass false for efficiency reasons unless the field is required.defaultPositionProjectionUs - A duration into the future that the populated window's
default start position should be projected.Timeline.Window, for convenience.public abstract int getPeriodCount()
public final int getNextPeriodIndex(int periodIndex,
Timeline.Period period,
Timeline.Window window,
int repeatMode)
periodIndex depending on the
repeatMode.periodIndex - Index of a period in the timeline.period - A Timeline.Period to be used internally. Must not be null.window - A Timeline.Window to be used internally. Must not be null.repeatMode - A repeat mode.C.INDEX_UNSET if this is the last period.public final boolean isLastPeriod(int periodIndex,
Timeline.Period period,
Timeline.Window window,
int repeatMode)
repeatMode.periodIndex - A period index.period - A Timeline.Period to be used internally. Must not be null.window - A Timeline.Window to be used internally. Must not be null.repeatMode - A repeat mode.public final Timeline.Period getPeriod(int periodIndex, Timeline.Period period)
Timeline.Period with data for the period at the specified index. Does not populate
Timeline.Period.id and Timeline.Period.uid.periodIndex - The index of the period.period - The Timeline.Period to populate. Must not be null.Timeline.Period, for convenience.public final Pair<Integer,Long> getPeriodPosition(Timeline.Window window, Timeline.Period period, int windowIndex, long windowPositionUs)
getPeriodPosition(Window, Period, int, long, long) with a zero default position
projection.public final Pair<Integer,Long> getPeriodPosition(Timeline.Window window, Timeline.Period period, int windowIndex, long windowPositionUs, long defaultPositionProjectionUs)
window - A Timeline.Window that may be overwritten.period - A Timeline.Period that may be overwritten.windowIndex - The window index.windowPositionUs - The window time, or C.TIME_UNSET to use the window's default
start position.defaultPositionProjectionUs - If windowPositionUs is C.TIME_UNSET, the
duration into the future by which the window's position should be projected.#windowPositionUs
is C.TIME_UNSET, defaultPositionProjectionUs is non-zero, and the window's
position could not be projected by defaultPositionProjectionUs.public abstract Timeline.Period getPeriod(int periodIndex, Timeline.Period period, boolean setIds)
Timeline.Period with data for the period at the specified index.periodIndex - The index of the period.period - The Timeline.Period to populate. Must not be null.setIds - Whether Timeline.Period.id and Timeline.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.Timeline.Period, for convenience.public abstract int getIndexOfPeriod(Object uid)
id, or C.INDEX_UNSET
if the period is not in the timeline.uid - A unique identifier for a period.C.INDEX_UNSET if the period was not found.