Package com.castlabs.android.adverts
Interface AdLoader
- All Known Implementing Classes:
HlsInterstitialAdLoader,ServerAdLoader
public interface AdLoader
The interface to provide SDK with the
Ad properties
The implementations are used by ClientAdProvider.createAdLoader(AdRequest)- Since:
- 4.2.0
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionvoidcreateMediaSource(PlayerConfig playerConfig, PlayerPlugin playerPlugin, AdLoader.Listener listener) Asynchronously createMediaSourceto playgetAdApi()Get anAdApito issue custom operations to the ad providerReturns ad UI containerlonggetAdPositionMs(Ad ad, com.google.android.exoplayer2.ExoPlayer player) Returns the position of the providedAdin milliseconds relative to the window that is currently playing (i.e.Get the currently loaded and prepared for playing Addefault com.google.android.exoplayer2.source.MediaSourcemaybeWrapMediaSource(com.google.android.exoplayer2.source.MediaSource mediaSource, PlayerConfig playerConfig) Optionally wraps the givenMediaSourcewith anotherMediaSource.default voidonContentMediaSource(PlayerConfig playerConfig, com.google.android.exoplayer2.source.MediaSource mediaSource) Notifies the loader of the contentMediaSourcethat will be used for playback.voidonPlayerStateChanged(boolean playWhenReady, int playbackState) Called when the player state is changedvoidonPositionDiscontinuity(int reason) Called when the playback discontinuity occurslongonSetPosition(long newPositionUs) Called just before thePlayerControllerstart seeking or setting a new position.voidrelease()Release any unused resourcesdefault booleanIndicates whether this loader needs to create its own media source (client-side ads) or whether it operates on the content media source prepared by the player (server-side ads).voidscheduleAd(AdRequest adRequest) Start loading anAdRequest.voidsetPlayerController(PlayerController playerController) Set the activePlayerControllerinstance ornullif there is no activePlayerControlleror it is about to be released
-
Method Details
-
getCurrentAd
Get the currently loaded and prepared for playing Ad- Returns:
- The current Ad or
null
-
getAdContainer
Returns ad UI container- Returns:
- ad UI container
-
setPlayerController
Set the activePlayerControllerinstance ornullif there is no activePlayerControlleror it is about to be released- Parameters:
playerController- ThePlayerControllerinstance ornull
-
release
void release()Release any unused resources -
requiresMediaSourceHook
default boolean requiresMediaSourceHook()Indicates whether this loader needs to create its own media source (client-side ads) or whether it operates on the content media source prepared by the player (server-side ads).- Returns:
trueif a media-source hook is required,falseotherwise.
-
createMediaSource
void createMediaSource(@NonNull PlayerConfig playerConfig, @NonNull PlayerPlugin playerPlugin, @NonNull AdLoader.Listener listener) Asynchronously createMediaSourceto play- Parameters:
playerConfig- ThePlayerConfigplayerPlugin- ThePlayerPluginlistener- The listener callback to provide the createdMediaSource
-
onSetPosition
long onSetPosition(long newPositionUs) Called just before thePlayerControllerstart seeking or setting a new position. Can be used when the new position has to be adjusted by theAdLoaderimplementation e.g. to do ads snap back. If the adjustment is not needed then the provided position can simply be returned.- Parameters:
newPositionUs- The new position in microseconds- Returns:
- The adjusted position in microseconds
-
onPlayerStateChanged
void onPlayerStateChanged(boolean playWhenReady, int playbackState) Called when the player state is changed- Parameters:
playWhenReady- Play when ready flagplaybackState- Playback state
-
onPositionDiscontinuity
void onPositionDiscontinuity(@DiscontinuityReason int reason) Called when the playback discontinuity occurs- Parameters:
reason- The reason for discontinuity
-
scheduleAd
Start loading anAdRequest. This may be also called during playback. Support for on-request ad scheduling depends on the AdLoader implementation.- Parameters:
adRequest- The ad request to perform.
-
getAdApi
Get anAdApito issue custom operations to the ad provider- Returns:
- the
AdApi
-
maybeWrapMediaSource
default com.google.android.exoplayer2.source.MediaSource maybeWrapMediaSource(com.google.android.exoplayer2.source.MediaSource mediaSource, PlayerConfig playerConfig) Optionally wraps the givenMediaSourcewith anotherMediaSource. This can be used to add custom behavior to theMediaSourcebefore it is used by the player. By default, this method returns the originalMediaSource.- Parameters:
mediaSource- The originalMediaSource.playerConfig- ThePlayerConfigto be used by the player.- Returns:
- The wrapped
MediaSource, or the originalMediaSourceif no wrapping is needed.
-
getAdPositionMs
Returns the position of the providedAdin milliseconds relative to the window that is currently playing (i.e. the media period exposed byPlayer.getCurrentWindowIndex()). Implementations that operate on concatenated timelines must therefore normalize the ad offset to the active window instead of returning a global playlist position.- Parameters:
ad- The ad for which the position should be resolved.player- The player instance that provides the current window context.- Returns:
- The ad start position in milliseconds, relative to the currently playing window.
-
onContentMediaSource
default void onContentMediaSource(@NonNull PlayerConfig playerConfig, @NonNull com.google.android.exoplayer2.source.MediaSource mediaSource) Notifies the loader of the contentMediaSourcethat will be used for playback. This is invoked only for loaders that do not require a media-source hook.- Parameters:
playerConfig- ThePlayerConfigassociated with the media source.mediaSource- The content media source that will be prepared.
-