# AdPlaybackState

Artifact: [androidx.media3:media3-common](https://developer.android.com/jetpack/androidx/releases/media3) [View Source](https://cs.android.com/search?q=file:androidx/media3/common/AdPlaybackState.java+class:androidx.media3.common.AdPlaybackState)

*** ** * ** ***


```
@UnstableApi
public final class AdPlaybackState
```

<br />

*** ** * ** ***

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 |
|---|
| `public final class https://developer.android.com/reference/androidx/media3/common/AdPlaybackState.AdGroup` Represents a group of ads, with information about their states. |
| `@https://developer.android.com/reference/java/lang/annotation/Documented.html @https://developer.android.com/reference/java/lang/annotation/Retention.html(value = https://developer.android.com/reference/java/lang/annotation/RetentionPolicy.html#SOURCE) @https://developer.android.com/reference/java/lang/annotation/Target.html(value = ) @https://developer.android.com/reference/androidx/annotation/IntDef(value = ) public annotation https://developer.android.com/reference/androidx/media3/common/AdPlaybackState.AdState` Represents the state of an ad in an ad group. |
| `public final class https://developer.android.com/reference/androidx/media3/common/AdPlaybackState.SkipInfo` Information about skipping an ad. |

| ### Constants |
|---|---|
| `static final int` | `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#AD_STATE_AVAILABLE() = 1` State for an ad that has a URL but has not yet been played. |
| `static final int` | `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#AD_STATE_ERROR() = 4` State for an ad that could not be loaded. |
| `static final int` | `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#AD_STATE_PLAYED() = 3` State for an ad that was played in full. |
| `static final int` | `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#AD_STATE_SKIPPED() = 2` State for an ad that was skipped. |
| `static final int` | `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#AD_STATE_UNAVAILABLE() = 0` State for an ad that does not yet have a URL. |
| `static final https://developer.android.com/reference/androidx/media3/common/AdPlaybackState` | `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#NONE()` Ad playback state with no ads. |

| ### Public fields |
|---|---|
| `final int` | `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#adGroupCount()` The number of ad groups. |
| `final long` | `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#adResumePositionUs()` The position offset in the first unplayed ad at which to begin playback, in microseconds. |
| `final @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/Object.html` | `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#adsId()` The opaque identifier for ads with which this instance is associated, or `null` if unset. |
| `final long` | `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#contentDurationUs()` The duration of the content period in microseconds, if known. |
| `final int` | `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#removedAdGroupCount()` The number of ad groups that have been removed. |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#AdPlaybackState(java.lang.Object,long...)(https://developer.android.com/reference/java/lang/Object.html adsId, long[] adGroupTimesUs)` Creates a new ad playback state with the specified ad group times. |

| ### Public methods |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState` | `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#copy()()` Returns an new instance that is a safe deep copy of this instance in case an immutable object is used for `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#adsId()`. |
| `boolean` | `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#endsWithLivePostrollPlaceHolder()()` Returns whether the last ad group is a live postroll placeholder as inserted by `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#withLivePostrollPlaceholderAppended(boolean)`. |
| `boolean` | `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#endsWithLivePostrollPlaceHolder(boolean)(boolean isServerSideInserted)` Returns whether the last ad group is a live postroll placeholder as inserted by `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#withLivePostrollPlaceholderAppended(boolean)` . |
| `boolean` | `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#equals(java.lang.Object)(@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/Object.html o)` |
| `static https://developer.android.com/reference/androidx/media3/common/AdPlaybackState` | `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#fromAdPlaybackState(java.lang.Object,androidx.media3.common.AdPlaybackState)(https://developer.android.com/reference/java/lang/Object.html adsId, https://developer.android.com/reference/androidx/media3/common/AdPlaybackState adPlaybackState)` Returns a copy of the ad playback state with the given ads ID. |
| `static https://developer.android.com/reference/androidx/media3/common/AdPlaybackState` | `[fromBundle](https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#fromBundle(android.os.Bundle))(https://developer.android.com/reference/android/os/Bundle.html bundle)` **This method is deprecated.** Use `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#fromBundle(android.os.Bundle,int)` instead. <br /> |
| `static https://developer.android.com/reference/androidx/media3/common/AdPlaybackState` | `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#fromBundle(android.os.Bundle,int)(https://developer.android.com/reference/android/os/Bundle.html bundle, int interfaceVersion)` Restores a `AdPlaybackState` from a `https://developer.android.com/reference/android/os/Bundle.html`. |
| `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState.AdGroup` | `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#getAdGroup(int)(@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int adGroupIndex)` Returns the specified `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState.AdGroup`. |
| `int` | `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#getAdGroupIndexAfterPositionUs(long,long)(long positionUs, long periodDurationUs)` Returns the index of the next ad group after `positionUs` that should be played. |
| `int` | `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#getAdGroupIndexForPositionUs(long,long)(long positionUs, long periodDurationUs)` Returns the index of the ad group at or before `positionUs` that should be played before the content at `positionUs`. |
| `int` | `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#getAdIndexOfAdId(int,java.lang.String)(int adGroupIndex, https://developer.android.com/reference/java/lang/String.html adId)` Returns the index of the ad with the given ad ID in the given ad group, or `https://developer.android.com/reference/androidx/media3/common/C#INDEX_UNSET()` if the ad ID can't be found. |
| `int` | `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#hashCode()()` |
| `boolean` | `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#isAdInErrorState(int,int)( @https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int adGroupIndex, @https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int adIndexInAdGroup )` Returns whether the specified ad has been marked as in `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#AD_STATE_ERROR()`. |
| `boolean` | `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#isLivePostrollPlaceholder(int)(int adGroupIndex)` Returns whether the `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState.AdGroup` at the given ad group index is a live postroll placeholder. |
| `boolean` | `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#isLivePostrollPlaceholder(int,boolean)( int adGroupIndex, boolean isServerSideInserted )` Returns whether the `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState.AdGroup` at the given ad group index is a live postroll placeholder and either server or client-side inserted. |
| `static long` | `@https://developer.android.com/reference/androidx/media3/common/util/UnstableApi https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#sumOfDurations(long...)(long[] durations)` Returns the sum of all durations in the given array, treating `https://developer.android.com/reference/androidx/media3/common/C#TIME_UNSET()` as 0. |
| `https://developer.android.com/reference/android/os/Bundle.html` | `[toBundle](https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#toBundle())()` **This method is deprecated.** Use `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#toBundle(int)` instead. <br /> |
| `https://developer.android.com/reference/android/os/Bundle.html` | `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#toBundle(int)(int interfaceVersion)` Returns a `https://developer.android.com/reference/android/os/Bundle.html` representing the information stored in this object. |
| `https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#toString()()` |
| `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState` | `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#withAdCount(int,int)( @https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int adGroupIndex, @https://developer.android.com/reference/androidx/annotation/IntRange(from = 1) int adCount )` Returns an instance with the number of ads in `adGroupIndex` resolved to `adCount`. |
| `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState` | `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#withAdDurationsUs(long[][])(long[][] adDurationUs)` Returns an instance with the specified ad durations, in microseconds. |
| `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState` | `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#withAdDurationsUs(int,long...)( @https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int adGroupIndex, long[] adDurationsUs )` Returns an instance with the specified ad durations, in microseconds, in the specified ad group. |
| `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState` | `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#withAdGroupTimeUs(int,long)(@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int adGroupIndex, long adGroupTimeUs)` Returns an instance with the specified ad group time. |
| `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState` | `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#withAdId(int,int,java.lang.String)( @https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int adGroupIndex, @https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int adIndexInAdGroup, https://developer.android.com/reference/java/lang/String.html adId )` Returns an instance with the specified ad ID for the given ad. |
| `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState` | `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#withAdLoadError(int,int)( @https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int adGroupIndex, @https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int adIndexInAdGroup )` Returns an instance with the specified ad marked `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#AD_STATE_ERROR()`. |
| `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState` | `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#withAdResumePositionUs(long)(long adResumePositionUs)` Returns an instance with the specified ad resume position, in microseconds, relative to the start of the current ad. |
| `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState` | `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#withAdSkipInfo(int,int,androidx.media3.common.AdPlaybackState.SkipInfo)( @https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int adGroupIndex, @https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int adIndexInAdGroup, https://developer.android.com/reference/androidx/media3/common/AdPlaybackState.SkipInfo skipInfo )` Returns an instance with the specified `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState.SkipInfo` for the given ad. |
| `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState` | `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#withAdsId(java.lang.Object)(https://developer.android.com/reference/java/lang/Object.html adsId)` Returns an instance with the specified value for `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#adsId()`. |
| `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState` | `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#withAvailableAd(int,int)( @https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int adGroupIndex, @https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int adIndexInAdGroup )` Returns an instance with the specified ad marked as `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#AD_STATE_AVAILABLE()`. |
| `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState` | `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#withAvailableAdMediaItem(int,int,androidx.media3.common.MediaItem)( @https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int adGroupIndex, @https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int adIndexInAdGroup, https://developer.android.com/reference/androidx/media3/common/MediaItem mediaItem )` Returns an instance with the specified ad `https://developer.android.com/reference/androidx/media3/common/MediaItem` and the ad marked as `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#AD_STATE_AVAILABLE()`. |
| `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState` | `[withAvailableAdUri](https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#withAvailableAdUri(int,int,android.net.Uri))( @https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int adGroupIndex, @https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int adIndexInAdGroup, https://developer.android.com/reference/android/net/Uri.html uri )` **This method is deprecated.** Use `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#withAvailableAdMediaItem(int,int,androidx.media3.common.MediaItem)` instead. <br /> |
| `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState` | `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#withContentDurationUs(long)(long contentDurationUs)` Returns an instance with the specified content duration, in microseconds. |
| `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState` | `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#withContentResumeOffsetUs(int,long)( @https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int adGroupIndex, long contentResumeOffsetUs )` Returns an instance with the specified `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState.AdGroup#contentResumeOffsetUs()`, in microseconds, for the specified ad group. |
| `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState` | `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#withIsServerSideInserted(int,boolean)( @https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int adGroupIndex, boolean isServerSideInserted )` Returns an instance with the specified value for `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState.AdGroup#isServerSideInserted()` in the specified ad group. |
| `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState` | `[withLastAdRemoved](https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#withLastAdRemoved(int))(@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int adGroupIndex)` **This method is deprecated.** Use `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#withRemovedAdsAfterIndex(int,int)` instead. <br /> |
| `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState` | `@https://checkerframework.org/api/com/google/errorprone/annotations/InlineMe.html(replacement = "this.withLivePostrollPlaceholderAppended(true)") [withLivePostrollPlaceholderAppended](https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#withLivePostrollPlaceholderAppended())()` **This method is deprecated.** Use `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#withLivePostrollPlaceholderAppended(boolean)` and pass `true` instead. <br /> |
| `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState` | `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#withLivePostrollPlaceholderAppended(boolean)(boolean isServerSideInserted)` Appends a live postroll placeholder ad group to the ad playback state. |
| `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState` | `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#withNewAdGroup(int,long)(@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int adGroupIndex, long adGroupTimeUs)` Returns an instance with a new ad group. |
| `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState` | `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#withOriginalAdCount(int,int)( @https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int adGroupIndex, int originalAdCount )` Returns an instance with the specified value for `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState.AdGroup#originalCount()` in the specified ad group. |
| `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState` | `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#withPlayedAd(int,int)( @https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int adGroupIndex, @https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int adIndexInAdGroup )` Returns an instance with the specified ad marked as `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#AD_STATE_PLAYED()`. |
| `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState` | `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#withRemovedAdGroupCount(int)(@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int removedAdGroupCount)` Returns an instance with the specified number of `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#removedAdGroupCount()`. |
| `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState` | `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#withRemovedAdGroupCountBefore(long)(long timeUs)` Returns an instance with ad groups removed until and excluding the first post roll ad group or the first ad group with `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState.AdGroup#timeUs()` larger than the given time, in microseconds. |
| `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState` | `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#withRemovedAdsAfterIndex(int,int)( @https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int adGroupIndex, @https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int adIndexInAdGroup )` Returns an instance with ads after `adIndexInAdGroup` removed from the specified ad group. |
| `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState` | `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#withResetAdGroup(int)(@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int adGroupIndex)` 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. |
| `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState` | `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#withSkippedAd(int,int)( @https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int adGroupIndex, @https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int adIndexInAdGroup )` Returns an instance with the specified ad marked as `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#AD_STATE_SKIPPED()`. |
| `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState` | `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#withSkippedAdGroup(int)(@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int adGroupIndex)` Returns an instance with all ads in the specified ad group skipped (except for those already marked as played or in the error state). |
| `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState` | `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#withUnavailableAdGroup(int)(@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int adGroupIndex)` Returns an instance with all ads in the specified ad group made unavailable. |

## Constants

### AD_STATE_AVAILABLE

```
public static final int AD_STATE_AVAILABLE = 1
```

State for an ad that has a URL but has not yet been played.

### AD_STATE_ERROR

```
public static final int AD_STATE_ERROR = 4
```

State for an ad that could not be loaded.

### AD_STATE_PLAYED

```
public static final int AD_STATE_PLAYED = 3
```

State for an ad that was played in full.

### AD_STATE_SKIPPED

```
public static final int AD_STATE_SKIPPED = 2
```

State for an ad that was skipped.

### AD_STATE_UNAVAILABLE

```
public static final int AD_STATE_UNAVAILABLE = 0
```

State for an ad that does not yet have a URL.

### NONE

```
public static final AdPlaybackState NONE
```

Ad playback state with no ads.

## Public fields

### adGroupCount

```
public final int adGroupCount
```

The number of ad groups.

### adResumePositionUs

```
public final long adResumePositionUs
```

The position offset in the first unplayed ad at which to begin playback, in microseconds.

### adsId

```
public final @Nullable Object adsId
```

The opaque identifier for ads with which this instance is associated, or `null` if unset.

### contentDurationUs

```
public final long contentDurationUs
```

The duration of the content period in microseconds, if known. `https://developer.android.com/reference/androidx/media3/common/C#TIME_UNSET()` otherwise.

### removedAdGroupCount

```
public final int removedAdGroupCount
```

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.

## Public constructors

### AdPlaybackState

```
public AdPlaybackState(Object adsId, long[] adGroupTimesUs)
```

Creates a new ad playback state with the specified ad group times.

| Parameters |
|---|---|
| `https://developer.android.com/reference/java/lang/Object.html adsId` | The opaque identifier for ads with which this instance is associated. |
| `long[] adGroupTimesUs` | The times of ad groups in microseconds, relative to the start of the `https://developer.android.com/reference/androidx/media3/common/Timeline.Period` they belong to. A final element with the value `https://developer.android.com/reference/androidx/media3/common/C#TIME_END_OF_SOURCE()` indicates that there is a postroll ad. |

## Public methods

### copy

```
public AdPlaybackState copy()
```

Returns an new instance that is a safe deep copy of this instance in case an immutable object is used for `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#adsId()`.

### endsWithLivePostrollPlaceHolder

```
public boolean endsWithLivePostrollPlaceHolder()
```

Returns whether the last ad group is a live postroll placeholder as inserted by `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#withLivePostrollPlaceholderAppended(boolean)`.

Note: That either server-side or client-side inserted placeholders are considered. Use `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#endsWithLivePostrollPlaceHolder(boolean)` 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

```
public boolean endsWithLivePostrollPlaceHolder(boolean isServerSideInserted)
```

Returns whether the last ad group is a live postroll placeholder as inserted by `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#withLivePostrollPlaceholderAppended(boolean)` .

| Parameters |
|---|---|
| `boolean isServerSideInserted` | Whether the trailing placeholder is server-side inserted. |

| Returns |
|---|---|
| `boolean` | Whether the ad playback state ends with a live postroll placeholder. |

### equals

```
public boolean equals(@Nullable Object o)
```

### fromAdPlaybackState

```
public static AdPlaybackState fromAdPlaybackState(Object adsId, AdPlaybackState adPlaybackState)
```

Returns a copy of the ad playback state with the given ads ID.

| Parameters |
|---|---|
| `https://developer.android.com/reference/java/lang/Object.html adsId` | The new ads ID. |
| `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState adPlaybackState` | The ad playback state to copy. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState` | The new ad playback state. |

### fromBundle

```
public static AdPlaybackState [fromBundle](https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#fromBundle(android.os.Bundle))(Bundle bundle)
```

> [!CAUTION]
> **This method is deprecated.**   
>
> Use `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#fromBundle(android.os.Bundle,int)` instead.

### fromBundle

```
public static AdPlaybackState fromBundle(Bundle bundle, int interfaceVersion)
```

Restores a `AdPlaybackState` from a `https://developer.android.com/reference/android/os/Bundle.html`.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/os/Bundle.html bundle` | The `https://developer.android.com/reference/android/os/Bundle.html`. |
| `int interfaceVersion` | The `https://developer.android.com/reference/androidx/media3/common/MediaLibraryInfo#INTERFACE_VERSION()` of the sending process. |

### getAdGroup

```
public AdPlaybackState.AdGroup getAdGroup(@IntRange(from = 0) int adGroupIndex)
```

Returns the specified `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState.AdGroup`.

### getAdGroupIndexAfterPositionUs

```
public int getAdGroupIndexAfterPositionUs(long positionUs, long periodDurationUs)
```

Returns the index of the next ad group after `positionUs` that should be played. Returns `https://developer.android.com/reference/androidx/media3/common/C#INDEX_UNSET()` if there is no such ad group.

| Parameters |
|---|---|
| `long positionUs` | The period position after which to find an ad group, in microseconds, or `https://developer.android.com/reference/androidx/media3/common/C#TIME_END_OF_SOURCE()` for the end of the stream (in which case there can be no ad group after the position). |
| `long periodDurationUs` | The duration of the containing timeline period, in microseconds, or `https://developer.android.com/reference/androidx/media3/common/C#TIME_UNSET()` if not known. |

| Returns |
|---|---|
| `int` | The index of the ad group, or `https://developer.android.com/reference/androidx/media3/common/C#INDEX_UNSET()`. |

### getAdGroupIndexForPositionUs

```
public int getAdGroupIndexForPositionUs(long positionUs, long periodDurationUs)
```

Returns the index of the ad group at or before `positionUs` that should be played before the content at `positionUs`. Returns `https://developer.android.com/reference/androidx/media3/common/C#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 |
|---|---|
| `long positionUs` | The period position at or before which to find an ad group, in microseconds, or `https://developer.android.com/reference/androidx/media3/common/C#TIME_END_OF_SOURCE()` for the end of the stream (in which case the index of any unplayed postroll ad group will be returned). |
| `long periodDurationUs` | The duration of the containing timeline period, in microseconds, or `https://developer.android.com/reference/androidx/media3/common/C#TIME_UNSET()` if not known. |

| Returns |
|---|---|
| `int` | The index of the ad group, or `https://developer.android.com/reference/androidx/media3/common/C#INDEX_UNSET()`. |

### getAdIndexOfAdId

```
public int getAdIndexOfAdId(int adGroupIndex, String adId)
```

Returns the index of the ad with the given ad ID in the given ad group, or `https://developer.android.com/reference/androidx/media3/common/C#INDEX_UNSET()` if the ad ID can't be found.

| Parameters |
|---|---|
| `int adGroupIndex` | The ad group index. |
| `https://developer.android.com/reference/java/lang/String.html adId` | The ad ID. |

| Returns |
|---|---|
| `int` | The ad index in the ad group, or `https://developer.android.com/reference/androidx/media3/common/C#INDEX_UNSET()` if the ad ID is not found. |

### hashCode

```
public int hashCode()
```

### isAdInErrorState

```
public boolean isAdInErrorState(
    @IntRange(from = 0) int adGroupIndex,
    @IntRange(from = 0) int adIndexInAdGroup
)
```

Returns whether the specified ad has been marked as in `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#AD_STATE_ERROR()`.

### isLivePostrollPlaceholder

```
public boolean isLivePostrollPlaceholder(int adGroupIndex)
```

Returns whether the `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState.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 `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#isLivePostrollPlaceholder(int,boolean)` if you want to test for one or the other only.

| Parameters |
|---|---|
| `int adGroupIndex` | The ad group index. |

| Returns |
|---|---|
| `boolean` | True if the ad group at the given index is a live postroll placeholder, false if not. |

### isLivePostrollPlaceholder

```
public boolean isLivePostrollPlaceholder(
    int adGroupIndex,
    boolean isServerSideInserted
)
```

Returns whether the `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState.AdGroup` at the given ad group index is a live postroll placeholder and either server or client-side inserted.

| Parameters |
|---|---|
| `int adGroupIndex` | The ad group index. |
| `boolean isServerSideInserted` | 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. |

### sumOfDurations

```
@UnstableApi
public static long sumOfDurations(long[] durations)
```

Returns the sum of all durations in the given array, treating `https://developer.android.com/reference/androidx/media3/common/C#TIME_UNSET()` as 0.

| Parameters |
|---|---|
| `long[] durations` | The durations to sum. |

| Returns |
|---|---|
| `long` | The sum of all durations. |

### toBundle

```
public Bundle [toBundle](https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#toBundle())()
```

> [!CAUTION]
> **This method is deprecated.**   
>
> Use `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#toBundle(int)` instead.

### toBundle

```
public Bundle toBundle(int interfaceVersion)
```

Returns a `https://developer.android.com/reference/android/os/Bundle.html` representing the information stored in this object.

It omits the `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#adsId()` field so the `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#adsId()` of instances restored by `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#fromBundle(android.os.Bundle,int)` will always be `null`.

| Parameters |
|---|---|
| `int interfaceVersion` | The `https://developer.android.com/reference/androidx/media3/common/MediaLibraryInfo#INTERFACE_VERSION()` of the receiving process. |

### toString

```
public String toString()
```

### withAdCount

```
public AdPlaybackState withAdCount(
    @IntRange(from = 0) int adGroupIndex,
    @IntRange(from = 1) int adCount
)
```

Returns an instance with the number of ads in `adGroupIndex` resolved to `adCount`. The ad count must be greater than zero.

### withAdDurationsUs

```
public AdPlaybackState withAdDurationsUs(long[][] adDurationUs)
```

Returns an instance with the specified ad durations, in microseconds.

The number of arrays of durations (`adDurations.length`) must always be equal to `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#adGroupCount()`. This is required even on an instance created with `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#withRemovedAdGroupCount(int)`. The array of durations at the index of a removed ad group can be null or empty.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if `adDurations.length != adGroupCount`. |

### withAdDurationsUs

```
public AdPlaybackState withAdDurationsUs(
    @IntRange(from = 0) int adGroupIndex,
    long[] adDurationsUs
)
```

Returns an instance with the specified ad durations, in microseconds, in the specified ad group.

### withAdGroupTimeUs

```
public AdPlaybackState withAdGroupTimeUs(@IntRange(from = 0) int adGroupIndex, long adGroupTimeUs)
```

Returns an instance with the specified ad group time.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int adGroupIndex` | The index of the ad group. |
| `long adGroupTimeUs` | The new ad group time, in microseconds, or `https://developer.android.com/reference/androidx/media3/common/C#TIME_END_OF_SOURCE()` to indicate a postroll ad. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState` | The updated ad playback state. |

### withAdId

```
public AdPlaybackState withAdId(
    @IntRange(from = 0) int adGroupIndex,
    @IntRange(from = 0) int adIndexInAdGroup,
    String adId
)
```

Returns an instance with the specified ad ID for the given ad.

### withAdLoadError

```
public AdPlaybackState withAdLoadError(
    @IntRange(from = 0) int adGroupIndex,
    @IntRange(from = 0) int adIndexInAdGroup
)
```

Returns an instance with the specified ad marked `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#AD_STATE_ERROR()`.

### withAdResumePositionUs

```
public AdPlaybackState withAdResumePositionUs(long adResumePositionUs)
```

Returns an instance with the specified ad resume position, in microseconds, relative to the start of the current ad.

### withAdSkipInfo

```
public AdPlaybackState withAdSkipInfo(
    @IntRange(from = 0) int adGroupIndex,
    @IntRange(from = 0) int adIndexInAdGroup,
    AdPlaybackState.SkipInfo skipInfo
)
```

Returns an instance with the specified `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState.SkipInfo` for the given ad.

### withAdsId

```
public AdPlaybackState withAdsId(Object adsId)
```

Returns an instance with the specified value for `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#adsId()`.

### withAvailableAd

```
public AdPlaybackState withAvailableAd(
    @IntRange(from = 0) int adGroupIndex,
    @IntRange(from = 0) int adIndexInAdGroup
)
```

Returns an instance with the specified ad marked as `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#AD_STATE_AVAILABLE()`.

Must not be called with client-side inserted ad groups. Client-side inserted ads should use `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#withAvailableAdMediaItem(int,int,androidx.media3.common.MediaItem)`.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | in case this methods is called on an ad group that `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState.AdGroup#isServerSideInserted()`. |

### withAvailableAdMediaItem

```
public AdPlaybackState withAvailableAdMediaItem(
    @IntRange(from = 0) int adGroupIndex,
    @IntRange(from = 0) int adIndexInAdGroup,
    MediaItem mediaItem
)
```

Returns an instance with the specified ad `https://developer.android.com/reference/androidx/media3/common/MediaItem` and the ad marked as `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#AD_STATE_AVAILABLE()`.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | If a `https://developer.android.com/reference/androidx/media3/common/MediaItem` with an empty `https://developer.android.com/reference/androidx/media3/common/MediaItem.LocalConfiguration#uri()` is passed as argument for a client-side inserted ad group. |

### withAvailableAdUri

```
public AdPlaybackState [withAvailableAdUri](https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#withAvailableAdUri(int,int,android.net.Uri))(
    @IntRange(from = 0) int adGroupIndex,
    @IntRange(from = 0) int adIndexInAdGroup,
    Uri uri
)
```

> [!CAUTION]
> **This method is deprecated.**   
>
> Use `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#withAvailableAdMediaItem(int,int,androidx.media3.common.MediaItem)` instead.

### withContentDurationUs

```
public AdPlaybackState withContentDurationUs(long contentDurationUs)
```

Returns an instance with the specified content duration, in microseconds.

### withContentResumeOffsetUs

```
public AdPlaybackState withContentResumeOffsetUs(
    @IntRange(from = 0) int adGroupIndex,
    long contentResumeOffsetUs
)
```

Returns an instance with the specified `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState.AdGroup#contentResumeOffsetUs()`, in microseconds, for the specified ad group.

### withIsServerSideInserted

```
public AdPlaybackState withIsServerSideInserted(
    @IntRange(from = 0) int adGroupIndex,
    boolean isServerSideInserted
)
```

Returns an instance with the specified value for `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState.AdGroup#isServerSideInserted()` in the specified ad group.

### withLastAdRemoved

```
public AdPlaybackState [withLastAdRemoved](https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#withLastAdRemoved(int))(@IntRange(from = 0) int adGroupIndex)
```

> [!CAUTION]
> **This method is deprecated.**   
>
> Use `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#withRemovedAdsAfterIndex(int,int)` instead.

### withLivePostrollPlaceholderAppended

```
@InlineMe(replacement = "this.withLivePostrollPlaceholderAppended(true)")
public AdPlaybackState [withLivePostrollPlaceholderAppended](https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#withLivePostrollPlaceholderAppended())()
```

> [!CAUTION]
> **This method is deprecated.**   
>
> Use `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#withLivePostrollPlaceholderAppended(boolean)` and pass `true` instead.

### withLivePostrollPlaceholderAppended

```
public AdPlaybackState withLivePostrollPlaceholderAppended(boolean isServerSideInserted)
```

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 `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#endsWithLivePostrollPlaceHolder()` and `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#endsWithLivePostrollPlaceHolder(boolean)` also.

| Parameters |
|---|---|
| `boolean isServerSideInserted` | Whether this is a server-side inserted ad (single stream). |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState` | The new ad playback state instance ending with a live postroll placeholder. |

### withNewAdGroup

```
public AdPlaybackState withNewAdGroup(@IntRange(from = 0) int adGroupIndex, long adGroupTimeUs)
```

Returns an instance with a new ad group.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int adGroupIndex` | The insertion index of the new group. |
| `long adGroupTimeUs` | The ad group time, in microseconds, or `https://developer.android.com/reference/androidx/media3/common/C#TIME_END_OF_SOURCE()` to indicate a postroll ad. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState` | The updated ad playback state. |

### withOriginalAdCount

```
public AdPlaybackState withOriginalAdCount(
    @IntRange(from = 0) int adGroupIndex,
    int originalAdCount
)
```

Returns an instance with the specified value for `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState.AdGroup#originalCount()` in the specified ad group.

### withPlayedAd

```
public AdPlaybackState withPlayedAd(
    @IntRange(from = 0) int adGroupIndex,
    @IntRange(from = 0) int adIndexInAdGroup
)
```

Returns an instance with the specified ad marked as `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#AD_STATE_PLAYED()`.

### withRemovedAdGroupCount

```
public AdPlaybackState withRemovedAdGroupCount(@IntRange(from = 0) int removedAdGroupCount)
```

Returns an instance with the specified number of `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#removedAdGroupCount()`.

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

```
public AdPlaybackState withRemovedAdGroupCountBefore(long timeUs)
```

Returns an instance with ad groups removed until and excluding the first post roll ad group or the first ad group with `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState.AdGroup#timeUs()` larger than the given time, in microseconds.

Any ad group with `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState.AdGroup#timeUs()` set to `https://developer.android.com/reference/androidx/media3/common/C#TIME_END_OF_SOURCE()` is considered a post roll ad group.

### withRemovedAdsAfterIndex

```
public AdPlaybackState withRemovedAdsAfterIndex(
    @IntRange(from = 0) int adGroupIndex,
    @IntRange(from = 0) int adIndexInAdGroup
)
```

Returns an instance with ads after `adIndexInAdGroup` removed from the specified ad group.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int adGroupIndex` | The index of the ad group. |
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int adIndexInAdGroup` | The index of the last ad to keep in the ad group. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState` | The updated ad playback state. |

### withResetAdGroup

```
public AdPlaybackState withResetAdGroup(@IntRange(from = 0) int adGroupIndex)
```

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

```
public AdPlaybackState withSkippedAd(
    @IntRange(from = 0) int adGroupIndex,
    @IntRange(from = 0) int adIndexInAdGroup
)
```

Returns an instance with the specified ad marked as `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#AD_STATE_SKIPPED()`.

### withSkippedAdGroup

```
public AdPlaybackState withSkippedAdGroup(@IntRange(from = 0) int adGroupIndex)
```

Returns an instance with all ads in the specified ad group skipped (except for those already marked as played or in the error state).

### withUnavailableAdGroup

```
public AdPlaybackState withUnavailableAdGroup(@IntRange(from = 0) int adGroupIndex)
```

Returns an instance with all ads in the specified ad group made unavailable.

See `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState.AdGroup#withAllAdsUnavailable()` also.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int adGroupIndex` | The index of the ad group. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState` | The updated ad playback state. |