> Documentation index: https://developer.android.com/reference/llms.txt

# ImaServerSideAdInsertionMediaSource

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

*** ** * ** ***


```
class ImaServerSideAdInsertionMediaSource : CompositeMediaSource<Void!>
```

<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.md.txt) |||
|   | ↳ | [androidx.media3.exoplayer.source.CompositeMediaSource](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/CompositeMediaSource.md.txt)\<[Void](https://developer.android.com/reference/java/lang/Void.md.txt)!\> ||
|   |   | ↳ | [androidx.media3.exoplayer.ima.ImaServerSideAdInsertionMediaSource](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/ima/ImaServerSideAdInsertionMediaSource.md.txt) |

*** ** * ** ***

MediaSource for IMA server side inserted ad streams.

## Summary

| ### Nested types |
|---|
| `class ImaServerSideAdInsertionMediaSource.AdsLoader` An ads loader for IMA server side ad insertion streams. |
| `class ImaServerSideAdInsertionMediaSource.AdsLoader.Builder` Builder for building an `AdsLoader`. |
| `class ImaServerSideAdInsertionMediaSource.AdsLoader.State` The state of the `AdsLoader` that can be used when resuming from the background. |
| `class ImaServerSideAdInsertionMediaSource.Factory : MediaSource.Factory` Factory for creating `ImaServerSideAdInsertionMediaSources`. |
| `@UnstableApi interface ImaServerSideAdInsertionMediaSource.StreamEventListener` A listener to be notified of stream events. |

| ### Public functions |
|---|---|
| `Boolean` | `@UnstableApi canUpdateMediaItem(mediaItem: MediaItem!)` Returns whether the `MediaItem` for this source can be updated with the provided item. |
| `MediaPeriod!` | `@UnstableApi createPeriod( id: MediaSource.MediaPeriodId!, allocator: Allocator!, startPositionUs: Long )` Returns a new `MediaPeriod` identified by `periodId`. |
| `Unit` | `@UnstableApi maybeThrowSourceInfoRefreshError()` Throws any pending error encountered while loading or refreshing source information. |
| `Unit` | `@UnstableApi prepareSourceInternal(mediaTransferListener: TransferListener?)` Starts source preparation and enables the source, see `prepareSource`. |
| `Unit` | `@UnstableApi releasePeriod(mediaPeriod: MediaPeriod!)` Releases the period. |
| `synchronized Unit` | `@UnstableApi updateMediaItem(mediaItem: MediaItem!)` Updates the `MediaItem` for this source. |

| ### Protected functions |
|---|---|
| `Unit` | `@UnstableApi onChildSourceInfoRefreshed( childSourceId: Void!, mediaSource: MediaSource!, newTimeline: Timeline! )` Called when the source info of a child source has been refreshed. |
| `Unit` | `@UnstableApi releaseSourceInternal()` Releases the source, see `releaseSource`. |

| ### Public properties |
|---|---|
| `MediaItem!` | `@GuardedBy(value = "this") mediaItem` |

### Inherited functions

From [androidx.media3.exoplayer.source.BaseMediaSource](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/BaseMediaSource.md.txt) `Unit` `@UnstableApi
addDrmEventListener(
handler: Handler!,
eventListener: DrmSessionEventListener!
)`

Adds a `DrmSessionEventListener` to the list of listeners which are notified of DRM events for this media source.
`Unit` `@UnstableApi
addEventListener(
handler: Handler!,
eventListener: MediaSourceEventListener!
)`

Adds a `MediaSourceEventListener` to the list of listeners which are notified of media source events.
`DrmSessionEventListener.EventDispatcher!` `createDrmEventDispatcher(mediaPeriodId: MediaSource.MediaPeriodId?)`

Returns a `DrmSessionEventListener.EventDispatcher` which dispatches all events to the registered listeners with the specified `MediaPeriodId`
`DrmSessionEventListener.EventDispatcher!` `createDrmEventDispatcher(
windowIndex: Int,
mediaPeriodId: MediaSource.MediaPeriodId?
)`

Returns a `DrmSessionEventListener.EventDispatcher` which dispatches all events to the registered listeners with the specified window index and `MediaPeriodId`.
`MediaSourceEventListener.EventDispatcher!` `createEventDispatcher(mediaPeriodId: MediaSource.MediaPeriodId?)`

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

**This function is deprecated.**

Use `createEventDispatcher` instead.

<br />

`MediaSourceEventListener.EventDispatcher!` `createEventDispatcher(
windowIndex: Int,
mediaPeriodId: MediaSource.MediaPeriodId?
)`

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

**This function is deprecated.**

Use `createEventDispatcher` instead.

<br />

`Unit` `@UnstableApi
disable(caller: MediaSource.MediaSourceCaller!)`

Disables the source for the creation of `MediaPeriods`.
`Unit` `@UnstableApi
enable(caller: MediaSource.MediaSourceCaller!)`

Enables the source for the creation of `MediaPeriods`.
`Boolean` `isEnabled()`

Returns whether the source is enabled.
`Unit` `@UnstableApi
prepareSource(
caller: MediaSource.MediaSourceCaller!,
playerId: PlayerId!,
bandwidthMeter: BandwidthMeter!
)`

Registers a `MediaSourceCaller`.
`Boolean` `prepareSourceCalled()`

Returns whether the source has `prepareSource` called.
`Unit` `refreshSourceInfo(timeline: Timeline!)`

Updates timeline and manifest and notifies all listeners of the update.
`Unit` `@UnstableApi
releaseSource(caller: MediaSource.MediaSourceCaller!)`

Unregisters a caller, and disables and releases the source if no longer required.
`Unit` `@UnstableApi
removeDrmEventListener(eventListener: DrmSessionEventListener!)`

Removes a `DrmSessionEventListener` from the list of listeners which are notified of DRM events for this media source.
`Unit` `@UnstableApi
removeEventListener(eventListener: MediaSourceEventListener!)`

Removes a `MediaSourceEventListener` from the list of listeners which are notified of media source events.
From [androidx.media3.exoplayer.source.CompositeMediaSource](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/CompositeMediaSource.md.txt) `Unit` `disableChildSource(id: T!)`

Disables a child source.
`Unit` `@CallSuper
disableInternal()`

Disables the source, see `disable`.
`Unit` `enableChildSource(id: T!)`

Enables a child source.
`Unit` `@CallSuper
enableInternal()`

Enables the source, see `enable`.
`MediaSource.MediaPeriodId?` `getMediaPeriodIdForChildMediaPeriodId(
childSourceId: T!,
mediaPeriodId: MediaSource.MediaPeriodId!
)`

Returns the `MediaPeriodId` in the composite source corresponding to the specified `MediaPeriodId` in a child source.
`Long` `getMediaTimeForChildMediaTime(
childSourceId: T!,
mediaTimeMs: Long,
mediaPeriodId: MediaSource.MediaPeriodId?
)`

Returns the media time in the `MediaPeriod` of the composite source corresponding to the specified media time in the `MediaPeriod` of the child source.
`Int` `getWindowIndexForChildWindowIndex(childSourceId: T!, windowIndex: Int)`

Returns the window index in the composite source corresponding to the specified window index in a child source.
`Unit` `prepareChildSource(id: T!, mediaSource: MediaSource!)`

Prepares a child source.
`Unit` `releaseChildSource(id: T!)`

Releases a child source.
From [androidx.media3.exoplayer.source.MediaSource](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSource.md.txt) `Timeline?` `@UnstableApi
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` `@UnstableApi
isSingleWindow()`

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

**This function is deprecated.**

Use `prepareSource` instead.

<br />

### Inherited properties

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

## Public functions

### canUpdateMediaItem

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

Returns whether the `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: MediaItem!` | The new `MediaItem`. |

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

### createPeriod

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

Returns a new `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: MediaSource.MediaPeriodId!` | The identifier of the period. |
| `allocator: Allocator!` | An `Allocator` from which to obtain media buffer allocations. |
| `startPositionUs: Long` | The expected start position, in microseconds. |

| Returns |
|---|---|
| `MediaPeriod!` | A new `MediaPeriod`. |

### maybeThrowSourceInfoRefreshError

```
@UnstableApi
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 `prepareSource`.

| Throws |
|---|---|
| `java.io.IOException` |   |

### prepareSourceInternal

```
@UnstableApi
fun prepareSourceInternal(mediaTransferListener: TransferListener?): Unit
```

Starts source preparation and enables the source, see `prepareSource`. This method is called at most once until the next call to `releaseSourceInternal`.

This method is called on the playback thread.

| Parameters |
|---|---|
| `mediaTransferListener: 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. |

### releasePeriod

```
@UnstableApi
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: MediaPeriod!` | The period to release. |

### updateMediaItem

```
@UnstableApi
synchronized fun updateMediaItem(mediaItem: MediaItem!): Unit
```

Updates the `MediaItem` for this source.

Should not be called directly from application code.

This method must be called on the playback thread and only if `canUpdateMediaItem` returns `true` for the new `MediaItem`.

| Parameters |
|---|---|
| `mediaItem: MediaItem!` | The new `MediaItem`. |

## Protected functions

### onChildSourceInfoRefreshed

```
@UnstableApi
protected fun onChildSourceInfoRefreshed(
    childSourceId: Void!,
    mediaSource: MediaSource!,
    newTimeline: Timeline!
): Unit
```

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

| Parameters |
|---|---|
| `childSourceId: Void!` | The unique id used to prepare the child source. |
| `mediaSource: MediaSource!` | The child source whose source info has been refreshed. |
| `newTimeline: Timeline!` | The timeline of the child source. |

### releaseSourceInternal

```
@UnstableApi
protected fun releaseSourceInternal(): Unit
```

Releases the source, see `releaseSource`. This method is called exactly once after each call to `prepareSourceInternal`.

This method is called on the playback thread.

## Public properties

### mediaItem

```
@GuardedBy(value = "this")
val mediaItem: MediaItem!
```