# ServerSideAdInsertionMediaSource

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/ServerSideAdInsertionMediaSource.java+class:androidx.media3.exoplayer.source.ads.ServerSideAdInsertionMediaSource)

*** ** * ** ***

<br />

```
@UnstableApi
public final class ServerSideAdInsertionMediaSource extends BaseMediaSource implements MediaSource.MediaSourceCaller, MediaSourceEventListener, DrmSessionEventListener
```

<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.ads.ServerSideAdInsertionMediaSource](https://developer.android.com/reference/androidx/media3/exoplayer/source/ads/ServerSideAdInsertionMediaSource) |

*** ** * ** ***

A `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource` for server-side inserted ad breaks.

The media source publishes a `https://developer.android.com/reference/androidx/media3/common/Timeline` for the wrapped `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource` with the server-side inserted ad breaks and ensures that playback continues seamlessly with the wrapped media across all transitions.

The ad breaks need to be specified using `https://developer.android.com/reference/androidx/media3/exoplayer/source/ads/ServerSideAdInsertionMediaSource#setAdPlaybackStates(com.google.common.collect.ImmutableMap<java.lang.Object,androidx.media3.common.AdPlaybackState>,androidx.media3.common.Timeline)` and can be updated during playback.

## Summary

| ### Nested types |
|---|
| `public interface https://developer.android.com/reference/androidx/media3/exoplayer/source/ads/ServerSideAdInsertionMediaSource.AdPlaybackStateUpdater` Receives ad playback state update requests when the `https://developer.android.com/reference/androidx/media3/common/Timeline` of the content media source has changed. |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/ads/ServerSideAdInsertionMediaSource#ServerSideAdInsertionMediaSource(androidx.media3.exoplayer.source.MediaSource,androidx.media3.exoplayer.source.ads.ServerSideAdInsertionMediaSource.AdPlaybackStateUpdater)( https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource mediaSource, @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/exoplayer/source/ads/ServerSideAdInsertionMediaSource.AdPlaybackStateUpdater adPlaybackStateUpdater )` Creates the media source. |

| ### Public methods |
|---|---|
| `boolean` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/ads/ServerSideAdInsertionMediaSource#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/ServerSideAdInsertionMediaSource#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/androidx/media3/common/MediaItem` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/ads/ServerSideAdInsertionMediaSource#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/ServerSideAdInsertionMediaSource#maybeThrowSourceInfoRefreshError()()` Throws any pending error encountered while loading or refreshing source information. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/ads/ServerSideAdInsertionMediaSource#onDownstreamFormatChanged(int,androidx.media3.exoplayer.source.MediaSource.MediaPeriodId,androidx.media3.exoplayer.source.MediaLoadData)( int windowIndex, @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId mediaPeriodId, https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaLoadData mediaLoadData )` Called when a downstream format change occurs (i.e. when the format of the media being read from one or more `https://developer.android.com/reference/androidx/media3/exoplayer/source/SampleStream`s provided by the source changes). |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/ads/ServerSideAdInsertionMediaSource#onDrmKeysLoaded(int,androidx.media3.exoplayer.source.MediaSource.MediaPeriodId,androidx.media3.exoplayer.drm.KeyRequestInfo)( int windowIndex, @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId mediaPeriodId, https://developer.android.com/reference/androidx/media3/exoplayer/drm/KeyRequestInfo keyRequestInfo )` Called each time keys are loaded. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/ads/ServerSideAdInsertionMediaSource#onDrmKeysRemoved(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 )` Called each time offline keys are removed. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/ads/ServerSideAdInsertionMediaSource#onDrmKeysRestored(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 )` Called each time offline keys are restored. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/ads/ServerSideAdInsertionMediaSource#onDrmSessionAcquired(int,androidx.media3.exoplayer.source.MediaSource.MediaPeriodId,int)( int windowIndex, @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId mediaPeriodId, @https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSession.State int state )` Called each time a drm session is acquired. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/ads/ServerSideAdInsertionMediaSource#onDrmSessionManagerError(int,androidx.media3.exoplayer.source.MediaSource.MediaPeriodId,java.lang.Exception)( int windowIndex, @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId mediaPeriodId, https://developer.android.com/reference/java/lang/Exception.html error )` Called when a drm error occurs. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/ads/ServerSideAdInsertionMediaSource#onDrmSessionReleased(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 )` Called each time a drm session is released. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/ads/ServerSideAdInsertionMediaSource#onLoadCanceled(int,androidx.media3.exoplayer.source.MediaSource.MediaPeriodId,androidx.media3.exoplayer.source.LoadEventInfo,androidx.media3.exoplayer.source.MediaLoadData)( int windowIndex, @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId mediaPeriodId, https://developer.android.com/reference/androidx/media3/exoplayer/source/LoadEventInfo loadEventInfo, https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaLoadData mediaLoadData )` Called when a load is canceled. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/ads/ServerSideAdInsertionMediaSource#onLoadCompleted(int,androidx.media3.exoplayer.source.MediaSource.MediaPeriodId,androidx.media3.exoplayer.source.LoadEventInfo,androidx.media3.exoplayer.source.MediaLoadData)( int windowIndex, @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId mediaPeriodId, https://developer.android.com/reference/androidx/media3/exoplayer/source/LoadEventInfo loadEventInfo, https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaLoadData mediaLoadData )` Called when a load ends. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/ads/ServerSideAdInsertionMediaSource#onLoadError(int,androidx.media3.exoplayer.source.MediaSource.MediaPeriodId,androidx.media3.exoplayer.source.LoadEventInfo,androidx.media3.exoplayer.source.MediaLoadData,java.io.IOException,boolean)( int windowIndex, @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId mediaPeriodId, https://developer.android.com/reference/androidx/media3/exoplayer/source/LoadEventInfo loadEventInfo, https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaLoadData mediaLoadData, https://developer.android.com/reference/java/io/IOException.html error, boolean wasCanceled )` Called when a load error occurs. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/ads/ServerSideAdInsertionMediaSource#onLoadStarted(int,androidx.media3.exoplayer.source.MediaSource.MediaPeriodId,androidx.media3.exoplayer.source.LoadEventInfo,androidx.media3.exoplayer.source.MediaLoadData,int)( int windowIndex, @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId mediaPeriodId, https://developer.android.com/reference/androidx/media3/exoplayer/source/LoadEventInfo loadEventInfo, https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaLoadData mediaLoadData, int retryCount )` Called when a load begins. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/ads/ServerSideAdInsertionMediaSource#onSourceInfoRefreshed(androidx.media3.exoplayer.source.MediaSource,androidx.media3.common.Timeline)(https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource source, https://developer.android.com/reference/androidx/media3/common/Timeline timeline)` Called when the `https://developer.android.com/reference/androidx/media3/common/Timeline` has been refreshed. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/ads/ServerSideAdInsertionMediaSource#onUpstreamDiscarded(int,androidx.media3.exoplayer.source.MediaSource.MediaPeriodId,androidx.media3.exoplayer.source.MediaLoadData)( int windowIndex, https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId mediaPeriodId, https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaLoadData mediaLoadData )` Called when data is removed from the back of a media buffer, typically so that it can be re-buffered in a different format. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/ads/ServerSideAdInsertionMediaSource#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/ServerSideAdInsertionMediaSource#setAdPlaybackStates(com.google.common.collect.ImmutableMap<java.lang.Object,androidx.media3.common.AdPlaybackState>,androidx.media3.common.Timeline)( https://guava.dev/releases/snapshot-android/api/docs/com/google/common/collect/ImmutableMap.html<https://developer.android.com/reference/java/lang/Object.html, https://developer.android.com/reference/androidx/media3/common/AdPlaybackState> adPlaybackStates, https://developer.android.com/reference/androidx/media3/common/Timeline contentTimeline )` Sets the map of `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState` published by this source. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/ads/ServerSideAdInsertionMediaSource#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 |
|---|---|
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/ads/ServerSideAdInsertionMediaSource#disableInternal()()` Disables the source, see `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource#disable(androidx.media3.exoplayer.source.MediaSource.MediaSourceCaller)`. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/ads/ServerSideAdInsertionMediaSource#enableInternal()()` Enables the source, see `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource#enable(androidx.media3.exoplayer.source.MediaSource.MediaSourceCaller)`. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/ads/ServerSideAdInsertionMediaSource#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/ServerSideAdInsertionMediaSource#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.drm.DrmSessionEventListener](https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSessionEventListener) `void` `[onDrmKeysLoaded](https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSessionEventListener#onDrmKeysLoaded(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

)`

**This method is deprecated.**

Implement `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSessionEventListener#onDrmKeysLoaded(int,androidx.media3.exoplayer.source.MediaSource.MediaPeriodId,androidx.media3.exoplayer.drm.KeyRequestInfo)` instead

<br />

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 constructors

### ServerSideAdInsertionMediaSource

```
public ServerSideAdInsertionMediaSource(
    MediaSource mediaSource,
    @Nullable ServerSideAdInsertionMediaSource.AdPlaybackStateUpdater adPlaybackStateUpdater
)
```

Creates the media source.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource mediaSource` | The `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource` to wrap. |
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/exoplayer/source/ads/ServerSideAdInsertionMediaSource.AdPlaybackStateUpdater adPlaybackStateUpdater` | The optional `https://developer.android.com/reference/androidx/media3/exoplayer/source/ads/ServerSideAdInsertionMediaSource.AdPlaybackStateUpdater` to be called before a source refresh is published. |

## 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`. |

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

### maybeThrowSourceInfoRefreshError

```
public void maybeThrowSourceInfoRefreshError()
```

Throws any pending error encountered while loading or refreshing source information.

Should not be called directly from application code.

This method must be called on the playback thread and only after `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)`.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` |   |

### onDownstreamFormatChanged

```
public void onDownstreamFormatChanged(
    int windowIndex,
    @Nullable MediaSource.MediaPeriodId mediaPeriodId,
    MediaLoadData mediaLoadData
)
```

Called when a downstream format change occurs (i.e. when the format of the media being read from one or more `https://developer.android.com/reference/androidx/media3/exoplayer/source/SampleStream`s provided by the source changes).

| Parameters |
|---|---|
| `int windowIndex` | The window index in the timeline of the media source this load belongs to. |
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId mediaPeriodId` | The `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId` the media belongs to. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaLoadData mediaLoadData` | The `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaLoadData` defining the newly selected downstream data. |

### onDrmKeysLoaded

```
public void onDrmKeysLoaded(
    int windowIndex,
    @Nullable MediaSource.MediaPeriodId mediaPeriodId,
    KeyRequestInfo keyRequestInfo
)
```

Called each time keys are loaded.

| Parameters |
|---|---|
| `int windowIndex` | The window index in the timeline this media period belongs to. |
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId mediaPeriodId` | The `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId` associated with the drm session. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/drm/KeyRequestInfo keyRequestInfo` | The `https://developer.android.com/reference/androidx/media3/exoplayer/drm/KeyRequestInfo` with load info for the drm server requests |

### onDrmKeysRemoved

```
public void onDrmKeysRemoved(
    int windowIndex,
    @Nullable MediaSource.MediaPeriodId mediaPeriodId
)
```

Called each time offline keys are removed.

| Parameters |
|---|---|
| `int windowIndex` | The window index in the timeline this media period belongs to. |
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId mediaPeriodId` | The `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId` associated with the drm session. |

### onDrmKeysRestored

```
public void onDrmKeysRestored(
    int windowIndex,
    @Nullable MediaSource.MediaPeriodId mediaPeriodId
)
```

Called each time offline keys are restored.

| Parameters |
|---|---|
| `int windowIndex` | The window index in the timeline this media period belongs to. |
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId mediaPeriodId` | The `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId` associated with the drm session. |

### onDrmSessionAcquired

```
public void onDrmSessionAcquired(
    int windowIndex,
    @Nullable MediaSource.MediaPeriodId mediaPeriodId,
    @DrmSession.State int state
)
```

Called each time a drm session is acquired.

| Parameters |
|---|---|
| `int windowIndex` | The window index in the timeline this media period belongs to. |
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId mediaPeriodId` | The `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId` associated with the drm session. |
| `@https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSession.State int state` | The `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSession.State` of the session when the acquisition completed. |

### onDrmSessionManagerError

```
public void onDrmSessionManagerError(
    int windowIndex,
    @Nullable MediaSource.MediaPeriodId mediaPeriodId,
    Exception error
)
```

Called when a drm error occurs.

This method being called does not indicate that playback has failed, or that it will fail. The player may be able to recover from the error and continue. Hence applications should *not* implement this method to display a user visible error or initiate an application level retry (`https://developer.android.com/reference/androidx/media3/common/Player.Listener#onPlayerError(androidx.media3.common.PlaybackException)` is the appropriate place to implement such behavior). This method is called to provide the application with an opportunity to log the error if it wishes to do so.

| Parameters |
|---|---|
| `int windowIndex` | The window index in the timeline this media period belongs to. |
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId mediaPeriodId` | The `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId` associated with the drm session. |
| `https://developer.android.com/reference/java/lang/Exception.html error` | The corresponding exception. |

### onDrmSessionReleased

```
public void onDrmSessionReleased(
    int windowIndex,
    @Nullable MediaSource.MediaPeriodId mediaPeriodId
)
```

Called each time a drm session is released.

| Parameters |
|---|---|
| `int windowIndex` | The window index in the timeline this media period belongs to. |
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId mediaPeriodId` | The `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId` associated with the drm session. |

### onLoadCanceled

```
public void onLoadCanceled(
    int windowIndex,
    @Nullable MediaSource.MediaPeriodId mediaPeriodId,
    LoadEventInfo loadEventInfo,
    MediaLoadData mediaLoadData
)
```

Called when a load is canceled.

| Parameters |
|---|---|
| `int windowIndex` | The window index in the timeline of the media source this load belongs to. |
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId mediaPeriodId` | The `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId` this load belongs to. Null if the load does not belong to a specific media period. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/LoadEventInfo loadEventInfo` | The `https://developer.android.com/reference/androidx/media3/exoplayer/source/LoadEventInfo` corresponding to the event. The values of `https://developer.android.com/reference/androidx/media3/exoplayer/source/LoadEventInfo#elapsedRealtimeMs()` and `https://developer.android.com/reference/androidx/media3/exoplayer/source/LoadEventInfo#bytesLoaded()` are relative to the corresponding `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSourceEventListener#onLoadStarted(int,androidx.media3.exoplayer.source.MediaSource.MediaPeriodId,androidx.media3.exoplayer.source.LoadEventInfo,androidx.media3.exoplayer.source.MediaLoadData,int)` event. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaLoadData mediaLoadData` | The `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaLoadData` defining the data being loaded. |

### onLoadCompleted

```
public void onLoadCompleted(
    int windowIndex,
    @Nullable MediaSource.MediaPeriodId mediaPeriodId,
    LoadEventInfo loadEventInfo,
    MediaLoadData mediaLoadData
)
```

Called when a load ends.

| Parameters |
|---|---|
| `int windowIndex` | The window index in the timeline of the media source this load belongs to. |
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId mediaPeriodId` | The `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId` this load belongs to. Null if the load does not belong to a specific media period. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/LoadEventInfo loadEventInfo` | The `https://developer.android.com/reference/androidx/media3/exoplayer/source/LoadEventInfo` corresponding to the event. The values of `https://developer.android.com/reference/androidx/media3/exoplayer/source/LoadEventInfo#elapsedRealtimeMs()` and `https://developer.android.com/reference/androidx/media3/exoplayer/source/LoadEventInfo#bytesLoaded()` are relative to the corresponding `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSourceEventListener#onLoadStarted(int,androidx.media3.exoplayer.source.MediaSource.MediaPeriodId,androidx.media3.exoplayer.source.LoadEventInfo,androidx.media3.exoplayer.source.MediaLoadData,int)` event. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaLoadData mediaLoadData` | The `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaLoadData` defining the data being loaded. |

### onLoadError

```
public void onLoadError(
    int windowIndex,
    @Nullable MediaSource.MediaPeriodId mediaPeriodId,
    LoadEventInfo loadEventInfo,
    MediaLoadData mediaLoadData,
    IOException error,
    boolean wasCanceled
)
```

Called when a load error occurs.

The error may or may not have resulted in the load being canceled, as indicated by the `wasCanceled` parameter. If the load was canceled, `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSourceEventListener#onLoadCanceled(int,androidx.media3.exoplayer.source.MediaSource.MediaPeriodId,androidx.media3.exoplayer.source.LoadEventInfo,androidx.media3.exoplayer.source.MediaLoadData)` will *not* be called in addition to this method.

This method being called does not indicate that playback has failed, or that it will fail. The player may be able to recover from the error. Hence applications should *not* implement this method to display a user visible error or initiate an application level retry. `https://developer.android.com/reference/androidx/media3/common/Player.Listener#onPlayerError(androidx.media3.common.PlaybackException)` is the appropriate place to implement such behavior. This method is called to provide the application with an opportunity to log the error if it wishes to do so.

| Parameters |
|---|---|
| `int windowIndex` | The window index in the timeline of the media source this load belongs to. |
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId mediaPeriodId` | The `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId` this load belongs to. Null if the load does not belong to a specific media period. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/LoadEventInfo loadEventInfo` | The `https://developer.android.com/reference/androidx/media3/exoplayer/source/LoadEventInfo` corresponding to the event. The values of `https://developer.android.com/reference/androidx/media3/exoplayer/source/LoadEventInfo#elapsedRealtimeMs()` and `https://developer.android.com/reference/androidx/media3/exoplayer/source/LoadEventInfo#bytesLoaded()` are relative to the corresponding `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSourceEventListener#onLoadStarted(int,androidx.media3.exoplayer.source.MediaSource.MediaPeriodId,androidx.media3.exoplayer.source.LoadEventInfo,androidx.media3.exoplayer.source.MediaLoadData,int)` event. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaLoadData mediaLoadData` | The `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaLoadData` defining the data being loaded. |
| `https://developer.android.com/reference/java/io/IOException.html error` | The load error. |
| `boolean wasCanceled` | Whether the load was canceled as a result of the error. |

### onLoadStarted

```
public void onLoadStarted(
    int windowIndex,
    @Nullable MediaSource.MediaPeriodId mediaPeriodId,
    LoadEventInfo loadEventInfo,
    MediaLoadData mediaLoadData,
    int retryCount
)
```

Called when a load begins.

| Parameters |
|---|---|
| `int windowIndex` | The window index in the timeline of the media source this load belongs to. |
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId mediaPeriodId` | The `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId` this load belongs to. Null if the load does not belong to a specific media period. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/LoadEventInfo loadEventInfo` | The `https://developer.android.com/reference/androidx/media3/exoplayer/source/LoadEventInfo` corresponding to the event. The value of `https://developer.android.com/reference/androidx/media3/exoplayer/source/LoadEventInfo#uri()` won't reflect potential redirection yet and `https://developer.android.com/reference/androidx/media3/exoplayer/source/LoadEventInfo#responseHeaders()` will be empty. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaLoadData mediaLoadData` | The `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaLoadData` defining the data being loaded. |
| `int retryCount` | The number of failed attempts since this method was first called (this is zero for the first load attempt). |

### onSourceInfoRefreshed

```
public void onSourceInfoRefreshed(MediaSource source, Timeline timeline)
```

Called when the `https://developer.android.com/reference/androidx/media3/common/Timeline` has been refreshed.

Called on the playback thread.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource source` | The `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource` whose info has been refreshed. |
| `https://developer.android.com/reference/androidx/media3/common/Timeline timeline` | The source's timeline. |

### onUpstreamDiscarded

```
public void onUpstreamDiscarded(
    int windowIndex,
    MediaSource.MediaPeriodId mediaPeriodId,
    MediaLoadData mediaLoadData
)
```

Called when data is removed from the back of a media buffer, typically so that it can be re-buffered in a different format.

| Parameters |
|---|---|
| `int windowIndex` | The window index in the timeline of the media source this load belongs to. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId mediaPeriodId` | The `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId` the media belongs to. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaLoadData mediaLoadData` | The `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaLoadData` defining the media being discarded. |

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

### setAdPlaybackStates

```
public void setAdPlaybackStates(
    ImmutableMap<Object, AdPlaybackState> adPlaybackStates,
    Timeline contentTimeline
)
```

Sets the map of `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState` published by this source. The key is the period UID of a period in the `contentTimeline`.

Each period has an `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState` that tells where in the period the ad groups start and end. Must only contain server-side inserted ad groups. The number of ad groups and the number of ads within an ad group may only increase. The durations of ads may change and the positions of future ad groups may change. Post-roll ad groups with `https://developer.android.com/reference/androidx/media3/common/C#TIME_END_OF_SOURCE()` must be empty and can be used as a placeholder for a future ad group.

May be called from any thread.

| Parameters |
|---|---|
| `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/collect/ImmutableMap.html<https://developer.android.com/reference/java/lang/Object.html, https://developer.android.com/reference/androidx/media3/common/AdPlaybackState> adPlaybackStates` | The map of `https://developer.android.com/reference/androidx/media3/common/AdPlaybackState` keyed by their period UID. |
| `https://developer.android.com/reference/androidx/media3/common/Timeline contentTimeline` | The content timeline containing the periods with the UIDs used as keys in the map of playback states. |

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

### disableInternal

```
protected void disableInternal()
```

Disables the source, see `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource#disable(androidx.media3.exoplayer.source.MediaSource.MediaSourceCaller)`.

### enableInternal

```
protected void enableInternal()
```

Enables the source, see `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource#enable(androidx.media3.exoplayer.source.MediaSource.MediaSourceCaller)`.

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