public final class

AdPlaybackState.AdGroup

extends java.lang.Object

 java.lang.Object

↳androidx.media3.common.AdPlaybackState.AdGroup

Overview

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

Fields
public final longcontentResumeOffsetUs

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

public final intcount

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

public final long[]durationsUs

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

public final booleanisServerSideInserted

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

public final MediaItemmediaItems

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

public final intoriginalCount

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

public final int[]states

The state of each ad in the ad group.

public final longtimeUs

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

public final Uriuris

Constructors
publicAdGroup(long timeUs)

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

Methods
public booleanequals(java.lang.Object o)

public static AdPlaybackState.AdGroupfromBundle(Bundle bundle)

Restores a AdGroup from a .

public intgetFirstAdIndexToPlay()

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

public intgetNextAdIndexToPlay(int lastPlayedAdIndex)

Returns the index of the next ad in the ad group that should be played after playing lastPlayedAdIndex, or AdPlaybackState.AdGroup.count if no later ads should be played.

public inthashCode()

public booleanhasUnplayedAds()

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

public booleanshouldPlayAdGroup()

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

public BundletoBundle()

public AdPlaybackState.AdGroupwithAdCount(int count)

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

public AdPlaybackState.AdGroupwithAdDurationsUs(long[] durationsUs[])

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

public AdPlaybackState.AdGroupwithAdMediaItem(MediaItem mediaItem, int index)

Returns a new instance with the specified MediaItem set for the specified ad, and the ad marked as AdPlaybackState.AD_STATE_AVAILABLE.

public AdPlaybackState.AdGroupwithAdState(int state, int index)

Returns a new instance with the specified ad set to the specified state.

public AdPlaybackState.AdGroupwithAdUri(Uri uri, int index)

public AdPlaybackState.AdGroupwithAllAdsReset()

Returns an instance with all ads in final states (played, skipped, error) reset to either available or unavailable, which allows to play them again.

public AdPlaybackState.AdGroupwithAllAdsSkipped()

Returns an instance with all unavailable and available ads marked as skipped.

public AdPlaybackState.AdGroupwithContentResumeOffsetUs(long contentResumeOffsetUs)

Returns an instance with the specified AdPlaybackState.AdGroup.contentResumeOffsetUs.

public AdPlaybackState.AdGroupwithIsServerSideInserted(boolean isServerSideInserted)

Returns an instance with the specified value for AdPlaybackState.AdGroup.isServerSideInserted.

public AdPlaybackState.AdGroupwithLastAdRemoved()

Removes the last ad from the ad group.

public AdPlaybackState.AdGroupwithOriginalAdCount(int originalCount)

Returns an instance with the specified value for AdPlaybackState.AdGroup.originalCount.

public AdPlaybackState.AdGroupwithTimeUs(long timeUs)

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

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

Fields

public final long timeUs

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

public final int count

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

public final int originalCount

The original number of ads in the ad group in case the ad group is only partially available, or C.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.

public final Uri uris

Deprecated: Use AdPlaybackState.AdGroup.mediaItems instead.

public final MediaItem mediaItems

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

public final int[] states

The state of each ad in the ad group.

public final long[] durationsUs

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

public final long contentResumeOffsetUs

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

public final boolean isServerSideInserted

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

Constructors

public AdGroup(long timeUs)

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

Parameters:

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

Methods

public int getFirstAdIndexToPlay()

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

public int getNextAdIndexToPlay(int lastPlayedAdIndex)

Returns the index of the next ad in the ad group that should be played after playing lastPlayedAdIndex, or AdPlaybackState.AdGroup.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.

public boolean shouldPlayAdGroup()

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

public boolean hasUnplayedAds()

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

public boolean equals(java.lang.Object o)

public int hashCode()

public AdPlaybackState.AdGroup withTimeUs(long timeUs)

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

public AdPlaybackState.AdGroup withAdCount(int count)

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

public AdPlaybackState.AdGroup withAdUri(Uri uri, int index)

Deprecated: Use AdPlaybackState.AdGroup.withAdMediaItem(MediaItem, int) instead.

public AdPlaybackState.AdGroup withAdMediaItem(MediaItem mediaItem, int index)

Returns a new instance with the specified MediaItem set for the specified ad, and the ad marked as AdPlaybackState.AD_STATE_AVAILABLE.

public AdPlaybackState.AdGroup withAdState(int state, int index)

Returns a new instance with the specified ad set to the specified state. The ad specified must currently either be in AdPlaybackState.AD_STATE_UNAVAILABLE or AdPlaybackState.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.

public AdPlaybackState.AdGroup withAdDurationsUs(long[] durationsUs[])

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

public AdPlaybackState.AdGroup withContentResumeOffsetUs(long contentResumeOffsetUs)

Returns an instance with the specified AdPlaybackState.AdGroup.contentResumeOffsetUs.

public AdPlaybackState.AdGroup withIsServerSideInserted(boolean isServerSideInserted)

Returns an instance with the specified value for AdPlaybackState.AdGroup.isServerSideInserted.

public AdPlaybackState.AdGroup withOriginalAdCount(int originalCount)

Returns an instance with the specified value for AdPlaybackState.AdGroup.originalCount.

public AdPlaybackState.AdGroup withLastAdRemoved()

Removes the last ad from the ad group.

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.

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.

public Bundle toBundle()

public static AdPlaybackState.AdGroup fromBundle(Bundle bundle)

Restores a AdGroup from a .