AdPlaybackState
@UnstableApi
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 |
|---|
class AdPlaybackState.AdGroupRepresents a group of ads, with information about their states. |
@DocumentedRepresents the state of an ad in an ad group. |
class AdPlaybackState.SkipInfoInformation about skipping an ad. |
Constants |
|
|---|---|
const Int |
State for an ad that has a URL but has not yet been played. |
const Int |
AD_STATE_ERROR = 4State for an ad that could not be loaded. |
const Int |
AD_STATE_PLAYED = 3State for an ad that was played in full. |
const Int |
AD_STATE_SKIPPED = 2State for an ad that was skipped. |
const Int |
State for an ad that does not yet have a URL. |
const AdPlaybackState! |
Ad playback state with no ads. |
Public constructors |
|---|
AdPlaybackState(adsId: Any!, adGroupTimesUs: LongArray!)Creates a new ad playback state with the specified ad group times. |
Public functions |
|
|---|---|
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(isServerSideInserted: Boolean)Returns whether the last ad group is a live postroll placeholder as inserted by |
Boolean |
|
java-static AdPlaybackState! |
fromAdPlaybackState(adsId: Any!, adPlaybackState: AdPlaybackState!)Returns a copy of the ad playback state with the given ads ID. |
java-static AdPlaybackState! |
fromBundle(bundle: Bundle!)Restores a |
AdPlaybackState.AdGroup! |
getAdGroup(adGroupIndex: @IntRange(from = 0) Int)Returns the specified |
Int |
getAdGroupIndexAfterPositionUs(positionUs: Long, periodDurationUs: Long)Returns the index of the next ad group after |
Int |
getAdGroupIndexForPositionUs(positionUs: Long, periodDurationUs: Long)Returns the index of the ad group at or before |
Int |
getAdIndexOfAdId(adGroupIndex: Int, adId: String!)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(adGroupIndex: Int)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(adDurationUs: Array<LongArray!>!)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(adGroupIndex: @IntRange(from = 0) Int, adGroupTimeUs: Long)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(adResumePositionUs: Long)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 function is deprecated. Use |
AdPlaybackState! |
withContentDurationUs(contentDurationUs: Long)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(adGroupIndex: @IntRange(from = 0) Int)Returns an instance with the last ad of the given ad group removed. |
AdPlaybackState! |
@InlineMe(replacement = "this.withLivePostrollPlaceholderAppended(true)")This function is deprecated. Use |
AdPlaybackState! |
withLivePostrollPlaceholderAppended(isServerSideInserted: Boolean)Appends a live postroll placeholder ad group to the ad playback state. |
AdPlaybackState! |
withNewAdGroup(adGroupIndex: @IntRange(from = 0) Int, adGroupTimeUs: Long)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(removedAdGroupCount: @IntRange(from = 0) Int)Returns an instance with the specified number of |
AdPlaybackState! |
withRemovedAdGroupCountBefore(timeUs: Long)Returns an instance with ad groups removed until and excluding the first post roll ad group or the first ad group with |
AdPlaybackState! |
withResetAdGroup(adGroupIndex: @IntRange(from = 0) Int)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(adGroupIndex: @IntRange(from = 0) Int)Returns an instance with all ads in the specified ad group skipped (except for those already marked as played or in the error state). |
Public properties |
|
|---|---|
Int |
The number of ad groups. |
Long |
The position offset in the first unplayed ad at which to begin playback, in microseconds. |
Any? |
The opaque identifier for ads with which this instance is associated, or |
Long |
The duration of the content period in microseconds, if known. |
Int |
The number of ad groups that have been removed. |
Constants
AD_STATE_AVAILABLE
const val AD_STATE_AVAILABLE = 1: Int
State for an ad that has a URL but has not yet been played.
AD_STATE_UNAVAILABLE
const val AD_STATE_UNAVAILABLE = 0: Int
State for an ad that does not yet have a URL.
Public constructors
AdPlaybackState
AdPlaybackState(adsId: Any!, adGroupTimesUs: LongArray!)
Creates a new ad playback state with the specified ad group times.
| Parameters | |
|---|---|
adsId: Any! |
The opaque identifier for ads with which this instance is associated. |
adGroupTimesUs: LongArray! |
The times of ad groups in microseconds, relative to the start of the |
Public functions
copy
fun copy(): AdPlaybackState!
Returns an new instance that is a safe deep copy of this instance in case an immutable object is used for adsId.
endsWithLivePostrollPlaceHolder
fun endsWithLivePostrollPlaceHolder(): Boolean
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
fun endsWithLivePostrollPlaceHolder(isServerSideInserted: Boolean): Boolean
Returns whether the last ad group is a live postroll placeholder as inserted by withLivePostrollPlaceholderAppended .
| Parameters | |
|---|---|
isServerSideInserted: Boolean |
Whether the trailing placeholder is server-side inserted. |
| Returns | |
|---|---|
Boolean |
Whether the ad playback state ends with a live postroll placeholder. |
fromAdPlaybackState
java-static fun fromAdPlaybackState(adsId: Any!, adPlaybackState: AdPlaybackState!): AdPlaybackState!
Returns a copy of the ad playback state with the given ads ID.
| Parameters | |
|---|---|
adsId: Any! |
The new ads ID. |
adPlaybackState: AdPlaybackState! |
The ad playback state to copy. |
| Returns | |
|---|---|
AdPlaybackState! |
The new ad playback state. |
fromBundle
java-static fun fromBundle(bundle: Bundle!): AdPlaybackState!
Restores a AdPlaybackState from a Bundle.
getAdGroup
fun getAdGroup(adGroupIndex: @IntRange(from = 0) Int): AdPlaybackState.AdGroup!
Returns the specified AdGroup.
getAdGroupIndexAfterPositionUs
fun getAdGroupIndexAfterPositionUs(positionUs: Long, periodDurationUs: Long): Int
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 | |
|---|---|
positionUs: Long |
The period position after which to find an ad group, in microseconds, or |
periodDurationUs: Long |
The duration of the containing timeline period, in microseconds, or |
| Returns | |
|---|---|
Int |
The index of the ad group, or |
getAdGroupIndexForPositionUs
fun getAdGroupIndexForPositionUs(positionUs: Long, periodDurationUs: Long): Int
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 | |
|---|---|
positionUs: Long |
The period position at or before which to find an ad group, in microseconds, or |
periodDurationUs: Long |
The duration of the containing timeline period, in microseconds, or |
| Returns | |
|---|---|
Int |
The index of the ad group, or |
getAdIndexOfAdId
fun getAdIndexOfAdId(adGroupIndex: Int, adId: String!): Int
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.
| Returns | |
|---|---|
Int |
The ad index in the ad group, or |
isAdInErrorState
fun isAdInErrorState(
adGroupIndex: @IntRange(from = 0) Int,
adIndexInAdGroup: @IntRange(from = 0) Int
): Boolean
Returns whether the specified ad has been marked as in AD_STATE_ERROR.
isLivePostrollPlaceholder
fun isLivePostrollPlaceholder(adGroupIndex: Int): Boolean
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 | |
|---|---|
adGroupIndex: Int |
The ad group index. |
| Returns | |
|---|---|
Boolean |
True if the ad group at the given index is a live postroll placeholder, false if not. |
isLivePostrollPlaceholder
fun isLivePostrollPlaceholder(
adGroupIndex: Int,
isServerSideInserted: Boolean
): Boolean
Returns whether the AdGroup at the given ad group index is a live postroll placeholder and either server or client-side inserted.
| Parameters | |
|---|---|
adGroupIndex: Int |
The ad group index. |
isServerSideInserted: Boolean |
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
fun toBundle(): Bundle!
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
fun withAdCount(
adGroupIndex: @IntRange(from = 0) Int,
adCount: @IntRange(from = 1) Int
): AdPlaybackState!
Returns an instance with the number of ads in adGroupIndex resolved to adCount. The ad count must be greater than zero.
withAdDurationsUs
fun withAdDurationsUs(adDurationUs: Array<LongArray!>!): AdPlaybackState!
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
fun withAdDurationsUs(
adGroupIndex: @IntRange(from = 0) Int,
adDurationsUs: LongArray!
): AdPlaybackState!
Returns an instance with the specified ad durations, in microseconds, in the specified ad group.
withAdGroupTimeUs
fun withAdGroupTimeUs(adGroupIndex: @IntRange(from = 0) Int, adGroupTimeUs: Long): AdPlaybackState!
Returns an instance with the specified ad group time.
| Parameters | |
|---|---|
adGroupIndex: @IntRange(from = 0) Int |
The index of the ad group. |
adGroupTimeUs: Long |
The new ad group time, in microseconds, or |
| Returns | |
|---|---|
AdPlaybackState! |
The updated ad playback state. |
withAdId
fun withAdId(
adGroupIndex: @IntRange(from = 0) Int,
adIndexInAdGroup: @IntRange(from = 0) Int,
adId: String!
): AdPlaybackState!
Returns an instance with the specified ad ID for the given ad.
withAdLoadError
fun withAdLoadError(
adGroupIndex: @IntRange(from = 0) Int,
adIndexInAdGroup: @IntRange(from = 0) Int
): AdPlaybackState!
Returns an instance with the specified ad marked as having a load error.
withAdResumePositionUs
fun withAdResumePositionUs(adResumePositionUs: Long): AdPlaybackState!
Returns an instance with the specified ad resume position, in microseconds, relative to the start of the current ad.
withAdSkipInfo
fun withAdSkipInfo(
adGroupIndex: @IntRange(from = 0) Int,
adIndexInAdGroup: @IntRange(from = 0) Int,
skipInfo: AdPlaybackState.SkipInfo!
): AdPlaybackState!
Returns an instance with the specified SkipInfo for the given ad.
withAdsId
fun withAdsId(adsId: Any!): AdPlaybackState!
Returns an instance with the specified value for adsId.
withAvailableAd
fun withAvailableAd(
adGroupIndex: @IntRange(from = 0) Int,
adIndexInAdGroup: @IntRange(from = 0) Int
): AdPlaybackState!
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
fun withAvailableAdMediaItem(
adGroupIndex: @IntRange(from = 0) Int,
adIndexInAdGroup: @IntRange(from = 0) Int,
mediaItem: MediaItem!
): AdPlaybackState!
Returns an instance with the specified ad MediaItem and the ad marked as available.
| Throws | |
|---|---|
java.lang.IllegalStateException |
If a |
withAvailableAdUri
funwithAvailableAdUri(
adGroupIndex: @IntRange(from = 0) Int,
adIndexInAdGroup: @IntRange(from = 0) Int,
uri: Uri!
): AdPlaybackState!
withContentDurationUs
fun withContentDurationUs(contentDurationUs: Long): AdPlaybackState!
Returns an instance with the specified content duration, in microseconds.
withContentResumeOffsetUs
fun withContentResumeOffsetUs(
adGroupIndex: @IntRange(from = 0) Int,
contentResumeOffsetUs: Long
): AdPlaybackState!
Returns an instance with the specified contentResumeOffsetUs, in microseconds, for the specified ad group.
withIsServerSideInserted
fun withIsServerSideInserted(
adGroupIndex: @IntRange(from = 0) Int,
isServerSideInserted: Boolean
): AdPlaybackState!
Returns an instance with the specified value for isServerSideInserted in the specified ad group.
withLastAdRemoved
fun withLastAdRemoved(adGroupIndex: @IntRange(from = 0) Int): AdPlaybackState!
Returns an instance with the last ad of the given ad group removed.
withLivePostrollPlaceholderAppended
@InlineMe(replacement = "this.withLivePostrollPlaceholderAppended(true)")
funwithLivePostrollPlaceholderAppended(): AdPlaybackState!
withLivePostrollPlaceholderAppended
fun withLivePostrollPlaceholderAppended(isServerSideInserted: Boolean): AdPlaybackState!
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 | |
|---|---|
isServerSideInserted: Boolean |
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
fun withNewAdGroup(adGroupIndex: @IntRange(from = 0) Int, adGroupTimeUs: Long): AdPlaybackState!
Returns an instance with a new ad group.
| Parameters | |
|---|---|
adGroupIndex: @IntRange(from = 0) Int |
The insertion index of the new group. |
adGroupTimeUs: Long |
The ad group time, in microseconds, or |
| Returns | |
|---|---|
AdPlaybackState! |
The updated ad playback state. |
withOriginalAdCount
fun withOriginalAdCount(
adGroupIndex: @IntRange(from = 0) Int,
originalAdCount: Int
): AdPlaybackState!
Returns an instance with the specified value for originalCount in the specified ad group.
withPlayedAd
fun withPlayedAd(
adGroupIndex: @IntRange(from = 0) Int,
adIndexInAdGroup: @IntRange(from = 0) Int
): AdPlaybackState!
Returns an instance with the specified ad marked as played.
withRemovedAdGroupCount
fun withRemovedAdGroupCount(removedAdGroupCount: @IntRange(from = 0) Int): AdPlaybackState!
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
fun withRemovedAdGroupCountBefore(timeUs: Long): AdPlaybackState!
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
fun withResetAdGroup(adGroupIndex: @IntRange(from = 0) Int): AdPlaybackState!
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
fun withSkippedAd(
adGroupIndex: @IntRange(from = 0) Int,
adIndexInAdGroup: @IntRange(from = 0) Int
): AdPlaybackState!
Returns an instance with the specified ad marked as skipped.
withSkippedAdGroup
fun withSkippedAdGroup(adGroupIndex: @IntRange(from = 0) Int): AdPlaybackState!
Returns an instance with all ads in the specified ad group skipped (except for those already marked as played or in the error state).
Public properties
adResumePositionUs
val adResumePositionUs: Long
The position offset in the first unplayed ad at which to begin playback, in microseconds.
adsId
val adsId: Any?
The opaque identifier for ads with which this instance is associated, or null if unset.
contentDurationUs
val contentDurationUs: Long
The duration of the content period in microseconds, if known. TIME_UNSET otherwise.
removedAdGroupCount
val removedAdGroupCount: Int
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.