Package com.castlabs.android.adverts

# Class HlsInterstitialAdLoader

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

All Implemented Interfaces:
  `AdLoader`

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

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `createMediaSource(PlayerConfig playerConfig, PlayerPlugin playerPlugin, AdLoader.Listener listener)`
  Asynchronously create `MediaSource` to play
  `AdApi`
  `getAdApi()`
  Get an `AdApi` to issue custom operations to the ad provider
  `ViewGroup`
  `getAdContainer()`
  Returns ad UI container
  `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
  `com.google.android.exoplayer2.source.MediaSource`
  `maybeWrapMediaSource(com.google.android.exoplayer2.source.MediaSource mediaSource, PlayerConfig playerConfig)`
  Optionally wraps the given `MediaSource` with another `MediaSource`.
  `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 java.lang.Object

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

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

  `onContentMediaSource, requiresMediaSourceHook`

- ## Constructor Details

  - ### HlsInterstitialAdLoader

    public HlsInterstitialAdLoader()
    Default constructor for HlsInterstitialAdLoader.

- ## Method Details

  - ### getCurrentAd

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

  - ### 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

    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

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

  - ### createMediaSource

    public 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`

  - ### 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.
    Specified by:
      `onSetPosition` in interface `AdLoader`
    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
    Specified by:
      `onPlayerStateChanged` in interface `AdLoader`
    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
    Specified by:
      `onPositionDiscontinuity` in interface `AdLoader`
    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`
    Parameters:
      `adRequest` - The ad request to perform.

  - ### getAdApi

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

  - ### maybeWrapMediaSource

    public com.google.android.exoplayer2.source.MediaSource maybeWrapMediaSource(com.google.android.exoplayer2.source.MediaSource mediaSource, PlayerConfig playerConfig)
    Description copied from interface: `AdLoader`
    Optionally wraps the given `MediaSource` with another `MediaSource`. This can be used to add custom behavior to the `MediaSource` before it is used by the player. By default, this method returns the original `MediaSource`.
    Specified by:
      `maybeWrapMediaSource` in interface `AdLoader`
    Parameters:
      `mediaSource` - The original `MediaSource`.
      `playerConfig` - The `PlayerConfig` to be used by the player.
    Returns:
      The wrapped `MediaSource`, or the original `MediaSource` if no wrapping is needed.

  - ### 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.
    Specified by:
      `getAdPositionMs` in interface `AdLoader`
    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.