AdPlaybackState.AdGroup


public final class AdPlaybackState.AdGroup implements Bundleable


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

Constants

static final Bundleable.Creator<AdPlaybackState.AdGroup>

This field is deprecated.

Use fromBundle instead.

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 LENGTH_UNSET if unknown.

final long[]

The durations of each ad in the ad group, in microseconds.

final boolean

Whether this ad group is server-side inserted and part of the content stream.

final MediaItem[]

The MediaItem instances for each ad in the ad group, or null if not yet known.

final int

The original number of ads in the ad group in case the ad group is only partially available, or LENGTH_UNSET if unknown.

final int[]

The state of each ad in the ad group.

final long

The time of the ad group in the Timeline.Period, in microseconds, or TIME_END_OF_SOURCE to indicate a postroll ad.

final Uri[]

This field is deprecated.

Use mediaItems instead.

Public constructors

AdGroup(long timeUs)

Creates a new ad group with an unspecified number of ads.

Public methods

boolean
static AdPlaybackState.AdGroup

Restores a AdGroup from a Bundle.

int

Returns the index of the first ad in the ad group that should be played, or count if no ads should be played.

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.

boolean

Returns whether the ad group has at least one ad that is neither played, skipped, nor failed.

int
boolean

Returns whether the ad group has at least one ad that should be played.

Bundle

Returns a Bundle representing the information stored in this object.

AdPlaybackState.AdGroup
withAdCount(int count)

Returns a new instance with the ad count set to count.

AdPlaybackState.AdGroup
withAdDurationsUs(long[] durationsUs)

Returns a new instance with the specified ad durations, in microseconds.

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.

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.

AdPlaybackState.AdGroup
withAdUri(Uri uri, @IntRange(from = 0) int index)

This method is deprecated.

Use withAdMediaItem instead.

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
withContentResumeOffsetUs(long contentResumeOffsetUs)

Returns an instance with the specified contentResumeOffsetUs.

AdPlaybackState.AdGroup
withIsServerSideInserted(boolean isServerSideInserted)

Returns an instance with the specified value for isServerSideInserted.

AdPlaybackState.AdGroup

Removes the last ad from the ad group.

AdPlaybackState.AdGroup
withOriginalAdCount(int originalCount)

Returns an instance with the specified value for originalCount.

AdPlaybackState.AdGroup
withTimeUs(long timeUs)

Returns a new instance with the timeUs set to the specified value.

Constants

CREATOR

public static final Bundleable.Creator<AdPlaybackState.AdGroupCREATOR

Object that can restore AdGroup from a Bundle.

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.

count

public final int count

The number of ads in the ad group, or LENGTH_UNSET if unknown.

durationsUs

public final long[] durationsUs

The durations of each ad in the ad group, in microseconds.

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.

states

@AdPlaybackState.AdState
public final int[] states

The state of 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.

uris

@NullableType
public final Uri[] uris

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 Timeline.Period, in microseconds, or TIME_END_OF_SOURCE to indicate a postroll ad.

Public methods

equals

public boolean equals(@Nullable Object o)

fromBundle

public static AdPlaybackState.AdGroup fromBundle(Bundle bundle)

Restores a AdGroup from a Bundle.

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.

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.

hashCode

public int hashCode()

shouldPlayAdGroup

public boolean shouldPlayAdGroup()

Returns whether the ad group has at least one ad that should be played.

toBundle

public Bundle toBundle()

Returns a Bundle representing the information stored in this object.

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.

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.

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.

withAdUri

public AdPlaybackState.AdGroup withAdUri(Uri uri, @IntRange(from = 0) int index)

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.

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.

withLastAdRemoved

public AdPlaybackState.AdGroup withLastAdRemoved()

Removes the last ad from the ad group.

withOriginalAdCount

public AdPlaybackState.AdGroup withOriginalAdCount(int originalCount)

Returns an instance with the specified value for originalCount.

withTimeUs

public AdPlaybackState.AdGroup withTimeUs(long timeUs)

Returns a new instance with the timeUs set to the specified value.