public final class

AdPlaybackState.AdGroup

extends java.lang.Object

implements Bundleable

 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 static final Bundleable.Creator<AdPlaybackState.AdGroup>CREATOR

Object that can restore AdPlaybackState.AdGroup from a .

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 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

The URI of each ad in the ad group.

Constructors
publicAdGroup(long timeUs)

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

Methods
public booleanequals(java.lang.Object o)

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.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)

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

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.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 Uri uris

The URI of each ad in the ad group.

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.

public static final Bundleable.Creator<AdPlaybackState.AdGroup> CREATOR

Object that can restore AdPlaybackState.AdGroup from a .

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.

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)

Returns a new instance with the specified uri 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 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()