Package com.castlabs.android.adverts
Class HlsInterstitialAdLoader
java.lang.Object
com.castlabs.android.adverts.HlsInterstitialAdLoader
- All Implemented Interfaces:
AdLoader
AdLoader implementation for handling HLS interstitial ads using ExoPlayer's HlsInterstitialMediaSource.
This class manages ad scheduling, playback state, and ad group tracking for HLS streams.
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.castlabs.android.adverts.AdLoader
AdLoader.Listener -
Constructor Summary
Constructors -
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 containerGet the currently loaded and prepared for playing Adcom.google.android.exoplayer2.source.MediaSourcemaybeWrapMediaSource(com.google.android.exoplayer2.source.MediaSource mediaSource, PlayerConfig playerConfig) Optionally wraps the givenMediaSourcewith anotherMediaSource.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 resourcesvoidscheduleAd(AdRequest adRequest) Start loading anAdRequest.voidsetPlayerController(PlayerController playerController) Set the activePlayerControllerinstance ornullif there is no activePlayerControlleror it is about to be released
-
Constructor Details
-
HlsInterstitialAdLoader
public HlsInterstitialAdLoader()Default constructor for HlsInterstitialAdLoader.
-
-
Method Details
-
getCurrentAd
Description copied from interface:AdLoaderGet the currently loaded and prepared for playing Ad- Specified by:
getCurrentAdin interfaceAdLoader- Returns:
- The current Ad or
null
-
getAdContainer
Description copied from interface:AdLoaderReturns ad UI container- Specified by:
getAdContainerin interfaceAdLoader- Returns:
- ad UI container
-
setPlayerController
Description copied from interface:AdLoaderSet the activePlayerControllerinstance ornullif there is no activePlayerControlleror it is about to be released- Specified by:
setPlayerControllerin interfaceAdLoader- Parameters:
playerController- ThePlayerControllerinstance ornull
-
release
public void release()Description copied from interface:AdLoaderRelease any unused resources -
createMediaSource
public void createMediaSource(@NonNull PlayerConfig playerConfig, @NonNull PlayerPlugin playerPlugin, @NonNull AdLoader.Listener listener) Description copied from interface:AdLoaderAsynchronously createMediaSourceto play- Specified by:
createMediaSourcein interfaceAdLoader- Parameters:
playerConfig- ThePlayerConfigplayerPlugin- ThePlayerPluginlistener- The listener callback to provide the createdMediaSource
-
onSetPosition
public long onSetPosition(long newPositionUs) Description copied from interface:AdLoaderCalled 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.- Specified by:
onSetPositionin interfaceAdLoader- Parameters:
newPositionUs- The new position in microseconds- Returns:
- The adjusted position in microseconds
-
onPlayerStateChanged
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) Description copied from interface:AdLoaderCalled when the player state is changed- Specified by:
onPlayerStateChangedin interfaceAdLoader- Parameters:
playWhenReady- Play when ready flagplaybackState- Playback state
-
onPositionDiscontinuity
public void onPositionDiscontinuity(int reason) Description copied from interface:AdLoaderCalled when the playback discontinuity occurs- Specified by:
onPositionDiscontinuityin interfaceAdLoader- Parameters:
reason- The reason for discontinuity
-
scheduleAd
Description copied from interface:AdLoaderStart loading anAdRequest. This may be also called during playback. Support for on-request ad scheduling depends on the AdLoader implementation.- Specified by:
scheduleAdin interfaceAdLoader- Parameters:
adRequest- The ad request to perform.
-
getAdApi
Description copied from interface:AdLoaderGet anAdApito issue custom operations to the ad provider -
maybeWrapMediaSource
public com.google.android.exoplayer2.source.MediaSource maybeWrapMediaSource(com.google.android.exoplayer2.source.MediaSource mediaSource, PlayerConfig playerConfig) Description copied from interface:AdLoaderOptionally 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.- Specified by:
maybeWrapMediaSourcein interfaceAdLoader- Parameters:
mediaSource- The originalMediaSource.playerConfig- ThePlayerConfigto be used by the player.- Returns:
- The wrapped
MediaSource, or the originalMediaSourceif no wrapping is needed.
-