AdPlaybackState
@UnstableApi
public final class AdPlaybackState
Represents ad group times and information on the state and URIs of ads within each ad group.
Instances are immutable. Call the with* methods to get new instances that have the required changes.
Summary
Nested types |
|---|
public final class AdPlaybackState.AdGroupRepresents a group of ads, with information about their states. |
@DocumentedRepresents the state of an ad in an ad group. |
public final class AdPlaybackState.SkipInfoInformation about skipping an ad. |
Constants |
|
|---|---|
static final int |
State for an ad that has a URL but has not yet been played. |
static final int |
AD_STATE_ERROR = 4State for an ad that could not be loaded. |
static final int |
AD_STATE_PLAYED = 3State for an ad that was played in full. |
static final int |
AD_STATE_SKIPPED = 2State for an ad that was skipped. |
static final int |
State for an ad that does not yet have a URL. |
static final AdPlaybackState |
Ad playback state with no ads. |
Public fields |
|
|---|---|
final int |
The number of ad groups. |
final long |
The position offset in the first unplayed ad at which to begin playback, in microseconds. |
final @Nullable Object |
The opaque identifier for ads with which this instance is associated, or |
final long |
The duration of the content period in microseconds, if known. |
final int |
The number of ad groups that have been removed. |
Public constructors |
|---|
AdPlaybackState(Object adsId, long[] adGroupTimesUs)Creates a new ad playback state with the specified ad group times. |
Public methods |
|
|---|---|
AdPlaybackState |
copy()Returns an new instance that is a safe deep copy of this instance in case an immutable object is used for |
boolean |
Returns whether the last ad group is a live postroll placeholder as inserted by |
boolean |
endsWithLivePostrollPlaceHolder(boolean isServerSideInserted)Returns whether the last ad group is a live postroll placeholder as inserted by |
boolean |
|
static AdPlaybackState |
fromAdPlaybackState(Object adsId, AdPlaybackState adPlaybackState)Returns a copy of the ad playback state with the given ads ID. |
static AdPlaybackState |
fromBundle(Bundle bundle)Restores a |
AdPlaybackState.AdGroup |
getAdGroup(@IntRange(from = 0) int adGroupIndex)Returns the specified |
int |
getAdGroupIndexAfterPositionUs(long positionUs, long periodDurationUs)Returns the index of the next ad group after |
int |
getAdGroupIndexForPositionUs(long positionUs, long periodDurationUs)Returns the index of the ad group at or before |
int |
getAdIndexOfAdId(int adGroupIndex, String adId)Returns the index of the ad with the given ad ID in the given ad group, or |
int |
hashCode() |
boolean |
isAdInErrorState(Returns whether the specified ad has been marked as in |
boolean |
isLivePostrollPlaceholder(int adGroupIndex)Returns whether the |
boolean |
isLivePostrollPlaceholder(Returns whether the |
Bundle |
toBundle()Returns a |
String |
toString() |
AdPlaybackState |
withAdCount(Returns an instance with the number of ads in |
AdPlaybackState |
withAdDurationsUs(long[][] adDurationUs)Returns an instance with the specified ad durations, in microseconds. |
AdPlaybackState |
withAdDurationsUs(Returns an instance with the specified ad durations, in microseconds, in the specified ad group. |
AdPlaybackState |
withAdGroupTimeUs(@IntRange(from = 0) int adGroupIndex, long adGroupTimeUs)Returns an instance with the specified ad group time. |
AdPlaybackState |
withAdId(Returns an instance with the specified ad ID for the given ad. |
AdPlaybackState |
withAdLoadError(Returns an instance with the specified ad marked |
AdPlaybackState |
withAdResumePositionUs(long adResumePositionUs)Returns an instance with the specified ad resume position, in microseconds, relative to the start of the current ad. |
AdPlaybackState |
withAdSkipInfo(Returns an instance with the specified |
AdPlaybackState |
Returns an instance with the specified value for |
AdPlaybackState |
withAvailableAd(Returns an instance with the specified ad marked as |
AdPlaybackState |
withAvailableAdMediaItem(Returns an instance with the specified ad |
AdPlaybackState |
This method is deprecated. Use |
AdPlaybackState |
withContentDurationUs(long contentDurationUs)Returns an instance with the specified content duration, in microseconds. |
AdPlaybackState |
withContentResumeOffsetUs(Returns an instance with the specified |
AdPlaybackState |
withIsServerSideInserted(Returns an instance with the specified value for |
AdPlaybackState |
withLastAdRemoved(@IntRange(from = 0) int adGroupIndex)Returns an instance with the last ad of the given ad group removed. |
AdPlaybackState |
@InlineMe(replacement = "this.withLivePostrollPlaceholderAppended(true)")This method is deprecated. Use |
AdPlaybackState |
withLivePostrollPlaceholderAppended(boolean isServerSideInserted)Appends a live postroll placeholder ad group to the ad playback state. |
AdPlaybackState |
withNewAdGroup(@IntRange(from = 0) int adGroupIndex, long adGroupTimeUs)Returns an instance with a new ad group. |
AdPlaybackState |
withOriginalAdCount(Returns an instance with the specified value for |
AdPlaybackState |
withPlayedAd(Returns an instance with the specified ad marked as |
AdPlaybackState |
withRemovedAdGroupCount(@IntRange(from = 0) int removedAdGroupCount)Returns an instance with the specified number of |
AdPlaybackState |
withRemovedAdGroupCountBefore(long timeUs)Returns an instance with ad groups removed until and excluding the first post roll ad group or the first ad group with |
AdPlaybackState |
withResetAdGroup(@IntRange(from = 0) int adGroupIndex)Returns an instance with all ads in the specified ad group reset from final states (played, skipped, error) to either available or unavailable, which allows to play them again. |
AdPlaybackState |
withSkippedAd(Returns an instance with the specified ad marked as |
AdPlaybackState |
withSkippedAdGroup(@IntRange(from = 0) int adGroupIndex)Returns an instance with all ads in the specified ad group skipped (except for those already marked as played or in the error state). |
Constants
AD_STATE_AVAILABLE
public static final int AD_STATE_AVAILABLE = 1
State for an ad that has a URL but has not yet been played.
AD_STATE_PLAYED
public static final int AD_STATE_PLAYED = 3
State for an ad that was played in full.
AD_STATE_UNAVAILABLE
public static final int AD_STATE_UNAVAILABLE = 0
State for an ad that does not yet have a URL.
Public fields
adResumePositionUs
public final long adResumePositionUs
The position offset in the first unplayed ad at which to begin playback, in microseconds.
adsId
public final @Nullable Object adsId
The opaque identifier for ads with which this instance is associated, or null if unset.
contentDurationUs
public final long contentDurationUs
The duration of the content period in microseconds, if known. TIME_UNSET otherwise.
removedAdGroupCount
public final int removedAdGroupCount
The number of ad groups that have been removed. Ad groups with indices between 0 (inclusive) and removedAdGroupCount (exclusive) will be empty and must not be modified by any of the with* methods.
Public constructors
AdPlaybackState
public AdPlaybackState(Object adsId, long[] adGroupTimesUs)
Creates a new ad playback state with the specified ad group times.
| Parameters | |
|---|---|
Object adsId |
The opaque identifier for ads with which this instance is associated. |
long[] adGroupTimesUs |
The times of ad groups in microseconds, relative to the start of the |
Public methods
copy
public AdPlaybackState copy()
Returns an new instance that is a safe deep copy of this instance in case an immutable object is used for adsId.
endsWithLivePostrollPlaceHolder
public boolean endsWithLivePostrollPlaceHolder()
Returns whether the last ad group is a live postroll placeholder as inserted by withLivePostrollPlaceholderAppended.
Note: That either server-side or client-side inserted placeholders are considered. Use endsWithLivePostrollPlaceHolder if you want to test for one or the other only.
| Returns | |
|---|---|
boolean |
Whether the ad playback state ends with a live postroll placeholder. |
endsWithLivePostrollPlaceHolder
public boolean endsWithLivePostrollPlaceHolder(boolean isServerSideInserted)
Returns whether the last ad group is a live postroll placeholder as inserted by withLivePostrollPlaceholderAppended .
| Parameters | |
|---|---|
boolean isServerSideInserted |
Whether the trailing placeholder is server-side inserted. |
| Returns | |
|---|---|
boolean |
Whether the ad playback state ends with a live postroll placeholder. |
fromAdPlaybackState
public static AdPlaybackState fromAdPlaybackState(Object adsId, AdPlaybackState adPlaybackState)
Returns a copy of the ad playback state with the given ads ID.
| Parameters | |
|---|---|
Object adsId |
The new ads ID. |
AdPlaybackState adPlaybackState |
The ad playback state to copy. |
| Returns | |
|---|---|
AdPlaybackState |
The new ad playback state. |
fromBundle
public static AdPlaybackState fromBundle(Bundle bundle)
Restores a AdPlaybackState from a Bundle.
getAdGroup
public AdPlaybackState.AdGroup getAdGroup(@IntRange(from = 0) int adGroupIndex)
Returns the specified AdGroup.
getAdGroupIndexAfterPositionUs
public int getAdGroupIndexAfterPositionUs(long positionUs, long periodDurationUs)
Returns the index of the next ad group after positionUs 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, or |
long periodDurationUs |
The duration of the containing timeline period, in microseconds, or |
| Returns | |
|---|---|
int |
The index of the ad group, or |
getAdGroupIndexForPositionUs
public int getAdGroupIndexForPositionUs(long positionUs, long periodDurationUs)
Returns the index of the ad group at or before positionUs 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, or |
long periodDurationUs |
The duration of the containing timeline period, in microseconds, or |
| Returns | |
|---|---|
int |
The index of the ad group, or |
getAdIndexOfAdId
public int getAdIndexOfAdId(int adGroupIndex, String adId)
Returns the index of the ad with the given ad ID in the given ad group, or INDEX_UNSET if the ad ID can't be found.
| Parameters | |
|---|---|
int adGroupIndex |
The ad group index. |
String adId |
The ad ID. |
| Returns | |
|---|---|
int |
The ad index in the ad group, or |
isAdInErrorState
public boolean isAdInErrorState(
@IntRange(from = 0) int adGroupIndex,
@IntRange(from = 0) int adIndexInAdGroup
)
Returns whether the specified ad has been marked as in AD_STATE_ERROR.
isLivePostrollPlaceholder
public boolean isLivePostrollPlaceholder(int adGroupIndex)
Returns whether the AdGroup at the given ad group index is a live postroll placeholder.
Note: That either server-side or client-side inserted placeholders return true. Use isLivePostrollPlaceholder if you want to test for one or the other only.
| Parameters | |
|---|---|
int adGroupIndex |
The ad group index. |
| Returns | |
|---|---|
boolean |
True if the ad group at the given index is a live postroll placeholder, false if not. |
isLivePostrollPlaceholder
public boolean isLivePostrollPlaceholder(
int adGroupIndex,
boolean isServerSideInserted
)
Returns whether the AdGroup at the given ad group index is a live postroll placeholder and either server or client-side inserted.
| Parameters | |
|---|---|
int adGroupIndex |
The ad group index. |
boolean isServerSideInserted |
Whether the placeholder is server-side inserted. |
| Returns | |
|---|---|
boolean |
True if the ad group at the given index is a live postroll placeholder, false if not. |
toBundle
public Bundle toBundle()
Returns a Bundle representing the information stored in this object.
It omits the adsId field so the adsId of instances restored by fromBundle will always be null.
withAdCount
public AdPlaybackState withAdCount(
@IntRange(from = 0) int adGroupIndex,
@IntRange(from = 1) int adCount
)
Returns an instance with the number of ads in adGroupIndex resolved to adCount. The ad count must be greater than zero.
withAdDurationsUs
public AdPlaybackState withAdDurationsUs(long[][] adDurationUs)
Returns an instance with the specified ad durations, in microseconds.
The number of arrays of durations (adDurations.length) must always be equal to adGroupCount. This is required even on an instance created with withRemovedAdGroupCount. The array of durations at the index of a removed ad group can be null or empty.
| Throws | |
|---|---|
java.lang.IllegalArgumentException |
if |
withAdDurationsUs
public AdPlaybackState withAdDurationsUs(
@IntRange(from = 0) int adGroupIndex,
long[] adDurationsUs
)
Returns an instance with the specified ad durations, in microseconds, in the specified ad group.
withAdGroupTimeUs
public AdPlaybackState withAdGroupTimeUs(@IntRange(from = 0) int adGroupIndex, long adGroupTimeUs)
Returns an instance with the specified ad group time.
| Parameters | |
|---|---|
@IntRange(from = 0) int adGroupIndex |
The index of the ad group. |
long adGroupTimeUs |
The new ad group time, in microseconds, or |
| Returns | |
|---|---|
AdPlaybackState |
The updated ad playback state. |
withAdId
public AdPlaybackState withAdId(
@IntRange(from = 0) int adGroupIndex,
@IntRange(from = 0) int adIndexInAdGroup,
String adId
)
Returns an instance with the specified ad ID for the given ad.
withAdLoadError
public AdPlaybackState withAdLoadError(
@IntRange(from = 0) int adGroupIndex,
@IntRange(from = 0) int adIndexInAdGroup
)
Returns an instance with the specified ad marked as having a load error.
withAdResumePositionUs
public AdPlaybackState withAdResumePositionUs(long adResumePositionUs)
Returns an instance with the specified ad resume position, in microseconds, relative to the start of the current ad.
withAdSkipInfo
public AdPlaybackState withAdSkipInfo(
@IntRange(from = 0) int adGroupIndex,
@IntRange(from = 0) int adIndexInAdGroup,
AdPlaybackState.SkipInfo skipInfo
)
Returns an instance with the specified SkipInfo for the given ad.
withAdsId
public AdPlaybackState withAdsId(Object adsId)
Returns an instance with the specified value for adsId.
withAvailableAd
public AdPlaybackState withAvailableAd(
@IntRange(from = 0) int adGroupIndex,
@IntRange(from = 0) int adIndexInAdGroup
)
Returns an instance with the specified ad marked as available.
Must not be called with client-side inserted ad groups. Client-side inserted ads should use withAvailableAdMediaItem.
| Throws | |
|---|---|
java.lang.IllegalStateException |
in case this methods is called on an ad group that |
withAvailableAdMediaItem
public AdPlaybackState withAvailableAdMediaItem(
@IntRange(from = 0) int adGroupIndex,
@IntRange(from = 0) int adIndexInAdGroup,
MediaItem mediaItem
)
Returns an instance with the specified ad MediaItem and the ad marked as available.
| Throws | |
|---|---|
java.lang.IllegalStateException |
If a |
withAvailableAdUri
public AdPlaybackStatewithAvailableAdUri(
@IntRange(from = 0) int adGroupIndex,
@IntRange(from = 0) int adIndexInAdGroup,
Uri uri
)
withContentDurationUs
public AdPlaybackState withContentDurationUs(long contentDurationUs)
Returns an instance with the specified content duration, in microseconds.
withContentResumeOffsetUs
public AdPlaybackState withContentResumeOffsetUs(
@IntRange(from = 0) int adGroupIndex,
long contentResumeOffsetUs
)
Returns an instance with the specified contentResumeOffsetUs, in microseconds, for the specified ad group.
withIsServerSideInserted
public AdPlaybackState withIsServerSideInserted(
@IntRange(from = 0) int adGroupIndex,
boolean isServerSideInserted
)
Returns an instance with the specified value for isServerSideInserted in the specified ad group.
withLastAdRemoved
public AdPlaybackState withLastAdRemoved(@IntRange(from = 0) int adGroupIndex)
Returns an instance with the last ad of the given ad group removed.
withLivePostrollPlaceholderAppended
@InlineMe(replacement = "this.withLivePostrollPlaceholderAppended(true)")
public AdPlaybackStatewithLivePostrollPlaceholderAppended()
withLivePostrollPlaceholderAppended
public AdPlaybackState withLivePostrollPlaceholderAppended(boolean isServerSideInserted)
Appends a live postroll placeholder ad group to the ad playback state.
Adding such a placeholder is only required for periods of live streams. A player is not expected to play this placeholder. It is only used to indicate that another ad group with this ad group index will be inserted in the future.
See endsWithLivePostrollPlaceHolder and endsWithLivePostrollPlaceHolder also.
| Parameters | |
|---|---|
boolean isServerSideInserted |
Whether this is a server-side inserted ad (single stream). |
| Returns | |
|---|---|
AdPlaybackState |
The new ad playback state instance ending with a live postroll placeholder. |
withNewAdGroup
public AdPlaybackState withNewAdGroup(@IntRange(from = 0) int adGroupIndex, long adGroupTimeUs)
Returns an instance with a new ad group.
| Parameters | |
|---|---|
@IntRange(from = 0) int adGroupIndex |
The insertion index of the new group. |
long adGroupTimeUs |
The ad group time, in microseconds, or |
| Returns | |
|---|---|
AdPlaybackState |
The updated ad playback state. |
withOriginalAdCount
public AdPlaybackState withOriginalAdCount(
@IntRange(from = 0) int adGroupIndex,
int originalAdCount
)
Returns an instance with the specified value for originalCount in the specified ad group.
withPlayedAd
public AdPlaybackState withPlayedAd(
@IntRange(from = 0) int adGroupIndex,
@IntRange(from = 0) int adIndexInAdGroup
)
Returns an instance with the specified ad marked as played.
withRemovedAdGroupCount
public AdPlaybackState withRemovedAdGroupCount(@IntRange(from = 0) int removedAdGroupCount)
Returns an instance with the specified number of removed ad groups.
Ad groups with indices between 0 (inclusive) and removedAdGroupCount (exclusive) will be empty and must not be modified by any of the with* methods.
withRemovedAdGroupCountBefore
public AdPlaybackState withRemovedAdGroupCountBefore(long timeUs)
Returns an instance with ad groups removed until and excluding the first post roll ad group or the first ad group with timeUs larger than the given time, in microseconds.
Any ad group with timeUs set to TIME_END_OF_SOURCE is considered a post roll ad group.
withResetAdGroup
public AdPlaybackState withResetAdGroup(@IntRange(from = 0) int adGroupIndex)
Returns an instance with all ads in the specified ad group reset from final states (played, skipped, error) to either available or unavailable, which allows to play them again.
withSkippedAd
public AdPlaybackState withSkippedAd(
@IntRange(from = 0) int adGroupIndex,
@IntRange(from = 0) int adIndexInAdGroup
)
Returns an instance with the specified ad marked as skipped.
withSkippedAdGroup
public AdPlaybackState withSkippedAdGroup(@IntRange(from = 0) int adGroupIndex)
Returns an instance with all ads in the specified ad group skipped (except for those already marked as played or in the error state).