Package com.castlabs.android.adverts

## Interface AdLoader

-     public interface AdLoader

  The interface to provide SDK with the `Ad` properties The implementations are used by `AdProvider.createAdLoader(AdRequest)`
  Since:
    4.2.0

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Interface | Description
    --- | --- | ---
    `static interface` | `AdLoader.Listener` |

  - ### Method Summary

    All Methods Instance Methods Abstract Methods
    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
    `Ad` | `getCurrentAd()` | Get the currently loaded and prepared for playing Ad
    `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
    `void` | `showAdUi​(boolean showUi)` | Whether to show the default ad UI from the ad provider

- - ### Method Detail

    - #### getCurrentAd

          @Nullable
          Ad getCurrentAd()

      Get the currently loaded and prepared for playing Ad
      Returns:
        The current Ad or `null`

    - #### getAdContainer

          @Nullable
          ViewGroup getAdContainer()

      Returns ad UI container
      Returns:
        ad UI container

    - #### setPlayerController

          void setPlayerController​(@Nullable
                                   PlayerController playerController)

      Set the active `PlayerController` instance or `null` if there is no active `PlayerController` or it is about to be released
      Parameters:
        `playerController` - The `PlayerController` instance or `null`

    - #### release

          void release()

      Release any unused resources

    - #### createMediaSource

          void createMediaSource​(@NonNull
                                 PlayerConfig playerConfig,
                                 @NonNull
                                 PlayerPlugin playerPlugin,
                                 @NonNull
                                 AdLoader.Listener listener)

      Asynchronously create `MediaSource` to play
      Parameters:
        `playerConfig` - The `PlayerConfig`
        `playerPlugin` - The `PlayerPlugin`
        `listener` - The listener callback to provide the created `MediaSource`

    - #### onSetPosition

          long onSetPosition​(long newPositionUs)

      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

          void onPlayerStateChanged​(boolean playWhenReady,
                                    int playbackState)

      Called when the player state is changed
      Parameters:
        `playWhenReady` - Play when ready flag
        `playbackState` - Playback state

    - #### onPositionDiscontinuity

          void onPositionDiscontinuity​(@DiscontinuityReason
                                       int reason)

      Called when the playback discontinuity occurs
      Parameters:
        `reason` - The reason for discontinuity

    - #### scheduleAd

          void scheduleAd​(@NonNull
                          AdRequest adRequest)

      Start loading an `AdRequest`. This may be also called during playback. Support for on-request ad scheduling depends on the AdLoader implementation.
      Parameters:
        `adRequest` - The ad request to perform.

    - #### showAdUi

          void showAdUi​(boolean showUi)

      Whether to show the default ad UI from the ad provider
      Parameters:
        `showUi` - show the ui

    - #### getAdApi

          @Nullable
          AdApi getAdApi()

      Get an `AdApi` to issue custom operations to the ad provider
      Returns:
        the `AdApi`