# AdsMediaSource

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

*** ** * ** ***


```
@UnstableApi
public final class AdsMediaSource extends CompositeMediaSource<MediaSource.MediaPeriodId>
```

<br />

|---|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) ||||
| ↳ | [androidx.media3.exoplayer.source.BaseMediaSource](https://developer.android.com/reference/androidx/media3/exoplayer/source/BaseMediaSource) |||
|   | ↳ | [androidx.media3.exoplayer.source.CompositeMediaSource](https://developer.android.com/reference/androidx/media3/exoplayer/source/CompositeMediaSource)\<[MediaSource.MediaPeriodId](https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId)\> ||
|   |   | ↳ | [androidx.media3.exoplayer.source.ads.AdsMediaSource](https://developer.android.com/reference/androidx/media3/exoplayer/source/ads/AdsMediaSource) |

*** ** * ** ***

A `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource` that inserts ads linearly into a provided content media source.

The wrapped content media source can contain multiple `https://developer.android.com/reference/androidx/media3/common/Timeline.Period`. The ad group times in the `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState` provided by the `https://developer.android.com/reference/androidx/media3/exoplayer/source/ads/AdsLoader` must be relative to the start of the first period of the content timeline. Note that multi-period ad insertion is not supported by all `https://developer.android.com/reference/androidx/media3/exoplayer/source/ads/AdsLoader` implementations (for example, the IMA extension's `ImaAdsLoader` only supports single-period Timelines).

## Summary

| ### Nested types |
|---|
| `public final class https://developer.android.com/reference/androidx/media3/exoplayer/source/ads/AdsMediaSource.AdLoadException extends https://developer.android.com/reference/java/io/IOException.html` Wrapper for exceptions that occur while loading ads, which are notified via `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSourceEventListener#onLoadError(int,androidx.media3.exoplayer.source.MediaSource.MediaPeriodId,androidx.media3.exoplayer.source.LoadEventInfo,androidx.media3.exoplayer.source.MediaLoadData,java.io.IOException,boolean)`. |
| `@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/java/lang/annotation/ElementType.html#TYPE_USE) @https://developer.android.com/reference/androidx/annotation/IntDef(value = ) public annotation https://developer.android.com/reference/androidx/media3/exoplayer/source/ads/AdsMediaSource.AdLoadException.Type` Types of ad load exceptions. |

| ### Public fields |
|---|---|
| `final https://developer.android.com/reference/java/lang/Object.html` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/ads/AdsMediaSource#adsId()` |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/ads/AdsMediaSource#AdsMediaSource(androidx.media3.exoplayer.source.MediaSource,androidx.media3.datasource.DataSpec,java.lang.Object,androidx.media3.exoplayer.source.MediaSource.Factory,androidx.media3.exoplayer.source.ads.AdsLoader,androidx.media3.common.AdViewProvider)( https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource contentMediaSource, https://developer.android.com/reference/androidx/media3/datasource/DataSpec adTagDataSpec, https://developer.android.com/reference/java/lang/Object.html adsId, https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.Factory adMediaSourceFactory, https://developer.android.com/reference/androidx/media3/exoplayer/source/ads/AdsLoader adsLoader, https://developer.android.com/reference/androidx/media3/common/AdViewProvider adViewProvider )` Constructs a new source that inserts ads linearly with the content specified by ` contentMediaSource`. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/ads/AdsMediaSource#AdsMediaSource(androidx.media3.exoplayer.source.MediaSource,androidx.media3.datasource.DataSpec,java.lang.Object,androidx.media3.exoplayer.source.MediaSource.Factory,androidx.media3.exoplayer.source.ads.AdsLoader,androidx.media3.common.AdViewProvider,boolean,boolean)( https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource contentMediaSource, https://developer.android.com/reference/androidx/media3/datasource/DataSpec adTagDataSpec, https://developer.android.com/reference/java/lang/Object.html adsId, https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.Factory adMediaSourceFactory, https://developer.android.com/reference/androidx/media3/exoplayer/source/ads/AdsLoader adsLoader, https://developer.android.com/reference/androidx/media3/common/AdViewProvider adViewProvider, boolean useLazyContentSourcePreparation, boolean useAdMediaSourceClipping )` Constructs a new source that inserts ads linearly with the content specified by ` contentMediaSource`. |

| ### Public methods |
|---|---|
| `boolean` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/ads/AdsMediaSource#canUpdateMediaItem(androidx.media3.common.MediaItem)(https://developer.android.com/reference/androidx/media3/common/MediaItem mediaItem)` Returns whether the `https://developer.android.com/reference/androidx/media3/common/MediaItem` for this source can be updated with the provided item. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaPeriod` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/ads/AdsMediaSource#createPeriod(androidx.media3.exoplayer.source.MediaSource.MediaPeriodId,androidx.media3.exoplayer.upstream.Allocator,long)( https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId id, https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Allocator allocator, long startPositionUs )` Returns a new `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaPeriod` identified by `periodId`. |
| `https://developer.android.com/reference/java/lang/Object.html` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/ads/AdsMediaSource#getAdsId()()` Returns the ads ID this source is serving. |
| `https://developer.android.com/reference/androidx/media3/common/MediaItem` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/ads/AdsMediaSource#getMediaItem()()` Returns the `https://developer.android.com/reference/androidx/media3/common/MediaItem` whose media is provided by the source. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/ads/AdsMediaSource#releasePeriod(androidx.media3.exoplayer.source.MediaPeriod)(https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaPeriod mediaPeriod)` Releases the period. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/ads/AdsMediaSource#updateMediaItem(androidx.media3.common.MediaItem)(https://developer.android.com/reference/androidx/media3/common/MediaItem mediaItem)` Updates the `https://developer.android.com/reference/androidx/media3/common/MediaItem` for this source. |

| ### Protected methods |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/ads/AdsMediaSource#getMediaPeriodIdForChildMediaPeriodId(androidx.media3.exoplayer.source.MediaSource.MediaPeriodId,androidx.media3.exoplayer.source.MediaSource.MediaPeriodId)( https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId childSourceId, https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId mediaPeriodId )` Returns the `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId` in the composite source corresponding to the specified `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId` in a child source. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/ads/AdsMediaSource#onChildSourceInfoRefreshed(androidx.media3.exoplayer.source.MediaSource.MediaPeriodId,androidx.media3.exoplayer.source.MediaSource,androidx.media3.common.Timeline)( https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId childSourceId, https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource mediaSource, https://developer.android.com/reference/androidx/media3/common/Timeline newTimeline )` Called when the source info of a child source has been refreshed. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/ads/AdsMediaSource#prepareSourceInternal(androidx.media3.datasource.TransferListener)(@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/datasource/TransferListener mediaTransferListener)` Starts source preparation and enables the source, see `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource#prepareSource(androidx.media3.exoplayer.source.MediaSource.MediaSourceCaller,androidx.media3.exoplayer.analytics.PlayerId,androidx.media3.exoplayer.upstream.BandwidthMeter)`. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/ads/AdsMediaSource#releaseSourceInternal()()` Releases the source, see `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource#releaseSource(androidx.media3.exoplayer.source.MediaSource.MediaSourceCaller)`. |

### Inherited fields

From [androidx.media3.exoplayer.source.BaseMediaSource](https://developer.android.com/reference/androidx/media3/exoplayer/source/BaseMediaSource) `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/exoplayer/upstream/BandwidthMeter` `https://developer.android.com/reference/androidx/media3/exoplayer/source/BaseMediaSource#bandwidthMeter()` `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/exoplayer/analytics/PlayerId` `https://developer.android.com/reference/androidx/media3/exoplayer/source/BaseMediaSource#playerId()`

### Inherited methods

From [androidx.media3.exoplayer.source.BaseMediaSource](https://developer.android.com/reference/androidx/media3/exoplayer/source/BaseMediaSource) `final void` `@https://developer.android.com/reference/androidx/media3/common/util/UnstableApi
https://developer.android.com/reference/androidx/media3/exoplayer/source/BaseMediaSource#addDrmEventListener(android.os.Handler,androidx.media3.exoplayer.drm.DrmSessionEventListener)(
https://developer.android.com/reference/android/os/Handler.html handler,
https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSessionEventListener eventListener
)`

Adds a `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSessionEventListener` to the list of listeners which are notified of DRM events for this media source.
`final void` `@https://developer.android.com/reference/androidx/media3/common/util/UnstableApi
https://developer.android.com/reference/androidx/media3/exoplayer/source/BaseMediaSource#addEventListener(android.os.Handler,androidx.media3.exoplayer.source.MediaSourceEventListener)(
https://developer.android.com/reference/android/os/Handler.html handler,
https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSourceEventListener eventListener
)`

Adds a `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSourceEventListener` to the list of listeners which are notified of media source events.
`final https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSessionEventListener.EventDispatcher` `https://developer.android.com/reference/androidx/media3/exoplayer/source/BaseMediaSource#createDrmEventDispatcher(androidx.media3.exoplayer.source.MediaSource.MediaPeriodId)(
@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId mediaPeriodId
)`

Returns a `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSessionEventListener.EventDispatcher` which dispatches all events to the registered listeners with the specified `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId`
`final https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSessionEventListener.EventDispatcher` `https://developer.android.com/reference/androidx/media3/exoplayer/source/BaseMediaSource#createDrmEventDispatcher(int,androidx.media3.exoplayer.source.MediaSource.MediaPeriodId)(
int windowIndex,
@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId mediaPeriodId
)`

Returns a `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSessionEventListener.EventDispatcher` which dispatches all events to the registered listeners with the specified window index and `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId`.
`final https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSourceEventListener.EventDispatcher` `https://developer.android.com/reference/androidx/media3/exoplayer/source/BaseMediaSource#createEventDispatcher(androidx.media3.exoplayer.source.MediaSource.MediaPeriodId)(@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId mediaPeriodId)`

Returns a `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSourceEventListener.EventDispatcher` which dispatches all events to the registered listeners with the specified `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId`.
`final https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSourceEventListener.EventDispatcher` `[createEventDispatcher](https://developer.android.com/reference/androidx/media3/exoplayer/source/BaseMediaSource#createEventDispatcher(androidx.media3.exoplayer.source.MediaSource.MediaPeriodId,long))(
https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId mediaPeriodId,
long mediaTimeOffsetMs
)`

**This method is deprecated.**

Use `https://developer.android.com/reference/androidx/media3/exoplayer/source/BaseMediaSource#createEventDispatcher(androidx.media3.exoplayer.source.MediaSource.MediaPeriodId)` instead.

<br />

`final https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSourceEventListener.EventDispatcher` `https://developer.android.com/reference/androidx/media3/exoplayer/source/BaseMediaSource#createEventDispatcher(int,androidx.media3.exoplayer.source.MediaSource.MediaPeriodId)(
int windowIndex,
@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId mediaPeriodId
)`

Returns a `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSourceEventListener.EventDispatcher` which dispatches all events to the registered listeners with the specified window index and `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId`.
`final https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSourceEventListener.EventDispatcher` `[createEventDispatcher](https://developer.android.com/reference/androidx/media3/exoplayer/source/BaseMediaSource#createEventDispatcher(int,androidx.media3.exoplayer.source.MediaSource.MediaPeriodId,long))(
int windowIndex,
@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId mediaPeriodId,
long mediaTimeOffsetMs
)`

**This method is deprecated.**

Use `https://developer.android.com/reference/androidx/media3/exoplayer/source/BaseMediaSource#createEventDispatcher(int,androidx.media3.exoplayer.source.MediaSource.MediaPeriodId)` instead.

<br />

`final void` `@https://developer.android.com/reference/androidx/media3/common/util/UnstableApi
https://developer.android.com/reference/androidx/media3/exoplayer/source/BaseMediaSource#disable(androidx.media3.exoplayer.source.MediaSource.MediaSourceCaller)(https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaSourceCaller caller)`

Disables the source for the creation of `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaPeriod`.
`final void` `@https://developer.android.com/reference/androidx/media3/common/util/UnstableApi
https://developer.android.com/reference/androidx/media3/exoplayer/source/BaseMediaSource#enable(androidx.media3.exoplayer.source.MediaSource.MediaSourceCaller)(https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaSourceCaller caller)`

Enables the source for the creation of `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaPeriod`.
`final https://developer.android.com/reference/androidx/media3/exoplayer/upstream/BandwidthMeter` `https://developer.android.com/reference/androidx/media3/exoplayer/source/BaseMediaSource#getBandwidthMeter()()`

Returns the `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/BandwidthMeter` that is used by this media source.
`final https://developer.android.com/reference/androidx/media3/exoplayer/analytics/PlayerId` `https://developer.android.com/reference/androidx/media3/exoplayer/source/BaseMediaSource#getPlayerId()()`

Returns the `https://developer.android.com/reference/androidx/media3/exoplayer/analytics/PlayerId` of the player using this media source.
`final boolean` `https://developer.android.com/reference/androidx/media3/exoplayer/source/BaseMediaSource#isEnabled()()`

Returns whether the source is enabled.
`final void` `@https://developer.android.com/reference/androidx/media3/common/util/UnstableApi
https://developer.android.com/reference/androidx/media3/exoplayer/source/BaseMediaSource#prepareSource(androidx.media3.exoplayer.source.MediaSource.MediaSourceCaller,androidx.media3.exoplayer.analytics.PlayerId,androidx.media3.exoplayer.upstream.BandwidthMeter)(
https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaSourceCaller caller,
https://developer.android.com/reference/androidx/media3/exoplayer/analytics/PlayerId playerId,
https://developer.android.com/reference/androidx/media3/exoplayer/upstream/BandwidthMeter bandwidthMeter
)`

Registers a `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaSourceCaller`.
`final boolean` `https://developer.android.com/reference/androidx/media3/exoplayer/source/BaseMediaSource#prepareSourceCalled()()`

Returns whether the source has `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource#prepareSource(androidx.media3.exoplayer.source.MediaSource.MediaSourceCaller,androidx.media3.exoplayer.analytics.PlayerId,androidx.media3.exoplayer.upstream.BandwidthMeter)` called.
`final void` `https://developer.android.com/reference/androidx/media3/exoplayer/source/BaseMediaSource#refreshSourceInfo(androidx.media3.common.Timeline)(https://developer.android.com/reference/androidx/media3/common/Timeline timeline)`

Updates timeline and manifest and notifies all listeners of the update.
`final void` `@https://developer.android.com/reference/androidx/media3/common/util/UnstableApi
https://developer.android.com/reference/androidx/media3/exoplayer/source/BaseMediaSource#releaseSource(androidx.media3.exoplayer.source.MediaSource.MediaSourceCaller)(https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaSourceCaller caller)`

Unregisters a caller, and disables and releases the source if no longer required.
`final void` `@https://developer.android.com/reference/androidx/media3/common/util/UnstableApi
https://developer.android.com/reference/androidx/media3/exoplayer/source/BaseMediaSource#removeDrmEventListener(androidx.media3.exoplayer.drm.DrmSessionEventListener)(https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSessionEventListener eventListener)`

Removes a `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSessionEventListener` from the list of listeners which are notified of DRM events for this media source.
`final void` `@https://developer.android.com/reference/androidx/media3/common/util/UnstableApi
https://developer.android.com/reference/androidx/media3/exoplayer/source/BaseMediaSource#removeEventListener(androidx.media3.exoplayer.source.MediaSourceEventListener)(https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSourceEventListener eventListener)`

Removes a `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSourceEventListener` from the list of listeners which are notified of media source events.
`final void` `https://developer.android.com/reference/androidx/media3/exoplayer/source/BaseMediaSource#setBandwidthMeter(androidx.media3.exoplayer.upstream.BandwidthMeter)(https://developer.android.com/reference/androidx/media3/exoplayer/upstream/BandwidthMeter bandwidthMeter)`

Sets the `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/BandwidthMeter` to be used by this media source.
`final void` `https://developer.android.com/reference/androidx/media3/exoplayer/source/BaseMediaSource#setPlayerId(androidx.media3.exoplayer.analytics.PlayerId)(https://developer.android.com/reference/androidx/media3/exoplayer/analytics/PlayerId playerId)`

Sets the `https://developer.android.com/reference/androidx/media3/exoplayer/analytics/PlayerId` of the player using this media source.
From [androidx.media3.exoplayer.source.CompositeMediaSource](https://developer.android.com/reference/androidx/media3/exoplayer/source/CompositeMediaSource) `final void` `https://developer.android.com/reference/androidx/media3/exoplayer/source/CompositeMediaSource#disableChildSource(T)(@https://developer.android.com/reference/androidx/media3/common/util/UnknownNull T id)`

Disables a child source.
`void` `@https://developer.android.com/reference/androidx/annotation/CallSuper
https://developer.android.com/reference/androidx/media3/exoplayer/source/CompositeMediaSource#disableInternal()()`

Disables the source, see `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource#disable(androidx.media3.exoplayer.source.MediaSource.MediaSourceCaller)`.
`final void` `https://developer.android.com/reference/androidx/media3/exoplayer/source/CompositeMediaSource#enableChildSource(T)(@https://developer.android.com/reference/androidx/media3/common/util/UnknownNull T id)`

Enables a child source.
`void` `@https://developer.android.com/reference/androidx/annotation/CallSuper
https://developer.android.com/reference/androidx/media3/exoplayer/source/CompositeMediaSource#enableInternal()()`

Enables the source, see `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource#enable(androidx.media3.exoplayer.source.MediaSource.MediaSourceCaller)`.
`long` `https://developer.android.com/reference/androidx/media3/exoplayer/source/CompositeMediaSource#getMediaTimeForChildMediaTime(T,long,androidx.media3.exoplayer.source.MediaSource.MediaPeriodId)(
@https://developer.android.com/reference/androidx/media3/common/util/UnknownNull T childSourceId,
long mediaTimeMs,
@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId mediaPeriodId
)`

Returns the media time in the `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaPeriod` of the composite source corresponding to the specified media time in the `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaPeriod` of the child source.
`int` `https://developer.android.com/reference/androidx/media3/exoplayer/source/CompositeMediaSource#getWindowIndexForChildWindowIndex(T,int)(
@https://developer.android.com/reference/androidx/media3/common/util/UnknownNull T childSourceId,
int windowIndex
)`

Returns the window index in the composite source corresponding to the specified window index in a child source.
`void` `@https://developer.android.com/reference/androidx/annotation/CallSuper
https://developer.android.com/reference/androidx/media3/exoplayer/source/CompositeMediaSource#maybeThrowSourceInfoRefreshError()()`

Throws any pending error encountered while loading or refreshing source information.
`final void` `https://developer.android.com/reference/androidx/media3/exoplayer/source/CompositeMediaSource#prepareChildSource(T,androidx.media3.exoplayer.source.MediaSource)(@https://developer.android.com/reference/androidx/media3/common/util/UnknownNull T id, https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource mediaSource)`

Prepares a child source.
`final void` `https://developer.android.com/reference/androidx/media3/exoplayer/source/CompositeMediaSource#releaseChildSource(T)(@https://developer.android.com/reference/androidx/media3/common/util/UnknownNull T id)`

Releases a child source.
From [androidx.media3.exoplayer.source.MediaSource](https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource) `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/common/Timeline` `@https://developer.android.com/reference/androidx/media3/common/util/UnstableApi
https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource#getInitialTimeline()()`

Returns the initial placeholder timeline that is returned immediately when the real timeline is not yet known, or null to let the player create an initial timeline.
`boolean` `@https://developer.android.com/reference/androidx/media3/common/util/UnstableApi
https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource#isSingleWindow()()`

Returns true if the media source is guaranteed to never have zero or more than one window.
`void` `@https://developer.android.com/reference/androidx/media3/common/util/UnstableApi
[prepareSource](https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource#prepareSource(androidx.media3.exoplayer.source.MediaSource.MediaSourceCaller,androidx.media3.datasource.TransferListener,androidx.media3.exoplayer.analytics.PlayerId))(
https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaSourceCaller caller,
@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/datasource/TransferListener mediaTransferListener,
https://developer.android.com/reference/androidx/media3/exoplayer/analytics/PlayerId playerId
)`

**This method is deprecated.**

Use `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource#prepareSource(androidx.media3.exoplayer.source.MediaSource.MediaSourceCaller,androidx.media3.exoplayer.analytics.PlayerId,androidx.media3.exoplayer.upstream.BandwidthMeter)` instead.

<br />

## Public fields

### adsId

```
public final Object adsId
```

## Public constructors

### AdsMediaSource

```
public AdsMediaSource(
    MediaSource contentMediaSource,
    DataSpec adTagDataSpec,
    Object adsId,
    MediaSource.Factory adMediaSourceFactory,
    AdsLoader adsLoader,
    AdViewProvider adViewProvider
)
```

Constructs a new source that inserts ads linearly with the content specified by `
contentMediaSource`.

This is equivalent to passing `true` as param `useLazyContentSourcePreparation` and `false` as param `useAdMediaSourceClipping` when calling `https://developer.android.com/reference/androidx/media3/exoplayer/source/ads/AdsMediaSource#AdsMediaSource(androidx.media3.exoplayer.source.MediaSource,androidx.media3.datasource.DataSpec,java.lang.Object,androidx.media3.exoplayer.source.MediaSource.Factory,androidx.media3.exoplayer.source.ads.AdsLoader,androidx.media3.common.AdViewProvider,boolean,boolean)`.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource contentMediaSource` | The `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource` providing the content to play. |
| `https://developer.android.com/reference/androidx/media3/datasource/DataSpec adTagDataSpec` | The data specification of the ad tag to load. |
| `https://developer.android.com/reference/java/lang/Object.html adsId` | An opaque identifier for ad playback state associated with this instance. Ad loading and playback state is shared among all playlist items that have the same ads id (by `https://developer.android.com/reference/java/lang/Object.html#equals(java.lang.Object)`), so it is important to pass the same identifiers when constructing playlist items each time the player returns to the foreground. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.Factory adMediaSourceFactory` | Factory for media sources used to load ad media. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/ads/AdsLoader adsLoader` | The loader for ads. |
| `https://developer.android.com/reference/androidx/media3/common/AdViewProvider adViewProvider` | Provider of views for the ad UI. |

### AdsMediaSource

```
public AdsMediaSource(
    MediaSource contentMediaSource,
    DataSpec adTagDataSpec,
    Object adsId,
    MediaSource.Factory adMediaSourceFactory,
    AdsLoader adsLoader,
    AdViewProvider adViewProvider,
    boolean useLazyContentSourcePreparation,
    boolean useAdMediaSourceClipping
)
```

Constructs a new source that inserts ads linearly with the content specified by `
contentMediaSource`.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource contentMediaSource` | The `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource` providing the content to play. |
| `https://developer.android.com/reference/androidx/media3/datasource/DataSpec adTagDataSpec` | The data specification of the ad tag to load. |
| `https://developer.android.com/reference/java/lang/Object.html adsId` | An opaque identifier for ad playback state associated with this instance. Ad loading and playback state is shared among all playlist items that have the same ads id (by `https://developer.android.com/reference/java/lang/Object.html#equals(java.lang.Object)`), so it is important to pass the same identifiers when constructing playlist items each time the player returns to the foreground. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.Factory adMediaSourceFactory` | Factory for media sources used to load ad media. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/ads/AdsLoader adsLoader` | The loader for ads. |
| `https://developer.android.com/reference/androidx/media3/common/AdViewProvider adViewProvider` | Provider of views for the ad UI. |
| `boolean useLazyContentSourcePreparation` | `true` if the content source should be prepared lazily and wait for an `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState` to be set before preparing. `false` if the timeline is required `https://developer.android.com/reference/androidx/media3/exoplayer/source/ads/AdsLoader#handleContentTimelineChanged(androidx.media3.exoplayer.source.ads.AdsMediaSource,androidx.media3.common.Timeline)` to populate the `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState` (See `https://developer.android.com/reference/androidx/media3/common/Timeline.Window#manifest()` also). |
| `boolean useAdMediaSourceClipping` | Whether ad sources should be clipped to the duration declared in the `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState#withAdDurationsUs(int,long...)`. If `false`, the ad sources are played to end of stream. |

## Public methods

### canUpdateMediaItem

```
public boolean canUpdateMediaItem(MediaItem mediaItem)
```

Returns whether the `https://developer.android.com/reference/androidx/media3/common/MediaItem` for this source can be updated with the provided item.

Should not be called directly from application code.

This method must be called on the application thread.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/MediaItem mediaItem` | The new `https://developer.android.com/reference/androidx/media3/common/MediaItem`. |

| Returns |
|---|---|
| `boolean` | Whether the source can be updated using this item. |

### createPeriod

```
public MediaPeriod createPeriod(
    MediaSource.MediaPeriodId id,
    Allocator allocator,
    long startPositionUs
)
```

Returns a new `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaPeriod` identified by `periodId`.

Should not be called directly from application code.

This method must be called on the playback thread and only if the source is enabled.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId id` | The identifier of the period. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Allocator allocator` | An `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Allocator` from which to obtain media buffer allocations. |
| `long startPositionUs` | The expected start position, in microseconds. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaPeriod` | A new `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaPeriod`. |

### getAdsId

```
public Object getAdsId()
```

Returns the ads ID this source is serving.

### getMediaItem

```
public MediaItem getMediaItem()
```

Returns the `https://developer.android.com/reference/androidx/media3/common/MediaItem` whose media is provided by the source.

Should not be called directly from application code.

This method must be called on the application thread.

### releasePeriod

```
public void releasePeriod(MediaPeriod mediaPeriod)
```

Releases the period.

Should not be called directly from application code.

This method must be called on the playback thread.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaPeriod mediaPeriod` | The period to release. |

### updateMediaItem

```
public void updateMediaItem(MediaItem mediaItem)
```

Updates the `https://developer.android.com/reference/androidx/media3/common/MediaItem` for this source.

Should not be called directly from application code.

This method must be called on the playback thread and only if `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource#canUpdateMediaItem(androidx.media3.common.MediaItem)` returns `true` for the new `https://developer.android.com/reference/androidx/media3/common/MediaItem`.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/MediaItem mediaItem` | The new `https://developer.android.com/reference/androidx/media3/common/MediaItem`. |

## Protected methods

### getMediaPeriodIdForChildMediaPeriodId

```
protected MediaSource.MediaPeriodId getMediaPeriodIdForChildMediaPeriodId(
    MediaSource.MediaPeriodId childSourceId,
    MediaSource.MediaPeriodId mediaPeriodId
)
```

Returns the `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId` in the composite source corresponding to the specified `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId` in a child source. The default implementation does not change the media period id.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId childSourceId` | The unique id used to prepare the child source. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId mediaPeriodId` | A `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId` of the child source. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId` | The corresponding `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId` in the composite source. Null if no corresponding media period id can be determined. |

### onChildSourceInfoRefreshed

```
protected void onChildSourceInfoRefreshed(
    MediaSource.MediaPeriodId childSourceId,
    MediaSource mediaSource,
    Timeline newTimeline
)
```

Called when the source info of a child source has been refreshed.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId childSourceId` | The unique id used to prepare the child source. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource mediaSource` | The child source whose source info has been refreshed. |
| `https://developer.android.com/reference/androidx/media3/common/Timeline newTimeline` | The timeline of the child source. |

### prepareSourceInternal

```
protected void prepareSourceInternal(@Nullable TransferListener mediaTransferListener)
```

Starts source preparation and enables the source, see `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource#prepareSource(androidx.media3.exoplayer.source.MediaSource.MediaSourceCaller,androidx.media3.exoplayer.analytics.PlayerId,androidx.media3.exoplayer.upstream.BandwidthMeter)`. This method is called at most once until the next call to `https://developer.android.com/reference/androidx/media3/exoplayer/source/BaseMediaSource#releaseSourceInternal()`.

This method is called on the playback thread.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/datasource/TransferListener mediaTransferListener` | The transfer listener which should be informed of any media data transfers. May be null if no listener is available. Note that this listener should usually be only informed of transfers related to the media loads and not of auxiliary loads for manifests and other data. |

### releaseSourceInternal

```
protected void releaseSourceInternal()
```

Releases the source, see `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource#releaseSource(androidx.media3.exoplayer.source.MediaSource.MediaSourceCaller)`. This method is called exactly once after each call to `https://developer.android.com/reference/androidx/media3/exoplayer/source/BaseMediaSource#prepareSourceInternal(androidx.media3.datasource.TransferListener)`.

This method is called on the playback thread.