# FakeAdsLoader

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

*** ** * ** ***

<br />

```
@UnstableApi
class FakeAdsLoader : AdsLoader
```

<br />

*** ** * ** ***

A fake implementation of `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ads/AdsLoader`.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeAdsLoader#FakeAdsLoader()()` Creates an instance. |

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeAdsLoader#handleContentTimelineChanged(androidx.media3.exoplayer.source.ads.AdsMediaSource,androidx.media3.common.Timeline)( adsMediaSource: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ads/AdsMediaSource!, timeline: https://developer.android.com/reference/kotlin/androidx/media3/common/Timeline! )` Notifies the ads loader when the content source has changed its timeline. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeAdsLoader#handlePrepareComplete(androidx.media3.exoplayer.source.ads.AdsMediaSource,int,int)( adsMediaSource: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ads/AdsMediaSource!, adGroupIndex: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, adIndexInAdGroup: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html )` Notifies the ads loader that preparation of an ad media period is complete. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeAdsLoader#handlePrepareError(androidx.media3.exoplayer.source.ads.AdsMediaSource,int,int,java.io.IOException)( adsMediaSource: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ads/AdsMediaSource!, adGroupIndex: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, adIndexInAdGroup: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, exception: https://developer.android.com/reference/java/io/IOException.html! )` Notifies the ads loader that the player was not able to prepare media for a given ad. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeAdsLoader#release()()` Releases the loader. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeAdsLoader#setPlayer(androidx.media3.common.Player)(player: https://developer.android.com/reference/kotlin/androidx/media3/common/Player?)` Sets the player that will play the loaded ads. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeAdsLoader#setSupportedContentTypes(int...)(@https://developer.android.com/reference/kotlin/androidx/media3/common/C.ContentType contentTypes: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html>!)` Sets the supported content types for ad media. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeAdsLoader#start(androidx.media3.exoplayer.source.ads.AdsMediaSource,androidx.media3.datasource.DataSpec,java.lang.Object,androidx.media3.common.AdViewProvider,androidx.media3.exoplayer.source.ads.AdsLoader.EventListener)( adsMediaSource: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ads/AdsMediaSource!, adTagDataSpec: https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSpec!, adsId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html!, adViewProvider: https://developer.android.com/reference/kotlin/androidx/media3/common/AdViewProvider!, eventListener: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ads/AdsLoader.EventListener! )` Starts using the ads loader for playback. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeAdsLoader#stop(androidx.media3.exoplayer.source.ads.AdsMediaSource,androidx.media3.exoplayer.source.ads.AdsLoader.EventListener)( adsMediaSource: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ads/AdsMediaSource!, eventListener: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ads/AdsLoader.EventListener! )` Stops using the ads loader for playback and deregisters the event listener. |

| ### Public properties |
|---|---|
| `(https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-map/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-map/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html!, https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ads/AdsLoader.EventListener!>!` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeAdsLoader#eventListeners()` |
| `https://developer.android.com/reference/kotlin/androidx/media3/common/Player?` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeAdsLoader#player()` |
| `@https://developer.android.com/reference/kotlin/androidx/media3/common/C.ContentType https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html>!` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeAdsLoader#supportedContentTypes()` |

## Public constructors

### FakeAdsLoader

```
FakeAdsLoader()
```

Creates an instance.

## Public functions

### handleContentTimelineChanged

```
fun handleContentTimelineChanged(
    adsMediaSource: AdsMediaSource!,
    timeline: Timeline!
): Boolean
```

Notifies the ads loader when the content source has changed its timeline. Called on the main thread by `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ads/AdsMediaSource`.

The default implementation returns false which makes the content timeline immediately being reported to the player.

When overriding this method for the purpose of reading ad data from the timeline to populate the `https://developer.android.com/reference/kotlin/androidx/media3/common/AdPlaybackState` with, false needs to be passed to the constructor of `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ads/AdsMediaSource#AdsMediaSource(androidx.media3.exoplayer.source.MediaSource,androidx.media3.datasource.DataSpec,java.lang.Object,androidx.media3.exoplayer.source.MediaSource.Factory,androidx.media3.exoplayer.source.ads.AdsLoader,androidx.media3.common.AdViewProvider,boolean,boolean)` to indicate that the content source needs to be prepared upfront. This way an ads loader can defer calling `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ads/AdsLoader.EventListener#onAdPlaybackState(androidx.media3.common.AdPlaybackState)` until the ad data from the timeline is available and populate the initial ad playback state with that data before publishing.

For live streams, this method is called additional times when the content source reports an advancing `https://developer.android.com/reference/kotlin/androidx/media3/common/Timeline` with new available media and/or new ad data in the manifest. If in such a case, the ads loader as a result calls `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ads/AdsLoader.EventListener#onAdPlaybackState(androidx.media3.common.AdPlaybackState)`, true must be returned. This prevents the timeline being reported with stale ad data. Conversely, when the ad playback state is not passed into `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ads/AdsLoader.EventListener#onAdPlaybackState(androidx.media3.common.AdPlaybackState)`, false must be returned to not drop a timeline update that needs to be published to the player.

Generally, if the timeline is not required to populate the ad playback state, `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ads/AdsLoader#start(androidx.media3.exoplayer.source.ads.AdsMediaSource,androidx.media3.datasource.DataSpec,java.lang.Object,androidx.media3.common.AdViewProvider,androidx.media3.exoplayer.source.ads.AdsLoader.EventListener)` should be used to initiate loading ad data and publish the first ad playback state as early as possible. This method can still be overridden for informational or other purpose. In this case, false is returned here and the `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ads/AdsMediaSource` is used with lazy preparation enabled.

| Parameters |
|---|---|
| `adsMediaSource: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ads/AdsMediaSource!` | The ads media source for which the content timeline changed. |
| `timeline: https://developer.android.com/reference/kotlin/androidx/media3/common/Timeline!` | The timeline of the content source. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | true If `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ads/AdsLoader.EventListener#onAdPlaybackState(androidx.media3.common.AdPlaybackState)` is or will be called, false otherwise. |

### handlePrepareComplete

```
fun handlePrepareComplete(
    adsMediaSource: AdsMediaSource!,
    adGroupIndex: Int,
    adIndexInAdGroup: Int
): Unit
```

Notifies the ads loader that preparation of an ad media period is complete. Called on the main thread by `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ads/AdsMediaSource`.

| Parameters |
|---|---|
| `adsMediaSource: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ads/AdsMediaSource!` | The ads media source for which preparation of ad media completed. |
| `adGroupIndex: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The index of the ad group. |
| `adIndexInAdGroup: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The index of the ad in the ad group. |

### handlePrepareError

```
fun handlePrepareError(
    adsMediaSource: AdsMediaSource!,
    adGroupIndex: Int,
    adIndexInAdGroup: Int,
    exception: IOException!
): Unit
```

Notifies the ads loader that the player was not able to prepare media for a given ad. Implementations should update the ad playback state as the specified ad has failed to load. Called on the main thread by `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ads/AdsMediaSource`.

| Parameters |
|---|---|
| `adsMediaSource: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ads/AdsMediaSource!` | The ads media source for which preparation of ad media failed. |
| `adGroupIndex: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The index of the ad group. |
| `adIndexInAdGroup: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The index of the ad in the ad group. |
| `exception: https://developer.android.com/reference/java/io/IOException.html!` | The preparation error. |

### release

```
fun release(): Unit
```

Releases the loader. Must be called by the application on the main thread when the instance is no longer needed.

### setPlayer

```
fun setPlayer(player: Player?): Unit
```

Sets the player that will play the loaded ads.

This method must be called before the player is prepared with media using this ads loader.

This method must also be called on the main thread and only players which are accessed on the main thread are supported (`player.getApplicationLooper() == Looper.getMainLooper()`).

| Parameters |
|---|---|
| `player: https://developer.android.com/reference/kotlin/androidx/media3/common/Player?` | The player instance that will play the loaded ads. May be null to delete the reference to a previously set player. |

### setSupportedContentTypes

```
fun setSupportedContentTypes(@C.ContentType contentTypes: IntArray<Int>!): Unit
```

Sets the supported content types for ad media. Must be called before the first call to `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ads/AdsLoader#start(androidx.media3.exoplayer.source.ads.AdsMediaSource,androidx.media3.datasource.DataSpec,java.lang.Object,androidx.media3.common.AdViewProvider,androidx.media3.exoplayer.source.ads.AdsLoader.EventListener)`. Subsequent calls may be ignored. Called on the main thread by `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ads/AdsMediaSource`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/kotlin/androidx/media3/common/C.ContentType contentTypes: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html>!` | The supported content types for ad media. Each element must be one of `https://developer.android.com/reference/kotlin/androidx/media3/common/C#CONTENT_TYPE_DASH()`, `https://developer.android.com/reference/kotlin/androidx/media3/common/C#CONTENT_TYPE_HLS()`, `https://developer.android.com/reference/kotlin/androidx/media3/common/C#CONTENT_TYPE_SS()` and `https://developer.android.com/reference/kotlin/androidx/media3/common/C#CONTENT_TYPE_OTHER()`. |

### start

```
fun start(
    adsMediaSource: AdsMediaSource!,
    adTagDataSpec: DataSpec!,
    adsId: Any!,
    adViewProvider: AdViewProvider!,
    eventListener: AdsLoader.EventListener!
): Unit
```

Starts using the ads loader for playback. Called on the main thread by `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ads/AdsMediaSource`.

Requests the ads loader to start loading ad data from the provided `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSpec`. Publishing an initial `https://developer.android.com/reference/kotlin/androidx/media3/common/AdPlaybackState` to provided `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ads/AdsLoader.EventListener#onAdPlaybackState(androidx.media3.common.AdPlaybackState)` is required to start playback. In the case of a pre roll, this ensures that the player doesn't briefly start playing content before ad data is available.

| Parameters |
|---|---|
| `adsMediaSource: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ads/AdsMediaSource!` | The ads media source requesting to start loading ads. |
| `adTagDataSpec: https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSpec!` | A data spec for the ad tag to load. |
| `adsId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html!` | An opaque identifier for the ad playback state across start/stop calls. |
| `adViewProvider: https://developer.android.com/reference/kotlin/androidx/media3/common/AdViewProvider!` | Provider of views for the ad UI. |
| `eventListener: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ads/AdsLoader.EventListener!` | Listener for ads loader events. |

### stop

```
fun stop(
    adsMediaSource: AdsMediaSource!,
    eventListener: AdsLoader.EventListener!
): Unit
```

Stops using the ads loader for playback and deregisters the event listener. Called on the main thread by `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ads/AdsMediaSource`.

| Parameters |
|---|---|
| `adsMediaSource: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ads/AdsMediaSource!` | The ads media source requesting to stop loading/playing ads. |
| `eventListener: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ads/AdsLoader.EventListener!` | The ads media source's listener for ads loader events. |

## Public properties

### eventListeners

```
val eventListeners: (Mutable)Map<Any!, AdsLoader.EventListener!>!
```

### player

```
val player: Player?
```

### supportedContentTypes

```
val supportedContentTypes: @C.ContentType Array<Int>!
```