Back to Exoplayer

AdsLoader (ExoPlayer library)

docs/doc/reference/com/google/android/exoplayer2/source/ads/AdsLoader.html

latest10.4 KB
Original Source

Package com.google.android.exoplayer2.source.ads

Interface AdsLoader

  • All Known Implementing Classes:ImaAdsLoader

[@Deprecated](https://developer.android.com/reference/java/lang/Deprecated.html "class or interface in java.lang")public interfaceAdsLoader

Deprecated. com.google.android.exoplayer2 is deprecated. Please migrate to androidx.media3 (which contains the same ExoPlayer code). See the migration guide for more details, including a script to help with the migration.

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

Ads loaders notify the AdsMediaSource about events via AdsLoader.EventListener. In particular, implementations must call AdsLoader.EventListener.onAdPlaybackState(AdPlaybackState) 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(AdsMediaSource, DataSpec, Object, AdViewProvider, EventListener) 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(AdsMediaSource, EventListener) will be called. Loaders should maintain any ad playback state in preparation for a later call to start(AdsMediaSource, DataSpec, Object, AdViewProvider, EventListener). If an ad is playing when the player is detached, update the ad playback state with the current playback position using AdPlaybackState.withAdResumePositionUs(long).

If AdsLoader.EventListener.onAdPlaybackState(AdPlaybackState) has been called, the implementation of start(AdsMediaSource, DataSpec, Object, AdViewProvider, EventListener) should invoke the same listener to provide the existing playback state to the new player.

Nested Class Summary

Nested Classes | Modifier and Type | Interface | Description | | --- | --- | --- | | static interface | AdsLoader.EventListener | Deprecated.

Listener for ads loader events. | | static interface | AdsLoader.Provider | Deprecated.

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

Method Summary

All Methods Instance Methods Abstract Methods Deprecated Methods | Modifier and Type | Method | Description | | --- | --- | --- | | void | handlePrepareComplete​(AdsMediaSource adsMediaSource, int adGroupIndex, int adIndexInAdGroup) | Deprecated.

Notifies the ads loader that preparation of an ad media period is complete. | | void | handlePrepareError​(AdsMediaSource adsMediaSource, int adGroupIndex, int adIndexInAdGroup, IOException exception) | Deprecated.

Notifies the ads loader that the player was not able to prepare media for a given ad. | | void | release() | Deprecated.

Releases the loader. | | void | setPlayer​(Player player) | Deprecated.

Sets the player that will play the loaded ads. | | void | setSupportedContentTypes​(@com.google.android.exoplayer2.C.ContentType int... contentTypes) | Deprecated.

Sets the supported content types for ad media. | | void | start​(AdsMediaSource adsMediaSource, DataSpec adTagDataSpec, Object adsId, AdViewProvider adViewProvider, AdsLoader.EventListener eventListener) | Deprecated.

Starts using the ads loader for playback. | | void | stop​(AdsMediaSource adsMediaSource, AdsLoader.EventListener eventListener) | Deprecated.

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

Method Detail

- 

setPlayer

void setPlayer​(@Nullable[Player](../../Player.html "interface in com.google.android.exoplayer2")player)

Deprecated.

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 - The player instance that will play the loaded ads. May be null to delete the reference to a previously set player.

- 

release

void release()

Deprecated.

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

- 

setSupportedContentTypes

void setSupportedContentTypes​([@ContentType](../../C.ContentType.html "annotation in com.google.android.exoplayer2")@com.google.android.exoplayer2.C.ContentType int... contentTypes)

Deprecated.

Sets the supported content types for ad media. Must be called before the first call to start(AdsMediaSource, DataSpec, Object, AdViewProvider, EventListener). Subsequent calls may be ignored. Called on the main thread by AdsMediaSource. Parameters:contentTypes - The supported content types for ad media. Each element must be one of C.CONTENT_TYPE_DASH, C.CONTENT_TYPE_HLS, C.CONTENT_TYPE_SS and C.CONTENT_TYPE_OTHER.

- 

start

void start​([AdsMediaSource](AdsMediaSource.html "class in com.google.android.exoplayer2.source.ads")adsMediaSource,[DataSpec](../../upstream/DataSpec.html "class in com.google.android.exoplayer2.upstream")adTagDataSpec,[Object](https://developer.android.com/reference/java/lang/Object.html "class or interface in java.lang")adsId,[AdViewProvider](../../ui/AdViewProvider.html "interface in com.google.android.exoplayer2.ui")adViewProvider,[AdsLoader.EventListener](AdsLoader.EventListener.html "interface in com.google.android.exoplayer2.source.ads")eventListener)

Deprecated.

Starts using the ads loader for playback. Called on the main thread by AdsMediaSource. Parameters:adsMediaSource - The ads media source requesting to start loading ads.adTagDataSpec - A data spec for the ad tag to load.adsId - An opaque identifier for the ad playback state across start/stop calls.adViewProvider - Provider of views for the ad UI.eventListener - Listener for ads loader events.

- 

stop

void stop​([AdsMediaSource](AdsMediaSource.html "class in com.google.android.exoplayer2.source.ads")adsMediaSource,[AdsLoader.EventListener](AdsLoader.EventListener.html "interface in com.google.android.exoplayer2.source.ads")eventListener)

Deprecated.

Stops using the ads loader for playback and deregisters the event listener. Called on the main thread by AdsMediaSource. Parameters:adsMediaSource - The ads media source requesting to stop loading/playing ads.eventListener - The ads media source's listener for ads loader events.

- 

handlePrepareComplete

void handlePrepareComplete​([AdsMediaSource](AdsMediaSource.html "class in com.google.android.exoplayer2.source.ads")adsMediaSource,
                           int adGroupIndex,
                           int adIndexInAdGroup)

Deprecated.

Notifies the ads loader that preparation of an ad media period is complete. Called on the main thread by AdsMediaSource. Parameters:adsMediaSource - The ads media source for which preparation of ad media completed.adGroupIndex - The index of the ad group.adIndexInAdGroup - The index of the ad in the ad group.

- 

handlePrepareError

void handlePrepareError​([AdsMediaSource](AdsMediaSource.html "class in com.google.android.exoplayer2.source.ads")adsMediaSource,
                        int adGroupIndex,
                        int adIndexInAdGroup,[IOException](https://developer.android.com/reference/java/io/IOException.html "class or interface in java.io")exception)

Deprecated.

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 - The ads media source for which preparation of ad media failed.adGroupIndex - The index of the ad group.adIndexInAdGroup - The index of the ad in the ad group.exception - The preparation error.