Package com.castlabs.android.adverts

# Class ServerAdLoader

java.lang.Object
com.castlabs.android.adverts.ServerAdLoader

All Implemented Interfaces:
  `AdLoader`

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.

- ## Nested Class Summary

  ## Nested classes/interfaces inherited from interface com.castlabs.android.adverts.AdLoader

  `AdLoader.Listener`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `final void`
  `createMediaSource(PlayerConfig playerConfig, PlayerPlugin playerPlugin, AdLoader.Listener listener)`
  Asynchronously create `MediaSource` to play
  `ViewGroup`
  `getAdContainer()`
  Returns ad UI container
  `void`
  `onContentMediaSource(PlayerConfig playerConfig, com.google.android.exoplayer2.source.MediaSource mediaSource)`
  Notifies the loader of the content `MediaSource` that will be used for playback.
  `void`
  `release()`
  Release any unused resources
  `final 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).
  `void`
  `scheduleAd(AdRequest adRequest)`
  Start loading an `AdRequest`.
  `void`
  `setPlayerController(PlayerController playerController)`
  Set the active `PlayerController` instance or `null` if there is no active `PlayerController` or it is about to be released

  ### Methods inherited from class java.lang.Object

  `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

  ### Methods inherited from interface com.castlabs.android.adverts.AdLoader

  `getAdApi, getAdPositionMs, getCurrentAd, maybeWrapMediaSource, onPlayerStateChanged, onPositionDiscontinuity, onSetPosition`

- ## 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 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:
      `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 the content `MediaSource` that will be used for playback. This is invoked only for loaders that do not require a media-source hook.
    Specified by:
      `onContentMediaSource` in interface `AdLoader`
    Parameters:
      `playerConfig` - The `PlayerConfig` associated with the media source.
      `mediaSource` - The content media source that will be prepared.