interface AdsLoader

Known direct subclasses
ImaAdsLoader

AdsLoader using the IMA SDK.


Interface for loaders of ads, which can be used with AdsMediaSource.

Ads loaders notify the AdsMediaSource about events via EventListener. In particular, implementations must call onAdPlaybackState with a new copy of the current AdPlaybackState whenever further information about ads becomes known (for example, when an ad media URI is available, or an ad has played to the end).

start will be called when an ads media source first initializes, at which point the loader can request ads. If the player enters the background, stop will be called. Loaders should maintain any ad playback state in preparation for a later call to start. If an ad is playing when the player is detached, update the ad playback state with the current playback position using withAdResumePositionUs.

If onAdPlaybackState has been called, the implementation of start should invoke the same listener to provide the existing playback state to the new player.

Summary

Nested types

Listener for ads loader events.

Provides AdsLoader instances for media items that have ad tag URIs.

Public functions

Unit
@UnstableApi
handlePrepareComplete(
    adsMediaSource: AdsMediaSource!,
    adGroupIndex: Int,
    adIndexInAdGroup: Int
)

Notifies the ads loader that preparation of an ad media period is complete.

Unit
@UnstableApi
handlePrepareError(
    adsMediaSource: AdsMediaSource!,
    adGroupIndex: Int,
    adIndexInAdGroup: Int,
    exception: IOException!
)

Notifies the ads loader that the player was not able to prepare media for a given ad.

Unit

Releases the loader.

Unit
setPlayer(player: Player?)

Sets the player that will play the loaded ads.

Unit

Sets the supported content types for ad media.

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

Starts using the ads loader for playback.

Unit
@UnstableApi
stop(
    adsMediaSource: AdsMediaSource!,
    eventListener: AdsLoader.EventListener!
)

Stops using the ads loader for playback and deregisters the event listener.

Public functions

handlePrepareComplete

@UnstableApi
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 AdsMediaSource.

Parameters
adsMediaSource: AdsMediaSource!

The ads media source for which preparation of ad media completed.

adGroupIndex: Int

The index of the ad group.

adIndexInAdGroup: Int

The index of the ad in the ad group.

handlePrepareError

@UnstableApi
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 AdsMediaSource.

Parameters
adsMediaSource: AdsMediaSource!

The ads media source for which preparation of ad media failed.

adGroupIndex: Int

The index of the ad group.

adIndexInAdGroup: Int

The index of the ad in the ad group.

exception: IOException!

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: Player?

The player instance that will play the loaded ads. May be null to delete the reference to a previously set player.

setSupportedContentTypes

@UnstableApi
fun setSupportedContentTypes(@C.ContentType contentTypes: IntArray!): Unit

Sets the supported content types for ad media. Must be called before the first call to start. Subsequent calls may be ignored. Called on the main thread by AdsMediaSource.

Parameters
@C.ContentType contentTypes: IntArray!

The supported content types for ad media. Each element must be one of CONTENT_TYPE_DASH, CONTENT_TYPE_HLS, CONTENT_TYPE_SS and CONTENT_TYPE_OTHER.

start

@UnstableApi
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 AdsMediaSource.

Parameters
adsMediaSource: AdsMediaSource!

The ads media source requesting to start loading ads.

adTagDataSpec: DataSpec!

A data spec for the ad tag to load.

adsId: Any!

An opaque identifier for the ad playback state across start/stop calls.

adViewProvider: AdViewProvider!

Provider of views for the ad UI.

eventListener: AdsLoader.EventListener!

Listener for ads loader events.

stop

@UnstableApi
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 AdsMediaSource.

Parameters
adsMediaSource: AdsMediaSource!

The ads media source requesting to stop loading/playing ads.

eventListener: AdsLoader.EventListener!

The ads media source's listener for ads loader events.