Package com.google.android.exoplayer2
Class Timeline.Period
- java.lang.Object
-
- com.google.android.exoplayer2.Timeline.Period
-
- All Implemented Interfaces:
Bundleable
- Enclosing class:
- Timeline
public static final class Timeline.Period extends Object implements Bundleable
Holds information about a period in aTimeline
. 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.
-
-
Nested Class Summary
-
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.Period>
CREATOR
Object that can restoreTimeline.Period
from aBundle
.long
durationUs
The duration of this period in microseconds, orC.TIME_UNSET
if unknown.Object
id
An identifier for the period.boolean
isPlaceholder
Whether this period contains placeholder information because the real information has yet to be loaded.long
positionInWindowUs
The position of the start of this period relative to the start of the window to which it belongs, in microseconds.Object
uid
A unique identifier for the period.int
windowIndex
The index of the window to which this period belongs.
-
Constructor Summary
Constructors Constructor Description Period()
Creates a new instance with no ad playback state.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object obj)
int
getAdCountInAdGroup(int adGroupIndex)
Returns the number of ads in the ad group at indexadGroupIndex
, orC.LENGTH_UNSET
if not yet known.long
getAdDurationUs(int adGroupIndex, int adIndexInAdGroup)
Returns the duration of the ad at indexadIndexInAdGroup
in the ad group atadGroupIndex
, in microseconds, orC.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 afterpositionUs
in the period that has ads that should be played.int
getAdGroupIndexForPositionUs(long positionUs)
Returns the index of the ad group at or beforepositionUs
in the period that should be played before the content atpositionUs
.long
getAdGroupTimeUs(int adGroupIndex)
Returns the time of the ad group at indexadGroupIndex
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, ornull
if unset.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.long
getDurationMs()
Returns the duration of the period in milliseconds, orC.TIME_UNSET
if unknown.long
getDurationUs()
Returns the duration of this period in microseconds, orC.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 playingadIndexInAdGroup
, 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
getRemovedAdGroupCount()
Returns the number of removed ad groups in the period.int
hashCode()
boolean
hasPlayedAdGroup(int adGroupIndex)
Returns whether all ads in the ad group at indexadGroupIndex
have been played, skipped or failed.boolean
isServerSideInsertedAdGroup(int adGroupIndex)
Returns whether the ad group at indexadGroupIndex
is server-side inserted and part of the content stream.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, boolean isPlaceholder)
Sets the data held by this period.Bundle
toBundle()
Returns aBundle
representing the information stored in this object.
-
-
-
Field Detail
-
id
@Nullable public Object id
An identifier for the period. Not necessarily unique. May be null if the ids of the period are not required.
-
uid
@Nullable public Object uid
A unique identifier for the period. May be null if the ids of the period are not required.
-
windowIndex
public int windowIndex
The index of the window to which this period belongs.
-
durationUs
public long durationUs
The duration of this period in microseconds, orC.TIME_UNSET
if unknown.
-
positionInWindowUs
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.
-
isPlaceholder
public boolean isPlaceholder
Whether this period contains placeholder information because the real information has yet to be loaded.
-
CREATOR
public static final Bundleable.Creator<Timeline.Period> CREATOR
Object that can restoreTimeline.Period
from aBundle
.
-
-
Method Detail
-
set
public Timeline.Period set(@Nullable Object id, @Nullable Object uid, int windowIndex, long durationUs, long positionInWindowUs)
Sets the data held by this period.- Parameters:
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, orC.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.- Returns:
- This period, for convenience.
-
set
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:
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, orC.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, orAdPlaybackState.NONE
if there are no ads.isPlaceholder
- Whether this period contains placeholder information because the real information has yet to be loaded.- Returns:
- This period, for convenience.
-
getDurationMs
public long getDurationMs()
Returns the duration of the period in milliseconds, orC.TIME_UNSET
if unknown.
-
getDurationUs
public long getDurationUs()
Returns the duration of this period in microseconds, orC.TIME_UNSET
if unknown.
-
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.
-
getAdsId
@Nullable public Object getAdsId()
Returns the opaque identifier for ads played with this period, ornull
if unset.
-
getAdGroupCount
public int getAdGroupCount()
Returns the number of ad groups in the period.
-
getRemovedAdGroupCount
public int getRemovedAdGroupCount()
Returns the number of removed ad groups in the period. Ad groups with indices between0
(inclusive) andremovedAdGroupCount
(exclusive) will be empty.
-
getAdGroupTimeUs
public long getAdGroupTimeUs(int adGroupIndex)
Returns the time of the ad group at indexadGroupIndex
in the period, in microseconds.- Parameters:
adGroupIndex
- The ad group index.- Returns:
- The time of the ad group at the index relative to the start of the enclosing
Timeline.Period
, in microseconds, orC.TIME_END_OF_SOURCE
for a post-roll ad group.
-
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:
adGroupIndex
- The ad group index.- Returns:
- 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 playingadIndexInAdGroup
, or the number of ads in the ad group if no later ads should be played.- Parameters:
adGroupIndex
- The ad group index.lastPlayedAdIndex
- The last played ad index in the ad group.- Returns:
- 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.
-
hasPlayedAdGroup
public boolean hasPlayedAdGroup(int adGroupIndex)
Returns whether all ads in the ad group at indexadGroupIndex
have been played, skipped or failed.- Parameters:
adGroupIndex
- The ad group index.- Returns:
- Whether all ads in the ad group at index
adGroupIndex
have been played, skipped or failed.
-
getAdGroupIndexForPositionUs
public int getAdGroupIndexForPositionUs(long positionUs)
Returns the index of the ad group at or beforepositionUs
in the period that should be played before the content atpositionUs
. ReturnsC.INDEX_UNSET
if the ad group at or beforepositionUs
has no ads remaining to be played, or if there is no such ad group.- Parameters:
positionUs
- The period position at or before which to find an ad group, in microseconds.- Returns:
- The index of the ad group, or
C.INDEX_UNSET
.
-
getAdGroupIndexAfterPositionUs
public int getAdGroupIndexAfterPositionUs(long positionUs)
Returns the index of the next ad group afterpositionUs
in the period that has ads that should be played. ReturnsC.INDEX_UNSET
if there is no such ad group.- Parameters:
positionUs
- The period position after which to find an ad group, in microseconds.- Returns:
- The index of the ad group, or
C.INDEX_UNSET
.
-
getAdCountInAdGroup
public int getAdCountInAdGroup(int adGroupIndex)
Returns the number of ads in the ad group at indexadGroupIndex
, orC.LENGTH_UNSET
if not yet known.- Parameters:
adGroupIndex
- The ad group index.- Returns:
- The number of ads in the ad group, or
C.LENGTH_UNSET
if not yet known.
-
getAdDurationUs
public long getAdDurationUs(int adGroupIndex, int adIndexInAdGroup)
Returns the duration of the ad at indexadIndexInAdGroup
in the ad group atadGroupIndex
, in microseconds, orC.TIME_UNSET
if not yet known.- Parameters:
adGroupIndex
- The ad group index.adIndexInAdGroup
- The ad index in the ad group.- Returns:
- The duration of the ad, or
C.TIME_UNSET
if not yet known.
-
getAdResumePositionUs
public long getAdResumePositionUs()
Returns the position offset in the first unplayed ad at which to begin playback, in microseconds.
-
isServerSideInsertedAdGroup
public boolean isServerSideInsertedAdGroup(int adGroupIndex)
Returns whether the ad group at indexadGroupIndex
is server-side inserted and part of the content stream.- Parameters:
adGroupIndex
- The ad group index.- Returns:
- Whether this ad group is server-side inserted and part of the content stream.
-
getContentResumeOffsetUs
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:
adGroupIndex
- The ad group index.- Returns:
- The offset that should be added to the content stream, in microseconds.
-
-