class ImaAdsLoader : AdsLoader


AdsLoader using the IMA SDK. All methods must be called on the main thread.

The player instance that will play the loaded ads must be set before playback using setPlayer. If the ads loader is no longer required, it must be released by calling release.

See IMA's Support and compatibility page for information on compatible ad tag formats. Pass the ad tag URI when setting media item playback properties (if using the media item API) or as a when constructing the AdsMediaSource (if using media sources directly). For the latter case, please note that this implementation delegates loading of the data spec to the IMA SDK, so range and headers specifications will be ignored in ad tag URIs. Literal ads responses can be encoded as data scheme data specs, for example, by constructing the data spec using a URI generated via getDataUriForString.

The IMA SDK can report obstructions to the ad view for accurate viewability measurement. This means that any overlay views that obstruct the ad overlay but are essential for playback need to be registered via the AdViewProvider passed to the AdsMediaSource. See the IMA SDK Open Measurement documentation for more information.

Summary

Nested types

Builder for ImaAdsLoader.

Public functions

Unit

Moves UI focus to the skip button (or other interactive elements), if currently shown.

AdDisplayContainer?

Returns the AdDisplayContainer used by this loader, or null if ads have not been requested yet.

AdsLoader?

Returns the underlying com.google.ads.interactivemedia.v3.api.AdsLoader wrapped by this instance, or null if ads have not been requested yet.

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
@UnstableApi
requestAds(adTagDataSpec: DataSpec!, adsId: Any!, adViewGroup: ViewGroup?)

Requests ads, if they have not already been requested.

Unit
setPlayer(player: Player?)

Sets the player that will play the loaded ads.

Unit

Sets the supported content types for ad media.

Unit

Skips the current ad.

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

focusSkipButton

@UnstableApi
fun focusSkipButton(): Unit

Moves UI focus to the skip button (or other interactive elements), if currently shown. See focus.

getAdDisplayContainer

@UnstableApi
fun getAdDisplayContainer(): AdDisplayContainer?

Returns the AdDisplayContainer used by this loader, or null if ads have not been requested yet.

Note: any video controls overlays registered via registerFriendlyObstruction will be unregistered automatically when the media source detaches from this instance. It is therefore necessary to re-register views each time the ads loader is reused. Alternatively, provide overlay views via the AdViewProvider when creating the media source to benefit from automatic registration.

getAdsLoader

@UnstableApi
fun getAdsLoader(): AdsLoader?

Returns the underlying com.google.ads.interactivemedia.v3.api.AdsLoader wrapped by this instance, or null if ads have not been requested yet.

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.

requestAds

@UnstableApi
fun requestAds(adTagDataSpec: DataSpec!, adsId: Any!, adViewGroup: ViewGroup?): Unit

Requests ads, if they have not already been requested. Must be called on the main thread.

Ads will be requested automatically when the player is prepared if this method has not been called, so it is only necessary to call this method if you want to request ads before preparing the player.

Parameters
adTagDataSpec: DataSpec!

The data specification of the ad tag to load. See class javadoc for information about compatible ad tag formats.

adsId: Any!

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

adViewGroup: ViewGroup?

A ViewGroup on top of the player that will show any ad UI, or null if playing audio-only ads.

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.

skipAd

@UnstableApi
fun skipAd(): Unit

Skips the current ad.

This method is intended for apps that play audio-only ads and so need to provide their own UI for users to skip skippable ads. Apps showing video ads should not call this method, as the IMA SDK provides the UI to skip ads in the ad view group passed via AdViewProvider.

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.