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.Windowin 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>CREATORObject that can restoreTimeline.Periodfrom aBundle.longdurationUsThe duration of this period in microseconds, orC.TIME_UNSETif unknown.ObjectidAn identifier for the period.booleanisPlaceholderWhether this period contains placeholder information because the real information has yet to be loaded.longpositionInWindowUsThe position of the start of this period relative to the start of the window to which it belongs, in microseconds.ObjectuidA unique identifier for the period.intwindowIndexThe 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 booleanequals(Object obj)intgetAdCountInAdGroup(int adGroupIndex)Returns the number of ads in the ad group at indexadGroupIndex, orC.LENGTH_UNSETif not yet known.longgetAdDurationUs(int adGroupIndex, int adIndexInAdGroup)Returns the duration of the ad at indexadIndexInAdGroupin the ad group atadGroupIndex, in microseconds, orC.TIME_UNSETif not yet known.intgetAdGroupCount()Returns the number of ad groups in the period.intgetAdGroupIndexAfterPositionUs(long positionUs)Returns the index of the next ad group afterpositionUsin the period that has ads that should be played.intgetAdGroupIndexForPositionUs(long positionUs)Returns the index of the ad group at or beforepositionUsin the period that should be played before the content atpositionUs.longgetAdGroupTimeUs(int adGroupIndex)Returns the time of the ad group at indexadGroupIndexin the period, in microseconds.longgetAdResumePositionUs()Returns the position offset in the first unplayed ad at which to begin playback, in microseconds.ObjectgetAdsId()Returns the opaque identifier for ads played with this period, ornullif unset.longgetDurationMs()Returns the duration of the period in milliseconds, orC.TIME_UNSETif unknown.longgetDurationUs()Returns the duration of this period in microseconds, orC.TIME_UNSETif unknown.intgetFirstAdIndexToPlay(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.intgetNextAdIndexToPlay(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.longgetPositionInWindowMs()Returns the position of the start of this period relative to the start of the window to which it belongs, in milliseconds.longgetPositionInWindowUs()Returns the position of the start of this period relative to the start of the window to which it belongs, in microseconds.inthashCode()booleanhasPlayedAdGroup(int adGroupIndex)Returns whether the ad group at indexadGroupIndexhas been played.Timeline.Periodset(Object id, Object uid, int windowIndex, long durationUs, long positionInWindowUs)Sets the data held by this period.Timeline.Periodset(Object id, Object uid, int windowIndex, long durationUs, long positionInWindowUs, AdPlaybackState adPlaybackState, boolean isPlaceholder)Sets the data held by this period.BundletoBundle()Returns aBundlerepresenting 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_UNSETif 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.Periodfrom 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_UNSETif 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_UNSETif 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.NONEif 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_UNSETif unknown.
-
getDurationUs
public long getDurationUs()
Returns the duration of this period in microseconds, orC.TIME_UNSETif 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, ornullif unset.
-
getAdGroupCount
public int getAdGroupCount()
Returns the number of ad groups in the period.
-
getAdGroupTimeUs
public long getAdGroupTimeUs(int adGroupIndex)
Returns the time of the ad group at indexadGroupIndexin 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_SOURCEfor 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 the ad group at indexadGroupIndexhas been played.- Parameters:
adGroupIndex- The ad group index.- Returns:
- Whether the ad group at index
adGroupIndexhas been played.
-
getAdGroupIndexForPositionUs
public int getAdGroupIndexForPositionUs(long positionUs)
Returns the index of the ad group at or beforepositionUsin the period that should be played before the content atpositionUs. ReturnsC.INDEX_UNSETif the ad group at or beforepositionUshas 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 afterpositionUsin the period that has ads that should be played. ReturnsC.INDEX_UNSETif 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_UNSETif not yet known.- Parameters:
adGroupIndex- The ad group index.- Returns:
- The number of ads in the ad group, or
C.LENGTH_UNSETif not yet known.
-
getAdDurationUs
public long getAdDurationUs(int adGroupIndex, int adIndexInAdGroup)Returns the duration of the ad at indexadIndexInAdGroupin the ad group atadGroupIndex, in microseconds, orC.TIME_UNSETif 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_UNSETif not yet known.
-
getAdResumePositionUs
public long getAdResumePositionUs()
Returns the position offset in the first unplayed ad at which to begin playback, in microseconds.
-
-