public final class

Timeline.Period

extends java.lang.Object

 java.lang.Object

↳androidx.media3.common.Timeline.Period

Overview

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 Timeline.Window in the timeline.

Information defined by a period

Summary

Fields
public AdPlaybackStateadPlaybackState

The AdPlaybackState for all ads in this period.

public longdurationUs

The duration of this period in microseconds, or C.TIME_UNSET if unknown.

public java.lang.Objectid

An identifier for the period.

public booleanisPlaceholder

Whether this period contains placeholder information because the real information has yet to be loaded.

public longpositionInWindowUs

The position of the start of this period relative to the start of the window to which it belongs, in microseconds.

public java.lang.Objectuid

A unique identifier for the period.

public intwindowIndex

The index of the window to which this period belongs.

Constructors
publicPeriod()

Creates a new instance with no ad playback state.

Methods
public booleanequals(java.lang.Object obj)

public static Timeline.PeriodfromBundle(Bundle bundle)

Restores a Period from a .

public intgetAdCountInAdGroup(int adGroupIndex)

Returns the number of ads in the ad group at index adGroupIndex, or C.LENGTH_UNSET if not yet known.

public longgetAdDurationUs(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.

public intgetAdGroupCount()

Returns the number of ad groups in the period.

public intgetAdGroupIndexAfterPositionUs(long positionUs)

Returns the index of the next ad group after positionUs in the period that has ads that should be played.

public intgetAdGroupIndexForPositionUs(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.

public longgetAdGroupTimeUs(int adGroupIndex)

Returns the time of the ad group at index adGroupIndex in the period, in microseconds.

public longgetAdResumePositionUs()

Returns the position offset in the first unplayed ad at which to begin playback, in microseconds.

public java.lang.ObjectgetAdsId()

Returns the opaque identifier for ads played with this period, or null if unset.

public intgetAdState(int adGroupIndex, int adIndexInAdGroup)

Returns the state of the ad at index adIndexInAdGroup in the ad group at adGroupIndex, or AdPlaybackState.AD_STATE_UNAVAILABLE if not yet known.

public longgetContentResumeOffsetUs(int adGroupIndex)

Returns the offset in microseconds which should be added to the content stream when resuming playback after the specified ad group.

public longgetDurationMs()

Returns the duration of the period in milliseconds, or C.TIME_UNSET if unknown.

public longgetDurationUs()

Returns the duration of this period in microseconds, or C.TIME_UNSET if unknown.

public 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.

public intgetNextAdIndexToPlay(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.

public longgetPositionInWindowMs()

Returns the position of the start of this period relative to the start of the window to which it belongs, in milliseconds.

public longgetPositionInWindowUs()

Returns the position of the start of this period relative to the start of the window to which it belongs, in microseconds.

public intgetRemovedAdGroupCount()

Returns the number of removed ad groups in the period.

public inthashCode()

public booleanhasPlayedAdGroup(int adGroupIndex)

Returns whether all ads in the ad group at index adGroupIndex have been played, skipped or failed.

public booleanisLivePostrollPlaceholder(int adGroupIndex)

Returns whether the ad group at the given ad group index is a live postroll placeholder.

public booleanisServerSideInsertedAdGroup(int adGroupIndex)

Returns whether the ad group at index adGroupIndex is server-side inserted and part of the content stream.

public Timeline.Periodset(java.lang.Object id, java.lang.Object uid, int windowIndex, long durationUs, long positionInWindowUs)

Sets the data held by this period.

public Timeline.Periodset(java.lang.Object id, java.lang.Object uid, int windowIndex, long durationUs, long positionInWindowUs, AdPlaybackState adPlaybackState, boolean isPlaceholder)

Sets the data held by this period.

public BundletoBundle()

Returns a representing the information stored in this object.

from java.lang.Objectclone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait

Fields

public java.lang.Object id

An identifier for the period. Not necessarily unique. May be null if the ids of the period are not required.

public java.lang.Object uid

A unique identifier for the period. May be null if the ids of the period are not required.

public int windowIndex

The index of the window to which this period belongs.

public long durationUs

The duration of this period in microseconds, or C.TIME_UNSET if unknown.

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 boolean isPlaceholder

Whether this period contains placeholder information because the real information has yet to be loaded.

public AdPlaybackState adPlaybackState

The AdPlaybackState for all ads in this period.

Constructors

public Period()

Creates a new instance with no ad playback state.

Methods

public Timeline.Period set(java.lang.Object id, java.lang.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, 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.

Returns:

This period, for convenience.

public Timeline.Period set(java.lang.Object id, java.lang.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, 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.
isPlaceholder: Whether this period contains placeholder information because the real information has yet to be loaded.

Returns:

This period, for convenience.

public long getDurationMs()

Returns the duration of the period in milliseconds, or C.TIME_UNSET if unknown.

public long getDurationUs()

Returns the duration of this period in microseconds, or C.TIME_UNSET if unknown.

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.

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.

public java.lang.Object getAdsId()

Returns the opaque identifier for ads played with this period, or null if unset.

public int getAdGroupCount()

Returns the number of ad groups in the period.

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.

public long getAdGroupTimeUs(int adGroupIndex)

Returns the time of the ad group at index adGroupIndex 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, or C.TIME_END_OF_SOURCE for a post-roll ad group.

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.

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:

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.

public boolean hasPlayedAdGroup(int adGroupIndex)

Returns whether all ads in the ad group at index adGroupIndex 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.

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 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.

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.

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 C.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.

public int getAdCountInAdGroup(int adGroupIndex)

Returns the number of ads in the ad group at index adGroupIndex, or C.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.

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 C.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.

public int getAdState(int adGroupIndex, int adIndexInAdGroup)

Returns the state of the ad at index adIndexInAdGroup in the ad group at adGroupIndex, or AdPlaybackState.AD_STATE_UNAVAILABLE if not yet known.

Parameters:

adGroupIndex: The ad group index.
adIndexInAdGroup: The index of the ad in the ad group.

Returns:

The state of the ad, or AdPlaybackState.AD_STATE_UNAVAILABLE if not yet known.

public boolean isLivePostrollPlaceholder(int adGroupIndex)

Returns whether the ad group at the given ad group index is a live postroll placeholder.

Parameters:

adGroupIndex: The ad group index.

Returns:

True if the ad group at the given index is a live postroll placeholder.

public long getAdResumePositionUs()

Returns the position offset in the first unplayed ad at which to begin playback, in microseconds.

public boolean isServerSideInsertedAdGroup(int adGroupIndex)

Returns whether the ad group at index adGroupIndex 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.

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.

public boolean equals(java.lang.Object obj)

public int hashCode()

public Bundle toBundle()

Returns a representing the information stored in this object.

It omits the Timeline.Period.id and Timeline.Period.uid fields so these fields of an instance restored by Timeline.Period.fromBundle(Bundle) will always be null.

public static Timeline.Period fromBundle(Bundle bundle)

Restores a Period from a .