Class ServerAdLoader

java.lang.Object
com.castlabs.android.adverts.ServerAdLoader
All Implemented Interfaces:
AdLoader
Direct Known Subclasses:
HlsInterstitialAdLoader

public abstract class ServerAdLoader extends Object implements AdLoader
Base class for server-side ad loaders that operate on top of the content media source instead of providing a custom media source hook.
  • Method Details

    • getAdContainer

      @Nullable public ViewGroup getAdContainer()
      Description copied from interface: AdLoader
      Returns ad UI container
      Specified by:
      getAdContainer in interface AdLoader
      Returns:
      ad UI container
    • setPlayerController

      @CallSuper public void setPlayerController(@Nullable PlayerController playerController)
      Description copied from interface: AdLoader
      Set the active PlayerController instance or null if there is no active PlayerController or it is about to be released
      Specified by:
      setPlayerController in interface AdLoader
      Parameters:
      playerController - The PlayerController instance or null
    • release

      @CallSuper public void release()
      Description copied from interface: AdLoader
      Release any unused resources
      Specified by:
      release in interface AdLoader
    • requiresMediaSourceHook

      public final boolean requiresMediaSourceHook()
      Description copied from interface: AdLoader
      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).
      Specified by:
      requiresMediaSourceHook in interface AdLoader
      Returns:
      true if a media-source hook is required, false otherwise.
    • createMediaSource

      public final void createMediaSource(@NonNull Object adsId, @NonNull PlayerConfig playerConfig, @NonNull PlayerPlugin playerPlugin, @NonNull AdLoader.Listener listener)
      Description copied from interface: AdLoader
      Asynchronously create MediaSource to play
      Specified by:
      createMediaSource in interface AdLoader
      Parameters:
      adsId - The unique to this PlayerConfig's ads id
      playerConfig - The PlayerConfig
      playerPlugin - The PlayerPlugin
      listener - The listener callback to provide the created MediaSource
    • scheduleAd

      public void scheduleAd(@NonNull AdRequest adRequest)
      Description copied from interface: AdLoader
      Start loading an AdRequest. This may be also called during playback. Support for on-request ad scheduling depends on the AdLoader implementation.
      Specified by:
      scheduleAd in interface AdLoader
      Parameters:
      adRequest - The ad request to perform.
    • onContentMediaSource

      public void onContentMediaSource(@NonNull PlayerConfig playerConfig, @NonNull com.google.android.exoplayer2.source.MediaSource mediaSource)
      Description copied from interface: AdLoader
      Notifies the loader of a content MediaSource that has just been built and will be used for playback.

      Called synchronously while the source is being created, before it is prepared, once per built source. A playlist rebuilds an item's media source whenever the item is evicted, refreshed, or removed and re-added, so one PlayerConfig can produce a sequence of media sources over its lifetime and each one is reported here. State recorded against the configuration must therefore be keyed, or at least validated, by media-source instance; AdLoader.onContentMediaSourceReleased(PlayerConfig, MediaSource) reports the retirement of each one.
      Specified by:
      onContentMediaSource in interface AdLoader
      Parameters:
      playerConfig - The PlayerConfig associated with the media source.
      mediaSource - The content media source that will be prepared.