# 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
class ServerSideAdInsertionMediaSource : BaseMediaSource, MediaSource.MediaSourceCaller, MediaSourceEventListener, DrmSessionEventListener
```

<br />

|---|---|---|
| [kotlin.Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html) |||
| ↳ | [androidx.media3.exoplayer.source.BaseMediaSource](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/BaseMediaSource) ||
|   | ↳ | [androidx.media3.exoplayer.source.ads.ServerSideAdInsertionMediaSource](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ads/ServerSideAdInsertionMediaSource) |

*** ** * ** ***

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

The media source publishes a `https://developer.android.com/reference/kotlin/androidx/media3/common/Timeline` for the wrapped `https://developer.android.com/reference/kotlin/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/kotlin/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 |
|---|
| `interface https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ads/ServerSideAdInsertionMediaSource.AdPlaybackStateUpdater` Receives ad playback state update requests when the `https://developer.android.com/reference/kotlin/androidx/media3/common/Timeline` of the content media source has changed. |

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

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ads/ServerSideAdInsertionMediaSource#canUpdateMediaItem(androidx.media3.common.MediaItem)(mediaItem: https://developer.android.com/reference/kotlin/androidx/media3/common/MediaItem!)` Returns whether the `https://developer.android.com/reference/kotlin/androidx/media3/common/MediaItem` for this source can be updated with the provided item. |
| `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaPeriod!` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ads/ServerSideAdInsertionMediaSource#createPeriod(androidx.media3.exoplayer.source.MediaSource.MediaPeriodId,androidx.media3.exoplayer.upstream.Allocator,long)( id: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId!, allocator: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Allocator!, startPositionUs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html )` Returns a new `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaPeriod` identified by `periodId`. |
| `https://developer.android.com/reference/kotlin/androidx/media3/common/MediaItem!` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ads/ServerSideAdInsertionMediaSource#getMediaItem()()` Returns the `https://developer.android.com/reference/kotlin/androidx/media3/common/MediaItem` whose media is provided by the source. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ads/ServerSideAdInsertionMediaSource#maybeThrowSourceInfoRefreshError()()` Throws any pending error encountered while loading or refreshing source information. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ads/ServerSideAdInsertionMediaSource#onDownstreamFormatChanged(int,androidx.media3.exoplayer.source.MediaSource.MediaPeriodId,androidx.media3.exoplayer.source.MediaLoadData)( windowIndex: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, mediaPeriodId: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId?, mediaLoadData: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/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/kotlin/androidx/media3/exoplayer/source/SampleStream`s provided by the source changes). |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ads/ServerSideAdInsertionMediaSource#onDrmKeysLoaded(int,androidx.media3.exoplayer.source.MediaSource.MediaPeriodId,androidx.media3.exoplayer.drm.KeyRequestInfo)( windowIndex: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, mediaPeriodId: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId?, keyRequestInfo: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/KeyRequestInfo! )` Called each time keys are loaded. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ads/ServerSideAdInsertionMediaSource#onDrmKeysRemoved(int,androidx.media3.exoplayer.source.MediaSource.MediaPeriodId)( windowIndex: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, mediaPeriodId: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId? )` Called each time offline keys are removed. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ads/ServerSideAdInsertionMediaSource#onDrmKeysRestored(int,androidx.media3.exoplayer.source.MediaSource.MediaPeriodId)( windowIndex: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, mediaPeriodId: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId? )` Called each time offline keys are restored. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ads/ServerSideAdInsertionMediaSource#onDrmSessionAcquired(int,androidx.media3.exoplayer.source.MediaSource.MediaPeriodId,int)( windowIndex: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, mediaPeriodId: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId?, @https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DrmSession.State state: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html )` Called each time a drm session is acquired. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ads/ServerSideAdInsertionMediaSource#onDrmSessionManagerError(int,androidx.media3.exoplayer.source.MediaSource.MediaPeriodId,java.lang.Exception)( windowIndex: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, mediaPeriodId: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId?, error: https://developer.android.com/reference/java/lang/Exception.html! )` Called when a drm error occurs. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ads/ServerSideAdInsertionMediaSource#onDrmSessionReleased(int,androidx.media3.exoplayer.source.MediaSource.MediaPeriodId)( windowIndex: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, mediaPeriodId: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId? )` Called each time a drm session is released. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ads/ServerSideAdInsertionMediaSource#onLoadCanceled(int,androidx.media3.exoplayer.source.MediaSource.MediaPeriodId,androidx.media3.exoplayer.source.LoadEventInfo,androidx.media3.exoplayer.source.MediaLoadData)( windowIndex: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, mediaPeriodId: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId?, loadEventInfo: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/LoadEventInfo!, mediaLoadData: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaLoadData! )` Called when a load is canceled. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ads/ServerSideAdInsertionMediaSource#onLoadCompleted(int,androidx.media3.exoplayer.source.MediaSource.MediaPeriodId,androidx.media3.exoplayer.source.LoadEventInfo,androidx.media3.exoplayer.source.MediaLoadData)( windowIndex: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, mediaPeriodId: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId?, loadEventInfo: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/LoadEventInfo!, mediaLoadData: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaLoadData! )` Called when a load ends. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/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)( windowIndex: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, mediaPeriodId: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId?, loadEventInfo: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/LoadEventInfo!, mediaLoadData: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaLoadData!, error: https://developer.android.com/reference/java/io/IOException.html!, wasCanceled: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html )` Called when a load error occurs. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/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)( windowIndex: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, mediaPeriodId: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId?, loadEventInfo: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/LoadEventInfo!, mediaLoadData: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaLoadData!, retryCount: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html )` Called when a load begins. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ads/ServerSideAdInsertionMediaSource#onSourceInfoRefreshed(androidx.media3.exoplayer.source.MediaSource,androidx.media3.common.Timeline)(source: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSource!, timeline: https://developer.android.com/reference/kotlin/androidx/media3/common/Timeline!)` Called when the `https://developer.android.com/reference/kotlin/androidx/media3/common/Timeline` has been refreshed. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ads/ServerSideAdInsertionMediaSource#onUpstreamDiscarded(int,androidx.media3.exoplayer.source.MediaSource.MediaPeriodId,androidx.media3.exoplayer.source.MediaLoadData)( windowIndex: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, mediaPeriodId: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId!, mediaLoadData: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/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. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ads/ServerSideAdInsertionMediaSource#releasePeriod(androidx.media3.exoplayer.source.MediaPeriod)(mediaPeriod: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaPeriod!)` Releases the period. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ads/ServerSideAdInsertionMediaSource#setAdPlaybackStates(com.google.common.collect.ImmutableMap<java.lang.Object,androidx.media3.common.AdPlaybackState>,androidx.media3.common.Timeline)( adPlaybackStates: https://guava.dev/releases/snapshot-android/api/docs/com/google/common/collect/ImmutableMap.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html!, https://developer.android.com/reference/kotlin/androidx/media3/common/AdPlaybackState!>!, contentTimeline: https://developer.android.com/reference/kotlin/androidx/media3/common/Timeline! )` Sets the map of `https://developer.android.com/reference/kotlin/androidx/media3/common/AdPlaybackState` published by this source. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ads/ServerSideAdInsertionMediaSource#updateMediaItem(androidx.media3.common.MediaItem)(mediaItem: https://developer.android.com/reference/kotlin/androidx/media3/common/MediaItem!)` Updates the `https://developer.android.com/reference/kotlin/androidx/media3/common/MediaItem` for this source. |

| ### Protected functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ads/ServerSideAdInsertionMediaSource#disableInternal()()` Disables the source, see `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSource#disable(androidx.media3.exoplayer.source.MediaSource.MediaSourceCaller)`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ads/ServerSideAdInsertionMediaSource#enableInternal()()` Enables the source, see `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSource#enable(androidx.media3.exoplayer.source.MediaSource.MediaSourceCaller)`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ads/ServerSideAdInsertionMediaSource#prepareSourceInternal(androidx.media3.datasource.TransferListener)(mediaTransferListener: https://developer.android.com/reference/kotlin/androidx/media3/datasource/TransferListener?)` Starts source preparation and enables the source, see `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSource#prepareSource(androidx.media3.exoplayer.source.MediaSource.MediaSourceCaller,androidx.media3.exoplayer.analytics.PlayerId,androidx.media3.exoplayer.upstream.BandwidthMeter)`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ads/ServerSideAdInsertionMediaSource#releaseSourceInternal()()` Releases the source, see `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSource#releaseSource(androidx.media3.exoplayer.source.MediaSource.MediaSourceCaller)`. |

### Inherited functions

From [androidx.media3.exoplayer.source.BaseMediaSource](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/BaseMediaSource) `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `@https://developer.android.com/reference/kotlin/androidx/media3/common/util/UnstableApi
https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/BaseMediaSource#addDrmEventListener(android.os.Handler,androidx.media3.exoplayer.drm.DrmSessionEventListener)(

handler: https://developer.android.com/reference/android/os/Handler.html!,

eventListener: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DrmSessionEventListener!

)`

Adds a `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DrmSessionEventListener` to the list of listeners which are notified of DRM events for this media source.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `@https://developer.android.com/reference/kotlin/androidx/media3/common/util/UnstableApi
https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/BaseMediaSource#addEventListener(android.os.Handler,androidx.media3.exoplayer.source.MediaSourceEventListener)(

handler: https://developer.android.com/reference/android/os/Handler.html!,

eventListener: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSourceEventListener!

)`

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

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

windowIndex: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html,

mediaPeriodId: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId?

)`

Returns a `https://developer.android.com/reference/kotlin/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/kotlin/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId`.
`https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSourceEventListener.EventDispatcher!` `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/BaseMediaSource#createEventDispatcher(androidx.media3.exoplayer.source.MediaSource.MediaPeriodId)(mediaPeriodId: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId?)`

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

mediaPeriodId: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId!,

mediaTimeOffsetMs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html

)`

**This function is deprecated.**

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

<br />

`https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSourceEventListener.EventDispatcher!` `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/BaseMediaSource#createEventDispatcher(int,androidx.media3.exoplayer.source.MediaSource.MediaPeriodId)(

windowIndex: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html,

mediaPeriodId: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId?

)`

Returns a `https://developer.android.com/reference/kotlin/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/kotlin/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId`.
`https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSourceEventListener.EventDispatcher!` `[createEventDispatcher](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/BaseMediaSource#createEventDispatcher(int,androidx.media3.exoplayer.source.MediaSource.MediaPeriodId,long))(

windowIndex: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html,

mediaPeriodId: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId?,

mediaTimeOffsetMs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html

)`

**This function is deprecated.**

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

<br />

`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `@https://developer.android.com/reference/kotlin/androidx/media3/common/util/UnstableApi
https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/BaseMediaSource#disable(androidx.media3.exoplayer.source.MediaSource.MediaSourceCaller)(caller: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSource.MediaSourceCaller!)`

Disables the source for the creation of `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaPeriod`.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `@https://developer.android.com/reference/kotlin/androidx/media3/common/util/UnstableApi
https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/BaseMediaSource#enable(androidx.media3.exoplayer.source.MediaSource.MediaSourceCaller)(caller: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSource.MediaSourceCaller!)`

Enables the source for the creation of `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaPeriod`.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/BaseMediaSource#isEnabled()()`

Returns whether the source is enabled.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `@https://developer.android.com/reference/kotlin/androidx/media3/common/util/UnstableApi
https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/BaseMediaSource#prepareSource(androidx.media3.exoplayer.source.MediaSource.MediaSourceCaller,androidx.media3.exoplayer.analytics.PlayerId,androidx.media3.exoplayer.upstream.BandwidthMeter)(

caller: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSource.MediaSourceCaller!,

playerId: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/analytics/PlayerId!,

bandwidthMeter: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/BandwidthMeter!

)`

Registers a `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSource.MediaSourceCaller`.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/BaseMediaSource#prepareSourceCalled()()`

Returns whether the source has `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSource#prepareSource(androidx.media3.exoplayer.source.MediaSource.MediaSourceCaller,androidx.media3.exoplayer.analytics.PlayerId,androidx.media3.exoplayer.upstream.BandwidthMeter)` called.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/BaseMediaSource#refreshSourceInfo(androidx.media3.common.Timeline)(timeline: https://developer.android.com/reference/kotlin/androidx/media3/common/Timeline!)`

Updates timeline and manifest and notifies all listeners of the update.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `@https://developer.android.com/reference/kotlin/androidx/media3/common/util/UnstableApi
https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/BaseMediaSource#releaseSource(androidx.media3.exoplayer.source.MediaSource.MediaSourceCaller)(caller: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSource.MediaSourceCaller!)`

Unregisters a caller, and disables and releases the source if no longer required.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `@https://developer.android.com/reference/kotlin/androidx/media3/common/util/UnstableApi
https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/BaseMediaSource#removeDrmEventListener(androidx.media3.exoplayer.drm.DrmSessionEventListener)(eventListener: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DrmSessionEventListener!)`

Removes a `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DrmSessionEventListener` from the list of listeners which are notified of DRM events for this media source.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `@https://developer.android.com/reference/kotlin/androidx/media3/common/util/UnstableApi
https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/BaseMediaSource#removeEventListener(androidx.media3.exoplayer.source.MediaSourceEventListener)(eventListener: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSourceEventListener!)`

Removes a `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSourceEventListener` from the list of listeners which are notified of media source events.
From [androidx.media3.exoplayer.drm.DrmSessionEventListener](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DrmSessionEventListener) `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `[onDrmKeysLoaded](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DrmSessionEventListener#onDrmKeysLoaded(int,androidx.media3.exoplayer.source.MediaSource.MediaPeriodId))(

windowIndex: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html,

mediaPeriodId: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId?

)`

**This function is deprecated.**

Implement `https://developer.android.com/reference/kotlin/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/kotlin/androidx/media3/exoplayer/source/MediaSource) `https://developer.android.com/reference/kotlin/androidx/media3/common/Timeline?` `@https://developer.android.com/reference/kotlin/androidx/media3/common/util/UnstableApi
https://developer.android.com/reference/kotlin/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.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` `@https://developer.android.com/reference/kotlin/androidx/media3/common/util/UnstableApi
https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSource#isSingleWindow()()`

Returns true if the media source is guaranteed to never have zero or more than one window.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `@https://developer.android.com/reference/kotlin/androidx/media3/common/util/UnstableApi
[prepareSource](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSource#prepareSource(androidx.media3.exoplayer.source.MediaSource.MediaSourceCaller,androidx.media3.datasource.TransferListener,androidx.media3.exoplayer.analytics.PlayerId))(

caller: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSource.MediaSourceCaller!,

mediaTransferListener: https://developer.android.com/reference/kotlin/androidx/media3/datasource/TransferListener?,

playerId: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/analytics/PlayerId!

)`

**This function is deprecated.**

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

<br />

### Inherited properties

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

## Public constructors

### ServerSideAdInsertionMediaSource

```
ServerSideAdInsertionMediaSource(
    mediaSource: MediaSource!,
    adPlaybackStateUpdater: ServerSideAdInsertionMediaSource.AdPlaybackStateUpdater?
)
```

Creates the media source.

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

## Public functions

### canUpdateMediaItem

```
fun canUpdateMediaItem(mediaItem: MediaItem!): Boolean
```

Returns whether the `https://developer.android.com/reference/kotlin/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 |
|---|---|
| `mediaItem: https://developer.android.com/reference/kotlin/androidx/media3/common/MediaItem!` | The new `https://developer.android.com/reference/kotlin/androidx/media3/common/MediaItem`. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | Whether the source can be updated using this item. |

### createPeriod

```
fun createPeriod(
    id: MediaSource.MediaPeriodId!,
    allocator: Allocator!,
    startPositionUs: Long
): MediaPeriod!
```

Returns a new `https://developer.android.com/reference/kotlin/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 |
|---|---|
| `id: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId!` | The identifier of the period. |
| `allocator: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Allocator!` | An `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Allocator` from which to obtain media buffer allocations. |
| `startPositionUs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | The expected start position, in microseconds. |

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

### getMediaItem

```
fun getMediaItem(): MediaItem!
```

Returns the `https://developer.android.com/reference/kotlin/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

```
fun maybeThrowSourceInfoRefreshError(): Unit
```

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

```
fun onDownstreamFormatChanged(
    windowIndex: Int,
    mediaPeriodId: MediaSource.MediaPeriodId?,
    mediaLoadData: MediaLoadData!
): Unit
```

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/kotlin/androidx/media3/exoplayer/source/SampleStream`s provided by the source changes).

| Parameters |
|---|---|
| `windowIndex: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The window index in the timeline of the media source this load belongs to. |
| `mediaPeriodId: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId?` | The `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId` the media belongs to. |
| `mediaLoadData: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaLoadData!` | The `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaLoadData` defining the newly selected downstream data. |

### onDrmKeysLoaded

```
fun onDrmKeysLoaded(
    windowIndex: Int,
    mediaPeriodId: MediaSource.MediaPeriodId?,
    keyRequestInfo: KeyRequestInfo!
): Unit
```

Called each time keys are loaded.

| Parameters |
|---|---|
| `windowIndex: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The window index in the timeline this media period belongs to. |
| `mediaPeriodId: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId?` | The `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId` associated with the drm session. |
| `keyRequestInfo: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/KeyRequestInfo!` | The `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/KeyRequestInfo` with load info for the drm server requests |

### onDrmKeysRemoved

```
fun onDrmKeysRemoved(
    windowIndex: Int,
    mediaPeriodId: MediaSource.MediaPeriodId?
): Unit
```

Called each time offline keys are removed.

| Parameters |
|---|---|
| `windowIndex: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The window index in the timeline this media period belongs to. |
| `mediaPeriodId: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId?` | The `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId` associated with the drm session. |

### onDrmKeysRestored

```
fun onDrmKeysRestored(
    windowIndex: Int,
    mediaPeriodId: MediaSource.MediaPeriodId?
): Unit
```

Called each time offline keys are restored.

| Parameters |
|---|---|
| `windowIndex: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The window index in the timeline this media period belongs to. |
| `mediaPeriodId: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId?` | The `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId` associated with the drm session. |

### onDrmSessionAcquired

```
fun onDrmSessionAcquired(
    windowIndex: Int,
    mediaPeriodId: MediaSource.MediaPeriodId?,
    @DrmSession.State state: Int
): Unit
```

Called each time a drm session is acquired.

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

### onDrmSessionManagerError

```
fun onDrmSessionManagerError(
    windowIndex: Int,
    mediaPeriodId: MediaSource.MediaPeriodId?,
    error: Exception!
): Unit
```

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/kotlin/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 |
|---|---|
| `windowIndex: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The window index in the timeline this media period belongs to. |
| `mediaPeriodId: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId?` | The `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId` associated with the drm session. |
| `error: https://developer.android.com/reference/java/lang/Exception.html!` | The corresponding exception. |

### onDrmSessionReleased

```
fun onDrmSessionReleased(
    windowIndex: Int,
    mediaPeriodId: MediaSource.MediaPeriodId?
): Unit
```

Called each time a drm session is released.

| Parameters |
|---|---|
| `windowIndex: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The window index in the timeline this media period belongs to. |
| `mediaPeriodId: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId?` | The `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId` associated with the drm session. |

### onLoadCanceled

```
fun onLoadCanceled(
    windowIndex: Int,
    mediaPeriodId: MediaSource.MediaPeriodId?,
    loadEventInfo: LoadEventInfo!,
    mediaLoadData: MediaLoadData!
): Unit
```

Called when a load is canceled.

| Parameters |
|---|---|
| `windowIndex: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The window index in the timeline of the media source this load belongs to. |
| `mediaPeriodId: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId?` | The `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId` this load belongs to. Null if the load does not belong to a specific media period. |
| `loadEventInfo: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/LoadEventInfo!` | The `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/LoadEventInfo` corresponding to the event. The values of `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/LoadEventInfo#elapsedRealtimeMs()` and `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/LoadEventInfo#bytesLoaded()` are relative to the corresponding `https://developer.android.com/reference/kotlin/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. |
| `mediaLoadData: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaLoadData!` | The `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaLoadData` defining the data being loaded. |

### onLoadCompleted

```
fun onLoadCompleted(
    windowIndex: Int,
    mediaPeriodId: MediaSource.MediaPeriodId?,
    loadEventInfo: LoadEventInfo!,
    mediaLoadData: MediaLoadData!
): Unit
```

Called when a load ends.

| Parameters |
|---|---|
| `windowIndex: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The window index in the timeline of the media source this load belongs to. |
| `mediaPeriodId: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId?` | The `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId` this load belongs to. Null if the load does not belong to a specific media period. |
| `loadEventInfo: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/LoadEventInfo!` | The `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/LoadEventInfo` corresponding to the event. The values of `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/LoadEventInfo#elapsedRealtimeMs()` and `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/LoadEventInfo#bytesLoaded()` are relative to the corresponding `https://developer.android.com/reference/kotlin/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. |
| `mediaLoadData: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaLoadData!` | The `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaLoadData` defining the data being loaded. |

### onLoadError

```
fun onLoadError(
    windowIndex: Int,
    mediaPeriodId: MediaSource.MediaPeriodId?,
    loadEventInfo: LoadEventInfo!,
    mediaLoadData: MediaLoadData!,
    error: IOException!,
    wasCanceled: Boolean
): Unit
```

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/kotlin/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/kotlin/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 |
|---|---|
| `windowIndex: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The window index in the timeline of the media source this load belongs to. |
| `mediaPeriodId: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId?` | The `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId` this load belongs to. Null if the load does not belong to a specific media period. |
| `loadEventInfo: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/LoadEventInfo!` | The `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/LoadEventInfo` corresponding to the event. The values of `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/LoadEventInfo#elapsedRealtimeMs()` and `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/LoadEventInfo#bytesLoaded()` are relative to the corresponding `https://developer.android.com/reference/kotlin/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. |
| `mediaLoadData: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaLoadData!` | The `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaLoadData` defining the data being loaded. |
| `error: https://developer.android.com/reference/java/io/IOException.html!` | The load error. |
| `wasCanceled: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | Whether the load was canceled as a result of the error. |

### onLoadStarted

```
fun onLoadStarted(
    windowIndex: Int,
    mediaPeriodId: MediaSource.MediaPeriodId?,
    loadEventInfo: LoadEventInfo!,
    mediaLoadData: MediaLoadData!,
    retryCount: Int
): Unit
```

Called when a load begins.

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

### onSourceInfoRefreshed

```
fun onSourceInfoRefreshed(source: MediaSource!, timeline: Timeline!): Unit
```

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

Called on the playback thread.

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

### onUpstreamDiscarded

```
fun onUpstreamDiscarded(
    windowIndex: Int,
    mediaPeriodId: MediaSource.MediaPeriodId!,
    mediaLoadData: MediaLoadData!
): Unit
```

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 |
|---|---|
| `windowIndex: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The window index in the timeline of the media source this load belongs to. |
| `mediaPeriodId: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId!` | The `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId` the media belongs to. |
| `mediaLoadData: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaLoadData!` | The `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaLoadData` defining the media being discarded. |

### releasePeriod

```
fun releasePeriod(mediaPeriod: MediaPeriod!): Unit
```

Releases the period.

Should not be called directly from application code.

This method must be called on the playback thread.

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

### setAdPlaybackStates

```
fun setAdPlaybackStates(
    adPlaybackStates: ImmutableMap<Any!, AdPlaybackState!>!,
    contentTimeline: Timeline!
): Unit
```

Sets the map of `https://developer.android.com/reference/kotlin/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/kotlin/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/kotlin/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 |
|---|---|
| `adPlaybackStates: https://guava.dev/releases/snapshot-android/api/docs/com/google/common/collect/ImmutableMap.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html!, https://developer.android.com/reference/kotlin/androidx/media3/common/AdPlaybackState!>!` | The map of `https://developer.android.com/reference/kotlin/androidx/media3/common/AdPlaybackState` keyed by their period UID. |
| `contentTimeline: https://developer.android.com/reference/kotlin/androidx/media3/common/Timeline!` | The content timeline containing the periods with the UIDs used as keys in the map of playback states. |

### updateMediaItem

```
fun updateMediaItem(mediaItem: MediaItem!): Unit
```

Updates the `https://developer.android.com/reference/kotlin/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/kotlin/androidx/media3/exoplayer/source/MediaSource#canUpdateMediaItem(androidx.media3.common.MediaItem)` returns `true` for the new `https://developer.android.com/reference/kotlin/androidx/media3/common/MediaItem`.

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

## Protected functions

### disableInternal

```
protected fun disableInternal(): Unit
```

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

### enableInternal

```
protected fun enableInternal(): Unit
```

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

### prepareSourceInternal

```
protected fun prepareSourceInternal(mediaTransferListener: TransferListener?): Unit
```

Starts source preparation and enables the source, see `https://developer.android.com/reference/kotlin/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/kotlin/androidx/media3/exoplayer/source/BaseMediaSource#releaseSourceInternal()`.

This method is called on the playback thread.

| Parameters |
|---|---|
| `mediaTransferListener: https://developer.android.com/reference/kotlin/androidx/media3/datasource/TransferListener?` | 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 fun releaseSourceInternal(): Unit
```

Releases the source, see `https://developer.android.com/reference/kotlin/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/kotlin/androidx/media3/exoplayer/source/BaseMediaSource#prepareSourceInternal(androidx.media3.datasource.TransferListener)`.

This method is called on the playback thread.