AdPlaybackState.AdGroup
public final class AdPlaybackState.AdGroup
Represents a group of ads, with information about their states.
Instances are immutable. Call the with* methods to get new instances that have the required changes.
Summary
Public fields |
|
|---|---|
final long |
The offset in microseconds which should be added to the content stream when resuming playback after the ad group. |
final int |
The number of ads in the ad group, or |
final long[] |
The durations of each ad in the ad group, in microseconds. |
final String[] |
The optional IDs of the ads. |
final boolean |
Whether this is an ignorable placeholder that must not be attempted to be played. |
final boolean |
Whether this ad group is server-side inserted and part of the content stream. |
final MediaItem[] |
The |
final int |
The original number of ads in the ad group in case the ad group is only partially available, or |
final AdPlaybackState.SkipInfo[] |
The skip information for each ad in the ad group. |
final int[] |
The state of each ad in the ad group. |
final long |
The time of the ad group in the |
final Uri[] |
This field is deprecated. Use |
Public constructors |
|---|
AdGroup(long timeUs)Creates a new ad group with an unspecified number of ads. |
Public methods |
|
|---|---|
AdPlaybackState.AdGroup |
copy()Returns a safe copy with all array fields copied into the new instance as new arrays. |
boolean |
|
static AdPlaybackState.AdGroup |
This method is deprecated. Use |
static AdPlaybackState.AdGroup |
fromBundle(Bundle bundle, int interfaceVersion)Restores a |
int |
Returns the index of the first ad in the ad group that should be played, or |
int |
getIndexOfAdId(String adId)Returns the index of the ad with the given ad ID, or |
int |
getNextAdIndexToPlay(@IntRange(from = "-1") int lastPlayedAdIndex)Returns the index of the next ad in the ad group that should be played after playing |
boolean |
Returns whether the ad group has at least one ad that is neither played, skipped, nor failed. |
int |
hashCode() |
boolean |
Returns whether this is a placeholder ad group. |
boolean |
isLivePostrollPlaceholder(boolean isServerSideInserted)Returns whether this is a is a placeholder ad group. |
boolean |
Returns whether the ad group has at least one ad that should be played. |
Bundle |
This method is deprecated. Use |
Bundle |
toBundle(int interfaceVersion)Write this ad playback state to a |
AdPlaybackState.AdGroup |
withAdCount(int count)Returns a new instance with the ad count set to |
AdPlaybackState.AdGroup |
withAdDurationsUs(long[] durationsUs)Returns a new instance with the specified ad durations, in microseconds. |
AdPlaybackState.AdGroup |
Returns a new instance with the specified ID for the given ad index. |
AdPlaybackState.AdGroup |
withAdMediaItem(MediaItem mediaItem, @IntRange(from = 0) int index)Returns a new instance with the specified |
AdPlaybackState.AdGroup |
withAdSkipInfo(Returns a new instance with the specified |
AdPlaybackState.AdGroup |
withAdState(Returns a new instance with the specified ad set to the specified |
AdPlaybackState.AdGroup |
This method is deprecated. Use |
AdPlaybackState.AdGroup |
Returns an instance with all ads in final states (played, skipped, error) reset to either available or unavailable, which allows to play them again. |
AdPlaybackState.AdGroup |
Returns an instance with all unavailable and available ads marked as skipped. |
AdPlaybackState.AdGroup |
Returns an instance with all ads made unavailable. |
AdPlaybackState.AdGroup |
withContentResumeOffsetUs(long contentResumeOffsetUs)Returns an instance with the specified |
AdPlaybackState.AdGroup |
withIsServerSideInserted(boolean isServerSideInserted)Returns an instance with the specified value for |
AdPlaybackState.AdGroup |
This method is deprecated. Use |
AdPlaybackState.AdGroup |
withOriginalAdCount(int originalCount)Returns an instance with the specified value for |
AdPlaybackState.AdGroup |
withRemovedAdsAfterIndex(int adIndexInAdGroup)Returns an instance with ads after |
AdPlaybackState.AdGroup |
withTimeUs(long timeUs)Returns a new instance with the |
Public fields
contentResumeOffsetUs
public final long contentResumeOffsetUs
The offset in microseconds which should be added to the content stream when resuming playback after the ad group.
durationsUs
public final long[] durationsUs
The durations of each ad in the ad group, in microseconds.
isPlaceholder
public final boolean isPlaceholder
Whether this is an ignorable placeholder that must not be attempted to be played.
isServerSideInserted
public final boolean isServerSideInserted
Whether this ad group is server-side inserted and part of the content stream.
mediaItems
@NullableType
public final MediaItem[] mediaItems
The MediaItem instances for each ad in the ad group, or null if not yet known.
originalCount
public final int originalCount
The original number of ads in the ad group in case the ad group is only partially available, or LENGTH_UNSET if unknown. An ad can be partially available when a server-side inserted ad live stream is joined while an ad is already playing and some ad information is missing.
skipInfos
@NullableType
public final AdPlaybackState.SkipInfo[] skipInfos
The skip information for each ad in the ad group.
timeUs
public final long timeUs
The time of the ad group in the Timeline.Period, in microseconds, or TIME_END_OF_SOURCE to indicate a postroll ad.
Public constructors
AdGroup
public AdGroup(long timeUs)
Creates a new ad group with an unspecified number of ads.
| Parameters | |
|---|---|
long timeUs |
The time of the ad group in the |
Public methods
copy
public AdPlaybackState.AdGroup copy()
Returns a safe copy with all array fields copied into the new instance as new arrays.
fromBundle
public static AdPlaybackState.AdGroup fromBundle(Bundle bundle, int interfaceVersion)
Restores a AdGroup from a Bundle.
| Parameters | |
|---|---|
Bundle bundle |
The |
int interfaceVersion |
The |
getFirstAdIndexToPlay
public int getFirstAdIndexToPlay()
Returns the index of the first ad in the ad group that should be played, or count if no ads should be played.
getIndexOfAdId
public int getIndexOfAdId(String adId)
Returns the index of the ad with the given ad ID, or INDEX_UNSET if the ad ID can't be found.
getNextAdIndexToPlay
public int getNextAdIndexToPlay(@IntRange(from = "-1") int lastPlayedAdIndex)
Returns the index of the next ad in the ad group that should be played after playing
lastPlayedAdIndex, or count if no later ads should be played. If no ads have been played, pass -1 to get the index of the first ad to play.
Note: server-side inserted ads are always considered playable.
hasUnplayedAds
public boolean hasUnplayedAds()
Returns whether the ad group has at least one ad that is neither played, skipped, nor failed.
isLivePostrollPlaceholder
public boolean isLivePostrollPlaceholder()
Returns whether this is a placeholder ad group. It can be server-side inserted or not. Use isLivePostrollPlaceholder if you want to differentiate.
| Returns | |
|---|---|
boolean |
true only if this is a live postroll placeholder. |
isLivePostrollPlaceholder
public boolean isLivePostrollPlaceholder(boolean isServerSideInserted)
Returns whether this is a is a placeholder ad group.
| Parameters | |
|---|---|
boolean isServerSideInserted |
Whether the postroll placeholder must be server-side inserted. |
| Returns | |
|---|---|
boolean |
true only if this ad group has a matching |
shouldPlayAdGroup
public boolean shouldPlayAdGroup()
Returns whether the ad group has at least one ad that should be played.
toBundle
public Bundle toBundle(int interfaceVersion)
Write this ad playback state to a Bundle.
| Parameters | |
|---|---|
int interfaceVersion |
The |
withAdCount
public AdPlaybackState.AdGroup withAdCount(int count)
Returns a new instance with the ad count set to count.
withAdDurationsUs
public AdPlaybackState.AdGroup withAdDurationsUs(long[] durationsUs)
Returns a new instance with the specified ad durations, in microseconds.
withAdId
public AdPlaybackState.AdGroup withAdId(String adId, @IntRange(from = 0) int index)
Returns a new instance with the specified ID for the given ad index.
withAdMediaItem
public AdPlaybackState.AdGroup withAdMediaItem(MediaItem mediaItem, @IntRange(from = 0) int index)
Returns a new instance with the specified MediaItem set for the specified ad, and the ad marked as AD_STATE_AVAILABLE.
withAdSkipInfo
public AdPlaybackState.AdGroup withAdSkipInfo(
AdPlaybackState.SkipInfo skipInfo,
@IntRange(from = 0) int index
)
Returns a new instance with the specified SkipInfo for the given ad index.
withAdState
public AdPlaybackState.AdGroup withAdState(
@AdPlaybackState.AdState int state,
@IntRange(from = 0) int index
)
Returns a new instance with the specified ad set to the specified state. The ad specified must currently either be in AD_STATE_UNAVAILABLE or AD_STATE_AVAILABLE.
This instance's ad count may be unknown, in which case index must be less than the ad count specified later. Otherwise, index must be less than the current ad count.
withAllAdsReset
public AdPlaybackState.AdGroup withAllAdsReset()
Returns an instance with all ads in final states (played, skipped, error) reset to either available or unavailable, which allows to play them again.
withAllAdsSkipped
public AdPlaybackState.AdGroup withAllAdsSkipped()
Returns an instance with all unavailable and available ads marked as skipped. If the ad count hasn't been set, it will be set to zero.
withAllAdsUnavailable
public AdPlaybackState.AdGroup withAllAdsUnavailable()
Returns an instance with all ads made unavailable.
The state of each ad is set to AD_STATE_UNAVAILABLE, durations are reset to TIME_UNSET and the media item is set to null. The contentResumeOffsetUs is reset to 0 accordingly.
withContentResumeOffsetUs
public AdPlaybackState.AdGroup withContentResumeOffsetUs(long contentResumeOffsetUs)
Returns an instance with the specified contentResumeOffsetUs.
withIsServerSideInserted
public AdPlaybackState.AdGroup withIsServerSideInserted(boolean isServerSideInserted)
Returns an instance with the specified value for isServerSideInserted.
withOriginalAdCount
public AdPlaybackState.AdGroup withOriginalAdCount(int originalCount)
Returns an instance with the specified value for originalCount.
withRemovedAdsAfterIndex
public AdPlaybackState.AdGroup withRemovedAdsAfterIndex(int adIndexInAdGroup)
Returns an instance with ads after adIndexInAdGroup removed.
If contentResumeOffsetUs has a non-zero value its value is reset to the safe sum of the remaining durations.
| Parameters | |
|---|---|
int adIndexInAdGroup |
The index of the last ad to keep in the ad group (non-negative). |
| Returns | |
|---|---|
AdPlaybackState.AdGroup |
The updated ad group. |
| Throws | |
|---|---|
java.lang.IllegalArgumentException |
if |
withTimeUs
public AdPlaybackState.AdGroup withTimeUs(long timeUs)
Returns a new instance with the timeUs set to the specified value.