public interface AdsLoader
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(EventListener, AdViewProvider) will be called when the 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(EventListener, AdViewProvider). 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(EventListener, AdViewProvider) should invoke the same listener
to provide the existing playback state to the new player.
| Modifier and Type | Interface and Description |
|---|---|
static interface |
AdsLoader.AdViewProvider
Provides views for the ad UI.
|
static interface |
AdsLoader.EventListener
Listener for ads loader events.
|
| Modifier and Type | Method and Description |
|---|---|
void |
handlePrepareError(int adGroupIndex,
int adIndexInAdGroup,
java.io.IOException exception)
Notifies the ads loader that the player was not able to prepare media for a given ad.
|
void |
release()
Releases the loader.
|
void |
setPlayer(Player player)
Sets the player that will play the loaded ads.
|
void |
setSupportedContentTypes(int... contentTypes)
Sets the supported content types for ad media.
|
void |
start(AdsLoader.EventListener eventListener,
AdsLoader.AdViewProvider adViewProvider)
Starts using the ads loader for playback.
|
void |
stop()
Stops using the ads loader for playback and deregisters the event listener.
|
void setPlayer(@Nullable
Player player)
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()).
player - The player instance that will play the loaded ads. May be null to delete the
reference to a previously set player.void release()
void setSupportedContentTypes(@C.ContentType int... contentTypes)
start(EventListener, AdViewProvider). Subsequent calls may be ignored. Called on the main
thread by AdsMediaSource.contentTypes - The supported content types for ad media. Each element must be one of
C.TYPE_DASH, C.TYPE_HLS, C.TYPE_SS and C.TYPE_OTHER.void start(AdsLoader.EventListener eventListener, AdsLoader.AdViewProvider adViewProvider)
AdsMediaSource.eventListener - Listener for ads loader events.adViewProvider - Provider of views for the ad UI.void stop()
AdsMediaSource.void handlePrepareError(int adGroupIndex,
int adIndexInAdGroup,
java.io.IOException exception)
AdsMediaSource.adGroupIndex - The index of the ad group.adIndexInAdGroup - The index of the ad in the ad group.exception - The preparation error.