Package com.castlabs.android.adverts

# Class HlsInterstitialAdLoader

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

All Implemented Interfaces:
  `AdLoader`

public class HlsInterstitialAdLoader extends ServerAdLoader
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
  Constructor
  Description
  `HlsInterstitialAdLoader()`
  Default constructor for HlsInterstitialAdLoader.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `AdApi`
  `getAdApi()`
  Get an `AdApi` to issue custom operations to the ad provider
  `long`
  `getAdPositionMs(Ad ad, com.google.android.exoplayer2.ExoPlayer player)`
  Returns the position of the provided `Ad` in milliseconds relative to the window that is currently playing (i.e.
  `Ad`
  `getCurrentAd()`
  Get the currently loaded and prepared for playing Ad
  `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`
  `onPlayerStateChanged(boolean playWhenReady, int playbackState)`
  Called when the player state is changed
  `void`
  `onPositionDiscontinuity(int reason)`
  Called when the playback discontinuity occurs
  `long`
  `onSetPosition(long newPositionUs)`
  Called just before the `PlayerController` start seeking or setting a new position.
  `void`
  `release()`
  Release any unused resources
  `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 com.castlabs.android.adverts.ServerAdLoader

  `createMediaSource, getAdContainer, requiresMediaSourceHook`

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

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

- ## Constructor Details

  - ### HlsInterstitialAdLoader

    public HlsInterstitialAdLoader()
    Default constructor for HlsInterstitialAdLoader.

- ## Method Details

  - ### setPlayerController

    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`
    Overrides:
      `setPlayerController` in class `ServerAdLoader`
    Parameters:
      `playerController` - The `PlayerController` instance or `null`

  - ### getCurrentAd

    @Nullable public Ad getCurrentAd()
    Description copied from interface: `AdLoader`
    Get the currently loaded and prepared for playing Ad
    Returns:
      The current Ad or `null`

  - ### release

    public void release()
    Description copied from interface: `AdLoader`
    Release any unused resources
    Specified by:
      `release` in interface `AdLoader`
    Overrides:
      `release` in class `ServerAdLoader`

  - ### onSetPosition

    public long onSetPosition(long newPositionUs)
    Description copied from interface: `AdLoader`
    Called just before the `PlayerController` start seeking or setting a new position. Can be used when the new position has to be adjusted by the `AdLoader` implementation 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

    public void onPlayerStateChanged(boolean playWhenReady, int playbackState)
    Description copied from interface: `AdLoader`
    Called when the player state is changed
    Parameters:
      `playWhenReady` - Play when ready flag
      `playbackState` - Playback state

  - ### onPositionDiscontinuity

    public void onPositionDiscontinuity(int reason)
    Description copied from interface: `AdLoader`
    Called when the playback discontinuity occurs
    Parameters:
      `reason` - The reason for discontinuity

  - ### 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`
    Overrides:
      `scheduleAd` in class `ServerAdLoader`
    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`
    Overrides:
      `onContentMediaSource` in class `ServerAdLoader`
    Parameters:
      `playerConfig` - The `PlayerConfig` associated with the media source.
      `mediaSource` - The content media source that will be prepared.

  - ### getAdApi

    @Nullable public AdApi getAdApi()
    Description copied from interface: `AdLoader`
    Get an `AdApi` to issue custom operations to the ad provider
    Returns:
      the `AdApi`

  - ### getAdPositionMs

    public long getAdPositionMs(@NonNull Ad ad, @NonNull com.google.android.exoplayer2.ExoPlayer player)
    Description copied from interface: `AdLoader`
    Returns the position of the provided `Ad` in milliseconds relative to the window that is currently playing (i.e. the media period exposed by `Player.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.