Back to Exoplayer

Timeline (ExoPlayer library)

docs/doc/reference/com/google/android/exoplayer2/Timeline.html

latest33.1 KB
Original Source

Package com.google.android.exoplayer2

Class Timeline

  • java.lang.Object

    • com.google.android.exoplayer2.Timeline
  • All Implemented Interfaces:BundleableDirect Known Subclasses:AbstractConcatenatedTimeline, FakeMultiPeriodLiveTimeline, FakeTimeline, ForwardingTimeline, MaskingMediaSource.PlaceholderTimeline, SinglePeriodTimeline, Timeline.RemotableTimeline


[@Deprecated](https://developer.android.com/reference/java/lang/Deprecated.html "class or interface in java.lang")public abstract classTimelineextends[Object](https://developer.android.com/reference/java/lang/Object.html "class or interface in java.lang")implements[Bundleable](Bundleable.html "interface in com.google.android.exoplayer2")

Deprecated. com.google.android.exoplayer2 is deprecated. Please migrate to androidx.media3 (which contains the same ExoPlayer code). See the migration guide for more details, including a script to help with the migration.

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 Timeline.Window usually 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 Timeline.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.

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 Timeline.Window.isLive() to indicate it's a live stream and Timeline.Window.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.

Nested Class Summary

Nested Classes | Modifier and Type | Class | Description | | --- | --- | --- | | static class | Timeline.Period | Deprecated.

Holds information about a period in a Timeline. | | static class | Timeline.RemotableTimeline | Deprecated.

A concrete class of Timeline to restore a Timeline instance from a Bundle sent by another process via IBinder. | | static class | Timeline.Window | Deprecated.

Holds information about a window in a Timeline. |

- 

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 Bundleable.Creator<Timeline> | CREATOR | Deprecated.

Object that can restore a Timeline from a Bundle. | | static Timeline | EMPTY | Deprecated.

An empty timeline. |

Constructor Summary

Constructors | Modifier | Constructor | Description | | --- | --- | --- | | protected | Timeline() | Deprecated. |

Method Summary

All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods | Modifier and Type | Method | Description | | --- | --- | --- | | boolean | equals​(Object obj) | Deprecated. | | int | getFirstWindowIndex​(boolean shuffleModeEnabled) | Deprecated.

Returns the index of the first window in the playback order depending on whether shuffling is enabled. | | abstract int | getIndexOfPeriod​(Object uid) | Deprecated.

Returns the index of the period identified by its unique Timeline.Period.uid, or C.INDEX_UNSET if the period is not in the timeline. | | int | getLastWindowIndex​(boolean shuffleModeEnabled) | Deprecated.

Returns the index of the last window in the playback order depending on whether shuffling is enabled. | | int | getNextPeriodIndex​(int periodIndex, Timeline.Period period, Timeline.Window window, @com.google.android.exoplayer2.Player.RepeatMode int repeatMode, boolean shuffleModeEnabled) | Deprecated.

Returns the index of the period after the period at index periodIndex depending on the repeatMode and whether shuffling is enabled. | | int | getNextWindowIndex​(int windowIndex, @com.google.android.exoplayer2.Player.RepeatMode int repeatMode, boolean shuffleModeEnabled) | Deprecated.

Returns the index of the window after the window at index windowIndex depending on the repeatMode and whether shuffling is enabled. | | Timeline.Period | getPeriod​(int periodIndex, Timeline.Period period) | Deprecated.

Populates a Timeline.Period with data for the period at the specified index. | | abstract Timeline.Period | getPeriod​(int periodIndex, Timeline.Period period, boolean setIds) | Deprecated.

Populates a Timeline.Period with data for the period at the specified index. | | Timeline.Period | getPeriodByUid​(Object periodUid, Timeline.Period period) | Deprecated.

Populates a Timeline.Period with data for the period with the specified unique identifier. | | abstract int | getPeriodCount() | Deprecated.

Returns the number of periods in the timeline. | | Pair<Object,​Long> | getPeriodPosition​(Timeline.Window window, Timeline.Period period, int windowIndex, long windowPositionUs) | Deprecated. Use getPeriodPositionUs(Window, Period, int, long) instead.

| | Pair<Object,​Long> | getPeriodPosition​(Timeline.Window window, Timeline.Period period, int windowIndex, long windowPositionUs, long defaultPositionProjectionUs) | Deprecated. Use getPeriodPositionUs(Window, Period, int, long, long) instead.

| | Pair<Object,​Long> | getPeriodPositionUs​(Timeline.Window window, Timeline.Period period, int windowIndex, long windowPositionUs) | Deprecated.

Calls getPeriodPositionUs(Window, Period, int, long) with a zero default position projection. | | Pair<Object,​Long> | getPeriodPositionUs​(Timeline.Window window, Timeline.Period period, int windowIndex, long windowPositionUs, long defaultPositionProjectionUs) | Deprecated.

Converts (windowIndex, windowPositionUs) to the corresponding (periodUid, periodPositionUs). | | int | getPreviousWindowIndex​(int windowIndex, @com.google.android.exoplayer2.Player.RepeatMode int repeatMode, boolean shuffleModeEnabled) | Deprecated.

Returns the index of the window before the window at index windowIndex depending on the repeatMode and whether shuffling is enabled. | | abstract Object | getUidOfPeriod​(int periodIndex) | Deprecated.

Returns the unique id of the period identified by its index in the timeline. | | Timeline.Window | getWindow​(int windowIndex, Timeline.Window window) | Deprecated.

Populates a Timeline.Window with data for the window at the specified index. | | abstract Timeline.Window | getWindow​(int windowIndex, Timeline.Window window, long defaultPositionProjectionUs) | Deprecated.

Populates a Timeline.Window with data for the window at the specified index. | | abstract int | getWindowCount() | Deprecated.

Returns the number of windows in the timeline. | | int | hashCode() | Deprecated. | | boolean | isEmpty() | Deprecated.

Returns whether the timeline is empty. | | boolean | isLastPeriod​(int periodIndex, Timeline.Period period, Timeline.Window window, @com.google.android.exoplayer2.Player.RepeatMode int repeatMode, boolean shuffleModeEnabled) | Deprecated.

Returns whether the given period is the last period of the timeline depending on the repeatMode and whether shuffling is enabled. | | Bundle | toBundle() | Deprecated.

Returns a Bundle representing the information stored in this object. | | Bundle | toBundleWithOneWindowOnly​(int windowIndex) | Deprecated.

Returns a Bundle containing just the specified Timeline.Window. |

- 

Methods inherited from class java.lang.Object

clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait

Field Detail

- 

EMPTY

public static final[Timeline](Timeline.html "class in com.google.android.exoplayer2")EMPTY

Deprecated.

An empty timeline.

- 

CREATOR

public static final[Bundleable.Creator](Bundleable.Creator.html "interface in com.google.android.exoplayer2")<[Timeline](Timeline.html "class in com.google.android.exoplayer2")> CREATOR

Deprecated.

Object that can restore a Timeline from a Bundle.

The getWindow(int, Window) windows} and periods of a restored instance may have missing fields as described in Timeline.Window.CREATOR and Timeline.Period.CREATOR.

Constructor Detail

- 

Timeline

protected Timeline()

Deprecated.

Method Detail

- 

isEmpty

public final boolean isEmpty()

Deprecated.

Returns whether the timeline is empty.

- 

getWindowCount

public abstract int getWindowCount()

Deprecated.

Returns the number of windows in the timeline.

- 

getNextWindowIndex

public int getNextWindowIndex​(int windowIndex,[@RepeatMode](Player.RepeatMode.html "annotation in com.google.android.exoplayer2")@com.google.android.exoplayer2.Player.RepeatMode int repeatMode,
                              boolean shuffleModeEnabled)

Deprecated.

Returns the index of the window after the window at index windowIndex depending on the repeatMode and whether shuffling is enabled. Parameters:windowIndex - Index of a window in the timeline.repeatMode - A repeat mode.shuffleModeEnabled - Whether shuffling is enabled.Returns:The index of the next window, or C.INDEX_UNSET if this is the last window.

- 

getPreviousWindowIndex

public int getPreviousWindowIndex​(int windowIndex,[@RepeatMode](Player.RepeatMode.html "annotation in com.google.android.exoplayer2")@com.google.android.exoplayer2.Player.RepeatMode int repeatMode,
                                  boolean shuffleModeEnabled)

Deprecated.

Returns the index of the window before the window at index windowIndex depending on the repeatMode and whether shuffling is enabled. Parameters:windowIndex - Index of a window in the timeline.repeatMode - A repeat mode.shuffleModeEnabled - Whether shuffling is enabled.Returns:The index of the previous window, or C.INDEX_UNSET if this is the first window.

- 

getLastWindowIndex

public int getLastWindowIndex​(boolean shuffleModeEnabled)

Deprecated.

Returns the index of the last window in the playback order depending on whether shuffling is enabled. Parameters:shuffleModeEnabled - Whether shuffling is enabled.Returns:The index of the last window in the playback order, or C.INDEX_UNSET if the timeline is empty.

- 

getFirstWindowIndex

public int getFirstWindowIndex​(boolean shuffleModeEnabled)

Deprecated.

Returns the index of the first window in the playback order depending on whether shuffling is enabled. Parameters:shuffleModeEnabled - Whether shuffling is enabled.Returns:The index of the first window in the playback order, or C.INDEX_UNSET if the timeline is empty.

- 

getWindow

public final[Timeline.Window](Timeline.Window.html "class in com.google.android.exoplayer2")getWindow​(int windowIndex,[Timeline.Window](Timeline.Window.html "class in com.google.android.exoplayer2")window)

Deprecated.

Populates a Timeline.Window with data for the window at the specified index. Parameters:windowIndex - The index of the window.window - The Timeline.Window to populate. Must not be null.Returns:The populated Timeline.Window, for convenience.

- 

getWindow

public abstract[Timeline.Window](Timeline.Window.html "class in com.google.android.exoplayer2")getWindow​(int windowIndex,[Timeline.Window](Timeline.Window.html "class in com.google.android.exoplayer2")window,
                                          long defaultPositionProjectionUs)

Deprecated.

Populates a Timeline.Window with data for the window at the specified index. Parameters:windowIndex - The index of the window.window - The Timeline.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 abstract int getPeriodCount()

Deprecated.

Returns the number of periods in the timeline.

- 

getNextPeriodIndex

public final int getNextPeriodIndex​(int periodIndex,[Timeline.Period](Timeline.Period.html "class in com.google.android.exoplayer2")period,[Timeline.Window](Timeline.Window.html "class in com.google.android.exoplayer2")window,[@RepeatMode](Player.RepeatMode.html "annotation in com.google.android.exoplayer2")@com.google.android.exoplayer2.Player.RepeatMode int repeatMode,
                                    boolean shuffleModeEnabled)

Deprecated.

Returns the index of the period after the period at index periodIndex depending on the repeatMode and whether shuffling is enabled. Parameters: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.shuffleModeEnabled - Whether shuffling is enabled.Returns:The index of the next period, or C.INDEX_UNSET if this is the last period.

- 

isLastPeriod

public final boolean isLastPeriod​(int periodIndex,[Timeline.Period](Timeline.Period.html "class in com.google.android.exoplayer2")period,[Timeline.Window](Timeline.Window.html "class in com.google.android.exoplayer2")window,[@RepeatMode](Player.RepeatMode.html "annotation in com.google.android.exoplayer2")@com.google.android.exoplayer2.Player.RepeatMode int repeatMode,
                                  boolean shuffleModeEnabled)

Deprecated.

Returns whether the given period is the last period of the timeline depending on the repeatMode and whether shuffling is enabled. Parameters: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.shuffleModeEnabled - Whether shuffling is enabled.Returns:Whether the period of the given index is the last period of the timeline.

- 

getPeriodPosition

[@Deprecated](https://developer.android.com/reference/java/lang/Deprecated.html "class or interface in java.lang")@InlineMe(replacement="this.getPeriodPositionUs(window, period, windowIndex, windowPositionUs)")
public final[Pair](https://developer.android.com/reference/android/util/Pair.html "class or interface in android.util")<[Object](https://developer.android.com/reference/java/lang/Object.html?is-external=true "class or interface in java.lang"),​[Long](https://developer.android.com/reference/java/lang/Long.html?is-external=true "class or interface in java.lang")> getPeriodPosition​([Timeline.Window](Timeline.Window.html "class in com.google.android.exoplayer2")window,[Timeline.Period](Timeline.Period.html "class in com.google.android.exoplayer2")period,
                                                       int windowIndex,
                                                       long windowPositionUs)

Deprecated. Use getPeriodPositionUs(Window, Period, int, long) instead.

- 

getPeriodPosition

[@Deprecated](https://developer.android.com/reference/java/lang/Deprecated.html "class or interface in java.lang")@Nullable
@InlineMe(replacement="this.getPeriodPositionUs(window, period, windowIndex, windowPositionUs, defaultPositionProjectionUs)")
public final[Pair](https://developer.android.com/reference/android/util/Pair.html "class or interface in android.util")<[Object](https://developer.android.com/reference/java/lang/Object.html?is-external=true "class or interface in java.lang"),​[Long](https://developer.android.com/reference/java/lang/Long.html?is-external=true "class or interface in java.lang")> getPeriodPosition​([Timeline.Window](Timeline.Window.html "class in com.google.android.exoplayer2")window,[Timeline.Period](Timeline.Period.html "class in com.google.android.exoplayer2")period,
                                                       int windowIndex,
                                                       long windowPositionUs,
                                                       long defaultPositionProjectionUs)

Deprecated. Use getPeriodPositionUs(Window, Period, int, long, long) instead.

- 

getPeriodPositionUs

public final[Pair](https://developer.android.com/reference/android/util/Pair.html "class or interface in android.util")<[Object](https://developer.android.com/reference/java/lang/Object.html?is-external=true "class or interface in java.lang"),​[Long](https://developer.android.com/reference/java/lang/Long.html?is-external=true "class or interface in java.lang")> getPeriodPositionUs​([Timeline.Window](Timeline.Window.html "class in com.google.android.exoplayer2")window,[Timeline.Period](Timeline.Period.html "class in com.google.android.exoplayer2")period,
                                                         int windowIndex,
                                                         long windowPositionUs)

Deprecated.

Calls getPeriodPositionUs(Window, Period, int, long) with a zero default position projection.

- 

getPeriodPositionUs

@Nullable
public final[Pair](https://developer.android.com/reference/android/util/Pair.html "class or interface in android.util")<[Object](https://developer.android.com/reference/java/lang/Object.html?is-external=true "class or interface in java.lang"),​[Long](https://developer.android.com/reference/java/lang/Long.html?is-external=true "class or interface in java.lang")> getPeriodPositionUs​([Timeline.Window](Timeline.Window.html "class in com.google.android.exoplayer2")window,[Timeline.Period](Timeline.Period.html "class in com.google.android.exoplayer2")period,
                                                         int windowIndex,
                                                         long windowPositionUs,
                                                         long defaultPositionProjectionUs)

Deprecated.

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 - 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.Returns:The corresponding (periodUid, periodPositionUs), or null if #windowPositionUs is C.TIME_UNSET, defaultPositionProjectionUs is non-zero, and the window's position could not be projected by defaultPositionProjectionUs.

- 

getPeriodByUid

public[Timeline.Period](Timeline.Period.html "class in com.google.android.exoplayer2")getPeriodByUid​([Object](https://developer.android.com/reference/java/lang/Object.html "class or interface in java.lang")periodUid,[Timeline.Period](Timeline.Period.html "class in com.google.android.exoplayer2")period)

Deprecated.

Populates a Timeline.Period with data for the period with the specified unique identifier. Parameters:periodUid - The unique identifier of the period.period - The Timeline.Period to populate. Must not be null.Returns:The populated Timeline.Period, for convenience.

- 

getPeriod

public final[Timeline.Period](Timeline.Period.html "class in com.google.android.exoplayer2")getPeriod​(int periodIndex,[Timeline.Period](Timeline.Period.html "class in com.google.android.exoplayer2")period)

Deprecated.

Populates a Timeline.Period with data for the period at the specified index. Timeline.Period.id and Timeline.Period.uid will be set to null. Parameters:periodIndex - The index of the period.period - The Timeline.Period to populate. Must not be null.Returns:The populated Timeline.Period, for convenience.

- 

getPeriod

public abstract[Timeline.Period](Timeline.Period.html "class in com.google.android.exoplayer2")getPeriod​(int periodIndex,[Timeline.Period](Timeline.Period.html "class in com.google.android.exoplayer2")period,
                                          boolean setIds)

Deprecated.

Populates a Timeline.Period with data for the period at the specified index. Parameters: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.Returns:The populated Timeline.Period, for convenience.

- 

getIndexOfPeriod

public abstract int getIndexOfPeriod​([Object](https://developer.android.com/reference/java/lang/Object.html "class or interface in java.lang")uid)

Deprecated.

Returns the index of the period identified by its unique Timeline.Period.uid, or C.INDEX_UNSET if the period is not in the timeline. 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 abstract[Object](https://developer.android.com/reference/java/lang/Object.html "class or interface in java.lang")getUidOfPeriod​(int periodIndex)

Deprecated.

Returns the unique id of the period identified by its index in the timeline. Parameters:periodIndex - The index of the period.Returns:The unique id of the period.

- 

equals

public boolean equals​(@Nullable[Object](https://developer.android.com/reference/java/lang/Object.html "class or interface in java.lang")obj)

Deprecated. Overrides:equals in class Object

- 

hashCode

public int hashCode()

Deprecated. Overrides:hashCode in class Object

- 

toBundle

public final[Bundle](https://developer.android.com/reference/android/os/Bundle.html "class or interface in android.os")toBundle()

Deprecated.

Returns a Bundle representing the information stored in this object.

The getWindow(int, Window) windows} and periods of an instance restored by CREATOR may have missing fields as described in Timeline.Window.toBundle() and Timeline.Period.toBundle().

Specified by:toBundle in interface Bundleable

- 

toBundleWithOneWindowOnly

public final[Bundle](https://developer.android.com/reference/android/os/Bundle.html "class or interface in android.os")toBundleWithOneWindowOnly​(int windowIndex)

Deprecated.

Returns a Bundle containing just the specified Timeline.Window.

The getWindow(int, Window) windows} and periods of an instance restored by CREATOR may have missing fields as described in Timeline.Window.toBundle() and Timeline.Period.toBundle().

Parameters:windowIndex - The index of the Timeline.Window to include in the Bundle.