public interface AdsLoader
AdsMediaSource.
Ad 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).
attachPlayer(ExoPlayer, EventListener, ViewGroup) will be called when the ads media
source first initializes, at which point the loader can request ads. If the player enters the
background, detachPlayer() will be called. Loaders should maintain any ad playback state
in preparation for a later call to attachPlayer(ExoPlayer, EventListener, ViewGroup). 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 attachPlayer(ExoPlayer, EventListener, ViewGroup) should invoke the
same listener to provide the existing playback state to the new player.
| Modifier and Type | Interface and Description |
|---|---|
static interface |
AdsLoader.EventListener
Listener for ad loader events.
|
| Modifier and Type | Method and Description |
|---|---|
void |
attachPlayer(ExoPlayer player,
AdsLoader.EventListener eventListener,
android.view.ViewGroup adUiViewGroup)
Attaches a player that will play ads loaded using this instance.
|
void |
detachPlayer()
Detaches the attached player and event listener.
|
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 |
setSupportedContentTypes(int... contentTypes)
Sets the supported content types for ad media.
|
void setSupportedContentTypes(int... contentTypes)
attachPlayer(ExoPlayer, EventListener, ViewGroup). Subsequent calls may be ignored.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 attachPlayer(ExoPlayer player, AdsLoader.EventListener eventListener, android.view.ViewGroup adUiViewGroup)
AdsMediaSource.player - The player instance that will play the loaded ads.eventListener - Listener for ads loader events.adUiViewGroup - A ViewGroup on top of the player that will show any ad UI.void detachPlayer()
AdsMediaSource.void release()
void handlePrepareError(int adGroupIndex,
int adIndexInAdGroup,
java.io.IOException exception)
adGroupIndex - The index of the ad group.adIndexInAdGroup - The index of the ad in the ad group.exception - The preparation error.