Timeline
abstract class Timeline
AbstractConcatenatedTimeline |
Abstract base class for the concatenation of one or more |
FakeMultiPeriodLiveTimeline |
A fake |
FakeTimeline |
Fake |
ForwardingTimeline |
An overridable |
MaskingMediaSource.PlaceholderTimeline |
A timeline with one dynamic window with a period of indeterminate duration. |
SinglePeriodTimeline |
A |
Timeline.RemotableTimeline |
A concrete class of |
FakeMediaSource.InitialTimeline |
A forwarding timeline to provide an initial timeline for fake multi window sources. |
SinglePeriodAdTimeline |
A |
TimelineWithUpdatedMediaItem |
A flexible representation of the structure of media. A timeline is able to represent the structure of a wide variety of media, from simple cases like a single media file through to complex compositions of media such as playlists and streams with inserted ads. Instances are immutable. For cases where media is changing dynamically (e.g. live streams), a timeline provides a snapshot of the current state.
A timeline consists of Windows and Periods.
- A
Windowusually corresponds to one playlist item. It may span one or more periods and it defines the region within those periods that's currently available for playback. The window also provides additional information such as whether seeking is supported within the window and the default position, which is the position from which playback will start when the player starts playing the window. - A
Perioddefines 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.
The following examples illustrate timelines for various use cases.
Single media file or on-demand stream
A timeline for a single media file or on-demand stream consists of a single period and window. The window spans the whole period, indicating that all parts of the media are available for playback. The window's default position is typically at the start of the period (indicated by the black dot in the figure above).
Playlist of media files or on-demand streams
A timeline for a playlist of media files or on-demand streams consists of multiple periods, each with its own window. Each window spans the whole of the corresponding period, and typically has a default position at the start of the period. The properties of the periods and windows (e.g. their durations and whether the window is seekable) will often only become known when the player starts buffering the corresponding file or stream.
Live stream with limited availability
A timeline for a live stream consists of a period whose duration is unknown, since it's continually extending as more content is broadcast. If content only remains available for a limited period of time then the window may start at a non-zero position, defining the region of content that can still be played. The window will return true from isLive to indicate it's a live stream and isDynamic will be set to true as long as we expect changes to the live window. Its default position is typically near to the live edge (indicated by the black dot in the figure above).
Live stream with indefinite availability
A timeline for a live stream with indefinite availability is similar to the Live stream with limited availability case, except that the window starts at the beginning of the period to indicate that all of the previously broadcast content can still be played.
Live stream with multiple periods
This case arises when a live stream is explicitly divided into separate periods, for example at content boundaries. This case is similar to the Live stream with limited availability case, except that the window may span more than one period. Multiple periods are also possible in the indefinite availability case.
On-demand stream followed by live stream
This case is the concatenation of the Single media file or on-demand stream and Live stream with multiple periods cases. When playback of the on-demand stream ends, playback of the live stream will start from its default position near the live edge.
On-demand stream with mid-roll ads
This case includes mid-roll ad groups, which are defined as part of the timeline's single period. The period can be queried for information about the ad groups and the ads they contain.
Summary
Nested types |
|---|
class Timeline.PeriodHolds information about a period in a |
|
A concrete class of |
class Timeline.WindowHolds information about a window in a |
Protected constructors |
|---|
Public functions |
|
|---|---|
Timeline! |
@UnstableApiReturns a copy of this timeline containing just the single specified |
Boolean |
|
java-static Timeline! |
@UnstableApiRestores a |
Int |
getFirstWindowIndex(shuffleModeEnabled: Boolean)Returns the index of the first window in the playback order depending on whether shuffling is enabled. |
abstract Int |
getIndexOfPeriod(uid: Any!)Returns the index of the period identified by its unique |
Int |
getLastWindowIndex(shuffleModeEnabled: Boolean)Returns the index of the last window in the playback order depending on whether shuffling is enabled. |
Int |
getNextPeriodIndex(Returns the index of the period after the period at index |
Int |
getNextWindowIndex(Returns the index of the window after the window at index |
Timeline.Period! |
getPeriod(periodIndex: Int, period: Timeline.Period!)Populates a |
abstract Timeline.Period! |
getPeriod(periodIndex: Int, period: Timeline.Period!, setIds: Boolean)Populates a |
Timeline.Period! |
getPeriodByUid(periodUid: Any!, period: Timeline.Period!)Populates a |
abstract Int |
Returns the number of periods in the timeline. |
Pair<Any!, Long!>! |
@UnstableApiThis function is deprecated. Use |
Pair<Any!, Long!>? |
@UnstableApiThis function is deprecated. Use |
Pair<Any!, Long!>! |
getPeriodPositionUs(Calls |
Pair<Any!, Long!>? |
getPeriodPositionUs(Converts |
Int |
getPreviousWindowIndex(Returns the index of the window before the window at index |
abstract Any! |
getUidOfPeriod(periodIndex: Int)Returns the unique id of the period identified by its index in the timeline. |
Timeline.Window! |
getWindow(windowIndex: Int, window: Timeline.Window!)Populates a |
abstract Timeline.Window! |
getWindow(Populates a |
abstract Int |
Returns the number of windows in the timeline. |
Int |
hashCode() |
Boolean |
isEmpty()Returns whether the timeline is empty. |
Boolean |
isLastPeriod(Returns whether the given period is the last period of the timeline depending on the |
Bundle! |
Returns a |
Protected constructors
Public functions
copyWithSingleWindow
@UnstableApi
fun copyWithSingleWindow(windowIndex: Int): Timeline!
Returns a copy of this timeline containing just the single specified Window.
The method returns the same instance if there is only one window.
fromBundle
@UnstableApi
java-static fun fromBundle(bundle: Bundle!): Timeline!
Restores a Timeline from a Bundle.
getFirstWindowIndex
fun getFirstWindowIndex(shuffleModeEnabled: Boolean): Int
Returns the index of the first window in the playback order depending on whether shuffling is enabled.
| Parameters | |
|---|---|
shuffleModeEnabled: Boolean |
Whether shuffling is enabled. |
| Returns | |
|---|---|
Int |
The index of the first window in the playback order, or |
getIndexOfPeriod
abstract fun getIndexOfPeriod(uid: Any!): Int
Returns the index of the period identified by its unique uid, or INDEX_UNSET if the period is not in the timeline.
| Parameters | |
|---|---|
uid: Any! |
A unique identifier for a period. |
| Returns | |
|---|---|
Int |
The index of the period, or |
getLastWindowIndex
fun getLastWindowIndex(shuffleModeEnabled: Boolean): Int
Returns the index of the last window in the playback order depending on whether shuffling is enabled.
| Parameters | |
|---|---|
shuffleModeEnabled: Boolean |
Whether shuffling is enabled. |
| Returns | |
|---|---|
Int |
The index of the last window in the playback order, or |
getNextPeriodIndex
fun getNextPeriodIndex(
periodIndex: Int,
period: Timeline.Period!,
window: Timeline.Window!,
@Player.RepeatMode repeatMode: Int,
shuffleModeEnabled: Boolean
): Int
Returns the index of the period after the period at index periodIndex depending on the repeatMode and whether shuffling is enabled.
| Parameters | |
|---|---|
periodIndex: Int |
Index of a period in the timeline. |
period: Timeline.Period! |
A |
window: Timeline.Window! |
A |
@Player.RepeatMode repeatMode: Int |
A repeat mode. |
shuffleModeEnabled: Boolean |
Whether shuffling is enabled. |
| Returns | |
|---|---|
Int |
The index of the next period, or |
getNextWindowIndex
fun getNextWindowIndex(
windowIndex: Int,
@Player.RepeatMode repeatMode: Int,
shuffleModeEnabled: Boolean
): Int
Returns the index of the window after the window at index windowIndex depending on the repeatMode and whether shuffling is enabled.
| Parameters | |
|---|---|
windowIndex: Int |
Index of a window in the timeline. |
@Player.RepeatMode repeatMode: Int |
A repeat mode. |
shuffleModeEnabled: Boolean |
Whether shuffling is enabled. |
| Returns | |
|---|---|
Int |
The index of the next window, or |
getPeriod
fun getPeriod(periodIndex: Int, period: Timeline.Period!): Timeline.Period!
Populates a Period with data for the period at the specified index. id and uid will be set to null.
| Parameters | |
|---|---|
periodIndex: Int |
The index of the period. |
period: Timeline.Period! |
The |
| Returns | |
|---|---|
Timeline.Period! |
The populated |
getPeriod
abstract fun getPeriod(periodIndex: Int, period: Timeline.Period!, setIds: Boolean): Timeline.Period!
Populates a Period with data for the period at the specified index.
| Parameters | |
|---|---|
periodIndex: Int |
The index of the period. |
period: Timeline.Period! |
The |
setIds: Boolean |
Whether |
| Returns | |
|---|---|
Timeline.Period! |
The populated |
getPeriodByUid
fun getPeriodByUid(periodUid: Any!, period: Timeline.Period!): Timeline.Period!
Populates a Period with data for the period with the specified unique identifier.
| Parameters | |
|---|---|
periodUid: Any! |
The unique identifier of the period. |
period: Timeline.Period! |
The |
| Returns | |
|---|---|
Timeline.Period! |
The populated |
getPeriodPosition
@UnstableApi
@InlineMe(replacement = "this.getPeriodPositionUs(window, period, windowIndex, windowPositionUs)")
fungetPeriodPosition(
window: Timeline.Window!,
period: Timeline.Period!,
windowIndex: Int,
windowPositionUs: Long
): Pair<Any!, Long!>!
getPeriodPosition
@UnstableApi
@InlineMe(replacement = "this.getPeriodPositionUs(" + "window, period, windowIndex, windowPositionUs, defaultPositionProjectionUs)")
fungetPeriodPosition(
window: Timeline.Window!,
period: Timeline.Period!,
windowIndex: Int,
windowPositionUs: Long,
defaultPositionProjectionUs: Long
): Pair<Any!, Long!>?
getPeriodPositionUs
fun getPeriodPositionUs(
window: Timeline.Window!,
period: Timeline.Period!,
windowIndex: Int,
windowPositionUs: Long
): Pair<Any!, Long!>!
Calls getPeriodPositionUs with a zero default position projection.
getPeriodPositionUs
fun getPeriodPositionUs(
window: Timeline.Window!,
period: Timeline.Period!,
windowIndex: Int,
windowPositionUs: Long,
defaultPositionProjectionUs: Long
): Pair<Any!, Long!>?
Converts (windowIndex, windowPositionUs) to the corresponding (periodUid,
periodPositionUs). The returned periodPositionUs is constrained to be non-negative, and to be less than the containing period's duration if it is known.
| Parameters | |
|---|---|
window: Timeline.Window! |
A |
period: Timeline.Period! |
A |
windowIndex: Int |
The window index. |
windowPositionUs: Long |
The window time, or |
defaultPositionProjectionUs: Long |
If |
| Returns | |
|---|---|
Pair<Any!, Long!>? |
The corresponding (periodUid, periodPositionUs), or null if |
getPreviousWindowIndex
fun getPreviousWindowIndex(
windowIndex: Int,
@Player.RepeatMode repeatMode: Int,
shuffleModeEnabled: Boolean
): Int
Returns the index of the window before the window at index windowIndex depending on the repeatMode and whether shuffling is enabled.
| Parameters | |
|---|---|
windowIndex: Int |
Index of a window in the timeline. |
@Player.RepeatMode repeatMode: Int |
A repeat mode. |
shuffleModeEnabled: Boolean |
Whether shuffling is enabled. |
| Returns | |
|---|---|
Int |
The index of the previous window, or |
getUidOfPeriod
abstract fun getUidOfPeriod(periodIndex: Int): Any!
Returns the unique id of the period identified by its index in the timeline.
| Parameters | |
|---|---|
periodIndex: Int |
The index of the period. |
| Returns | |
|---|---|
Any! |
The unique id of the period. |
getWindow
fun getWindow(windowIndex: Int, window: Timeline.Window!): Timeline.Window!
Populates a Window with data for the window at the specified index.
| Parameters | |
|---|---|
windowIndex: Int |
The index of the window. |
window: Timeline.Window! |
The |
| Returns | |
|---|---|
Timeline.Window! |
The populated |
getWindow
abstract fun getWindow(
windowIndex: Int,
window: Timeline.Window!,
defaultPositionProjectionUs: Long
): Timeline.Window!
Populates a Window with data for the window at the specified index.
| Parameters | |
|---|---|
windowIndex: Int |
The index of the window. |
window: Timeline.Window! |
The |
defaultPositionProjectionUs: Long |
A duration into the future that the populated window's default start position should be projected. |
| Returns | |
|---|---|
Timeline.Window! |
The populated |
isLastPeriod
fun isLastPeriod(
periodIndex: Int,
period: Timeline.Period!,
window: Timeline.Window!,
@Player.RepeatMode repeatMode: Int,
shuffleModeEnabled: Boolean
): Boolean
Returns whether the given period is the last period of the timeline depending on the
repeatMode and whether shuffling is enabled.
| Parameters | |
|---|---|
periodIndex: Int |
A period index. |
period: Timeline.Period! |
A |
window: Timeline.Window! |
A |
@Player.RepeatMode repeatMode: Int |
A repeat mode. |
shuffleModeEnabled: Boolean |
Whether shuffling is enabled. |
| Returns | |
|---|---|
Boolean |
Whether the period of the given index is the last period of the timeline. |
toBundle
@UnstableApi
fun toBundle(): Bundle!
Returns a Bundle representing the information stored in this object.
The getWindow windows} and periods of an instance restored by fromBundle may have missing fields as described in toBundle and toBundle.