Timeline.Period
public final class Timeline.Period
Holds information about a period in a Timeline. 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.
The figure below shows some of the information defined by a period, as well as how this information relates to a corresponding Window in the timeline.
Summary
Public fields |
|
|---|---|
AdPlaybackState |
The |
long |
The duration of this period in microseconds, or |
@Nullable Object |
An identifier for the period. |
boolean |
Whether this period contains placeholder information because the real information has yet to be loaded. |
long |
The position of the start of this period relative to the start of the window to which it belongs, in microseconds. |
@Nullable Object |
A unique identifier for the period. |
int |
The index of the window to which this period belongs. |
Public constructors |
|---|
Period()Creates a new instance with no ad playback state. |
Public methods |
|
|---|---|
boolean |
|
static Timeline.Period |
@UnstableApiRestores a |
int |
getAdCountInAdGroup(int adGroupIndex)Returns the number of ads in the ad group at index |
long |
getAdDurationUs(int adGroupIndex, int adIndexInAdGroup)Returns the duration of the ad at index |
int |
Returns the number of ad groups in the period. |
int |
getAdGroupIndexAfterPositionUs(long positionUs)Returns the index of the next ad group after |
int |
getAdGroupIndexForPositionUs(long positionUs)Returns the index of the ad group at or before |
long |
getAdGroupTimeUs(int adGroupIndex)Returns the time of the ad group at index |
long |
Returns the position offset in the first unplayed ad at which to begin playback, in microseconds. |
int |
@UnstableApiReturns the state of the ad at index |
@Nullable Object |
getAdsId()Returns the opaque identifier for ads played with this period, or |
long |
@UnstableApiReturns the offset in microseconds which should be added to the content stream when resuming playback after the specified ad group. |
long |
Returns the duration of the period in milliseconds, or |
long |
Returns the duration of this period in microseconds, or |
int |
getFirstAdIndexToPlay(int adGroupIndex)Returns the index of the first ad in the specified ad group that should be played, or the number of ads in the ad group if no ads should be played. |
int |
getNextAdIndexToPlay(int adGroupIndex, int lastPlayedAdIndex)Returns the index of the next ad in the specified ad group that should be played after playing |
long |
Returns the position of the start of this period relative to the start of the window to which it belongs, in milliseconds. |
long |
Returns the position of the start of this period relative to the start of the window to which it belongs, in microseconds. |
int |
Returns the number of removed ad groups in the period. |
boolean |
hasPlayedAdGroup(int adGroupIndex)Returns whether all ads in the ad group at index |
int |
hashCode() |
boolean |
@UnstableApiReturns whether the ad group at the given ad group index is a live postroll placeholder. |
boolean |
@UnstableApiReturns whether the ad group at index |
Timeline.Period |
@CanIgnoreReturnValueSets the data held by this period. |
Timeline.Period |
@CanIgnoreReturnValueSets the data held by this period. |
Bundle |
Returns a |
Public fields
adPlaybackState
@UnstableApi
public AdPlaybackState adPlaybackState
The AdPlaybackState for all ads in this period.
durationUs
@UnstableApi
public long durationUs
The duration of this period in microseconds, or TIME_UNSET if unknown.
id
public @Nullable Object id
An identifier for the period. Not necessarily unique. May be null if the ids of the period are not required.
isPlaceholder
public boolean isPlaceholder
Whether this period contains placeholder information because the real information has yet to be loaded.
positionInWindowUs
@UnstableApi
public long positionInWindowUs
The position of the start of this period relative to the start of the window to which it belongs, in microseconds. May be negative if the start of the period is not within the window.
Public constructors
Public methods
fromBundle
@UnstableApi
public static Timeline.Period fromBundle(Bundle bundle)
Restores a Period from a Bundle.
getAdCountInAdGroup
public int getAdCountInAdGroup(int adGroupIndex)
Returns the number of ads in the ad group at index adGroupIndex, or LENGTH_UNSET if not yet known.
| Parameters | |
|---|---|
int adGroupIndex |
The ad group index. |
| Returns | |
|---|---|
int |
The number of ads in the ad group, or |
getAdDurationUs
public long getAdDurationUs(int adGroupIndex, int adIndexInAdGroup)
Returns the duration of the ad at index adIndexInAdGroup in the ad group at
adGroupIndex, in microseconds, or TIME_UNSET if not yet known.
| Parameters | |
|---|---|
int adGroupIndex |
The ad group index. |
int adIndexInAdGroup |
The ad index in the ad group. |
| Returns | |
|---|---|
long |
The duration of the ad, or |
getAdGroupIndexAfterPositionUs
public int getAdGroupIndexAfterPositionUs(long positionUs)
Returns the index of the next ad group after positionUs in the period that has ads that should be played. Returns INDEX_UNSET if there is no such ad group.
| Parameters | |
|---|---|
long positionUs |
The period position after which to find an ad group, in microseconds. |
| Returns | |
|---|---|
int |
The index of the ad group, or |
getAdGroupIndexForPositionUs
public int getAdGroupIndexForPositionUs(long positionUs)
Returns the index of the ad group at or before positionUs in the period that should be played before the content at positionUs. Returns INDEX_UNSET if the ad group at or before positionUs has no ads remaining to be played, or if there is no such ad group.
| Parameters | |
|---|---|
long positionUs |
The period position at or before which to find an ad group, in microseconds. |
| Returns | |
|---|---|
int |
The index of the ad group, or |
getAdGroupTimeUs
public long getAdGroupTimeUs(int adGroupIndex)
Returns the time of the ad group at index adGroupIndex in the period, in microseconds.
| Parameters | |
|---|---|
int adGroupIndex |
The ad group index. |
| Returns | |
|---|---|
long |
The time of the ad group at the index relative to the start of the enclosing |
getAdResumePositionUs
public long getAdResumePositionUs()
Returns the position offset in the first unplayed ad at which to begin playback, in microseconds.
getAdState
@UnstableApi
public int getAdState(int adGroupIndex, int adIndexInAdGroup)
Returns the state of the ad at index adIndexInAdGroup in the ad group at
adGroupIndex, or AD_STATE_UNAVAILABLE if not yet known.
| Parameters | |
|---|---|
int adGroupIndex |
The ad group index. |
int adIndexInAdGroup |
The index of the ad in the ad group. |
| Returns | |
|---|---|
int |
The state of the ad, or |
getAdsId
public @Nullable Object getAdsId()
Returns the opaque identifier for ads played with this period, or null if unset.
getContentResumeOffsetUs
@UnstableApi
public long getContentResumeOffsetUs(int adGroupIndex)
Returns the offset in microseconds which should be added to the content stream when resuming playback after the specified ad group.
| Parameters | |
|---|---|
int adGroupIndex |
The ad group index. |
| Returns | |
|---|---|
long |
The offset that should be added to the content stream, in microseconds. |
getDurationMs
public long getDurationMs()
Returns the duration of the period in milliseconds, or TIME_UNSET if unknown.
getDurationUs
public long getDurationUs()
Returns the duration of this period in microseconds, or TIME_UNSET if unknown.
getFirstAdIndexToPlay
public int getFirstAdIndexToPlay(int adGroupIndex)
Returns the index of the first ad in the specified ad group that should be played, or the number of ads in the ad group if no ads should be played.
| Parameters | |
|---|---|
int adGroupIndex |
The ad group index. |
| Returns | |
|---|---|
int |
The index of the first ad that should be played, or the number of ads in the ad group if no ads should be played. |
getNextAdIndexToPlay
public int getNextAdIndexToPlay(int adGroupIndex, int lastPlayedAdIndex)
Returns the index of the next ad in the specified ad group that should be played after playing adIndexInAdGroup, or the number of ads in the ad group if no later ads should be played.
| Parameters | |
|---|---|
int adGroupIndex |
The ad group index. |
int lastPlayedAdIndex |
The last played ad index in the ad group. |
| Returns | |
|---|---|
int |
The index of the next ad that should be played, or the number of ads in the ad group if the ad group does not have any ads remaining to play. |
getPositionInWindowMs
public long getPositionInWindowMs()
Returns the position of the start of this period relative to the start of the window to which it belongs, in milliseconds. May be negative if the start of the period is not within the window.
getPositionInWindowUs
public long getPositionInWindowUs()
Returns the position of the start of this period relative to the start of the window to which it belongs, in microseconds. May be negative if the start of the period is not within the window.
getRemovedAdGroupCount
public int getRemovedAdGroupCount()
Returns the number of removed ad groups in the period. Ad groups with indices between
0 (inclusive) and removedAdGroupCount (exclusive) will be empty.
hasPlayedAdGroup
public boolean hasPlayedAdGroup(int adGroupIndex)
Returns whether all ads in the ad group at index adGroupIndex have been played, skipped or failed.
| Parameters | |
|---|---|
int adGroupIndex |
The ad group index. |
| Returns | |
|---|---|
boolean |
Whether all ads in the ad group at index |
isLivePostrollPlaceholder
@UnstableApi
public boolean isLivePostrollPlaceholder(int adGroupIndex)
Returns whether the ad group at the given ad group index is a live postroll placeholder.
| Parameters | |
|---|---|
int adGroupIndex |
The ad group index. |
| Returns | |
|---|---|
boolean |
True if the ad group at the given index is a live postroll placeholder. |
isServerSideInsertedAdGroup
@UnstableApi
public boolean isServerSideInsertedAdGroup(int adGroupIndex)
Returns whether the ad group at index adGroupIndex is server-side inserted and part of the content stream.
| Parameters | |
|---|---|
int adGroupIndex |
The ad group index. |
| Returns | |
|---|---|
boolean |
Whether this ad group is server-side inserted and part of the content stream. |
set
@CanIgnoreReturnValue
@UnstableApi
public Timeline.Period set(
@Nullable Object id,
@Nullable Object uid,
int windowIndex,
long durationUs,
long positionInWindowUs
)
Sets the data held by this period.
| Parameters | |
|---|---|
@Nullable Object id |
An identifier for the period. Not necessarily unique. May be null if the ids of the period are not required. |
@Nullable Object uid |
A unique identifier for the period. May be null if the ids of the period are not required. |
int windowIndex |
The index of the window to which this period belongs. |
long durationUs |
The duration of this period in microseconds, or |
long positionInWindowUs |
The position of the start of this period relative to the start of the window to which it belongs, in milliseconds. May be negative if the start of the period is not within the window. |
| Returns | |
|---|---|
Timeline.Period |
This period, for convenience. |
set
@CanIgnoreReturnValue
@UnstableApi
public Timeline.Period set(
@Nullable Object id,
@Nullable Object uid,
int windowIndex,
long durationUs,
long positionInWindowUs,
AdPlaybackState adPlaybackState,
boolean isPlaceholder
)
Sets the data held by this period.
| Parameters | |
|---|---|
@Nullable Object id |
An identifier for the period. Not necessarily unique. May be null if the ids of the period are not required. |
@Nullable Object uid |
A unique identifier for the period. May be null if the ids of the period are not required. |
int windowIndex |
The index of the window to which this period belongs. |
long durationUs |
The duration of this period in microseconds, or |
long positionInWindowUs |
The position of the start of this period relative to the start of the window to which it belongs, in milliseconds. May be negative if the start of the period is not within the window. |
AdPlaybackState adPlaybackState |
The state of the period's ads, or |
boolean isPlaceholder |
Whether this period contains placeholder information because the real information has yet to be loaded. |
| Returns | |
|---|---|
Timeline.Period |
This period, for convenience. |
toBundle
@UnstableApi
public Bundle toBundle()
Returns a Bundle representing the information stored in this object.
It omits the id and uid fields so these fields of an instance restored by fromBundle will always be null.