public static final class Timeline.Period extends Object
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 Timeline.Window
in the timeline.
Modifier and Type | Field | Description |
---|---|---|
long |
durationUs |
The duration of this period in microseconds, or
C.TIME_UNSET if unknown. |
Object |
id |
An identifier for the period.
|
Object |
uid |
A unique identifier for the period.
|
int |
windowIndex |
The index of the window to which this period belongs.
|
Constructor | Description |
---|---|
Period() |
Creates a new instance with no ad playback state.
|
Modifier and Type | Method | Description |
---|---|---|
boolean |
equals(Object obj) |
|
int |
getAdCountInAdGroup(int adGroupIndex) |
Returns the number of ads in the ad group at index
adGroupIndex , or
C.LENGTH_UNSET if not yet known. |
long |
getAdDurationUs(int adGroupIndex,
int adIndexInAdGroup) |
Returns the duration of the ad at index
adIndexInAdGroup in the ad group at
adGroupIndex , in microseconds, or C.TIME_UNSET if not yet known. |
int |
getAdGroupCount() |
Returns the number of ad groups in the period.
|
int |
getAdGroupIndexAfterPositionUs(long positionUs) |
Returns the index of the next ad group after
positionUs in the period that has ads
remaining to be played. |
int |
getAdGroupIndexForPositionUs(long positionUs) |
Returns the index of the ad group at or before
positionUs in the period, if that ad
group is unplayed. |
long |
getAdGroupTimeUs(int adGroupIndex) |
Returns the time of the ad group at index
adGroupIndex in the period, in
microseconds. |
long |
getAdResumePositionUs() |
Returns the position offset in the first unplayed ad at which to begin playback, in
microseconds.
|
Object |
getAdsId() |
Returns the opaque identifier for ads played with this period, or
null if unset. |
long |
getDurationMs() |
Returns the duration of the period in milliseconds, or
C.TIME_UNSET if unknown. |
long |
getDurationUs() |
Returns the duration of this period in microseconds, or
C.TIME_UNSET if unknown. |
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
adIndexInAdGroup , or the number of ads in the ad group if no later ads should
be played. |
long |
getPositionInWindowMs() |
Returns the position of the start of this period relative to the start of the window to which
it belongs, in milliseconds.
|
long |
getPositionInWindowUs() |
Returns the position of the start of this period relative to the start of the window to which
it belongs, in microseconds.
|
int |
hashCode() |
|
boolean |
hasPlayedAdGroup(int adGroupIndex) |
Returns whether the ad group at index
adGroupIndex has been played. |
Timeline.Period |
set(Object id,
Object uid,
int windowIndex,
long durationUs,
long positionInWindowUs) |
Sets the data held by this period.
|
Timeline.Period |
set(Object id,
Object uid,
int windowIndex,
long durationUs,
long positionInWindowUs,
AdPlaybackState adPlaybackState) |
Sets the data held by this period.
|
@Nullable public Object id
@Nullable public Object uid
public int windowIndex
public long durationUs
C.TIME_UNSET
if unknown.public Timeline.Period set(@Nullable Object id, @Nullable Object uid, int windowIndex, long durationUs, long positionInWindowUs)
id
- An identifier for the period. Not necessarily unique. May be null if the ids of the
period are not required.uid
- A unique identifier for the period. May be null if the ids of the period are not
required.windowIndex
- The index of the window to which this period belongs.durationUs
- The duration of this period in microseconds, or C.TIME_UNSET
if
unknown.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.public Timeline.Period set(@Nullable Object id, @Nullable Object uid, int windowIndex, long durationUs, long positionInWindowUs, AdPlaybackState adPlaybackState)
id
- An identifier for the period. Not necessarily unique. May be null if the ids of the
period are not required.uid
- A unique identifier for the period. May be null if the ids of the period are not
required.windowIndex
- The index of the window to which this period belongs.durationUs
- The duration of this period in microseconds, or C.TIME_UNSET
if
unknown.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
- The state of the period's ads, or AdPlaybackState.NONE
if
there are no ads.public long getDurationMs()
C.TIME_UNSET
if unknown.public long getDurationUs()
C.TIME_UNSET
if unknown.public long getPositionInWindowMs()
public long getPositionInWindowUs()
@Nullable public Object getAdsId()
null
if unset.public int getAdGroupCount()
public long getAdGroupTimeUs(int adGroupIndex)
adGroupIndex
in the period, in
microseconds.adGroupIndex
- The ad group index.Timeline.Period
, in microseconds, or C.TIME_END_OF_SOURCE
for a post-roll ad group.public int getFirstAdIndexToPlay(int adGroupIndex)
adGroupIndex
- The ad group index.public int getNextAdIndexToPlay(int adGroupIndex, int lastPlayedAdIndex)
adIndexInAdGroup
, or the number of ads in the ad group if no later ads should
be played.adGroupIndex
- The ad group index.lastPlayedAdIndex
- The last played ad index in the ad group.public boolean hasPlayedAdGroup(int adGroupIndex)
adGroupIndex
has been played.adGroupIndex
- The ad group index.adGroupIndex
has been played.public int getAdGroupIndexForPositionUs(long positionUs)
positionUs
in the period, if that ad
group is unplayed. Returns C.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.positionUs
- The period position at or before which to find an ad group, in
microseconds.C.INDEX_UNSET
.public int getAdGroupIndexAfterPositionUs(long positionUs)
positionUs
in the period that has ads
remaining to be played. Returns C.INDEX_UNSET
if there is no such ad group.positionUs
- The period position after which to find an ad group, in microseconds.C.INDEX_UNSET
.public int getAdCountInAdGroup(int adGroupIndex)
adGroupIndex
, or
C.LENGTH_UNSET
if not yet known.adGroupIndex
- The ad group index.C.LENGTH_UNSET
if not yet known.public long getAdDurationUs(int adGroupIndex, int adIndexInAdGroup)
adIndexInAdGroup
in the ad group at
adGroupIndex
, in microseconds, or C.TIME_UNSET
if not yet known.adGroupIndex
- The ad group index.adIndexInAdGroup
- The ad index in the ad group.C.TIME_UNSET
if not yet known.public long getAdResumePositionUs()