Package com.google.android.exoplayer2.ext.ima

## Class ImaAdsLoader.Builder

- java.lang.Object
- - com.google.android.exoplayer2.ext.ima.ImaAdsLoader.Builder

- Enclosing class:
    ImaAdsLoader

      public static final class ImaAdsLoader.Builder
      extends Object

  Builder for `ImaAdsLoader`.

- - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `static long` | `DEFAULT_AD_PRELOAD_TIMEOUT_MS` | The default duration in milliseconds for which the player must buffer while preloading an ad group before that ad group is skipped and marked as having failed to load.

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `Builder​(Context context)` | Creates a new builder for `ImaAdsLoader`.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `ImaAdsLoader` | `build()` | Returns a new `ImaAdsLoader`.
    `ImaAdsLoader.Builder` | `setAdErrorListener​(com.google.ads.interactivemedia.v3.api.AdErrorEvent.AdErrorListener adErrorListener)` | Sets a listener for ad errors that will be passed to `AdsLoader.addAdErrorListener(AdErrorListener)` and `BaseManager.addAdErrorListener(AdErrorListener)`.
    `ImaAdsLoader.Builder` | `setAdEventListener​(com.google.ads.interactivemedia.v3.api.AdEvent.AdEventListener adEventListener)` | Sets a listener for ad events that will be passed to `BaseManager.addAdEventListener(AdEventListener)`.
    `ImaAdsLoader.Builder` | `setAdMediaMimeTypes​(List<String> adMediaMimeTypes)` | Sets the MIME types to prioritize for linear ad media.
    `ImaAdsLoader.Builder` | `setAdPreloadTimeoutMs​(long adPreloadTimeoutMs)` | Sets the duration in milliseconds for which the player must buffer while preloading an ad group before that ad group is skipped and marked as having failed to load.
    `ImaAdsLoader.Builder` | `setAdUiElements​(Set<com.google.ads.interactivemedia.v3.api.UiElement> adUiElements)` | Sets the ad UI elements to be rendered by the IMA SDK.
    `ImaAdsLoader.Builder` | `setCompanionAdSlots​(Collection<com.google.ads.interactivemedia.v3.api.CompanionAdSlot> companionAdSlots)` | Sets the slots to use for companion ads, if they are present in the loaded ad.
    `ImaAdsLoader.Builder` | `setDebugModeEnabled​(boolean debugModeEnabled)` | Sets whether to enable outputting verbose logs for the IMA extension and IMA SDK.
    `ImaAdsLoader.Builder` | `setEnableContinuousPlayback​(boolean enableContinuousPlayback)` | Sets whether to enable continuous playback.
    `ImaAdsLoader.Builder` | `setFocusSkipButtonWhenAvailable​(boolean focusSkipButtonWhenAvailable)` | Sets whether to focus the skip button (when available) on Android TV devices.
    `ImaAdsLoader.Builder` | `setImaSdkSettings​(com.google.ads.interactivemedia.v3.api.ImaSdkSettings imaSdkSettings)` | Sets the IMA SDK settings.
    `ImaAdsLoader.Builder` | `setMaxMediaBitrate​(int bitrate)` | Sets the media maximum recommended bitrate for ads, in bps.
    `ImaAdsLoader.Builder` | `setMediaLoadTimeoutMs​(int mediaLoadTimeoutMs)` | Sets the ad media load timeout, in milliseconds.
    `ImaAdsLoader.Builder` | `setPlayAdBeforeStartPosition​(boolean playAdBeforeStartPosition)` | Sets whether to play an ad before the start position when beginning playback.
    `ImaAdsLoader.Builder` | `setVastLoadTimeoutMs​(int vastLoadTimeoutMs)` | Sets the VAST load timeout, in milliseconds.
    `ImaAdsLoader.Builder` | `setVideoAdPlayerCallback​(com.google.ads.interactivemedia.v3.api.player.VideoAdPlayer.VideoAdPlayerCallback videoAdPlayerCallback)` | Sets a callback to receive video ad player events.

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

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

- - ### Field Detail

    - #### DEFAULT_AD_PRELOAD_TIMEOUT_MS

          public static final long DEFAULT_AD_PRELOAD_TIMEOUT_MS

      The default duration in milliseconds for which the player must buffer while preloading an ad group before that ad group is skipped and marked as having failed to load.

      This value should be large enough not to trigger discarding the ad when it actually might load soon, but small enough so that user is not waiting for too long.

      See Also:
        `setAdPreloadTimeoutMs(long)`, Constant Field Values

  - ### Constructor Detail

    - #### Builder

          public Builder​(Context context)

      Creates a new builder for `ImaAdsLoader`.
      Parameters:
        `context` - The context;

  - ### Method Detail

    - #### setImaSdkSettings

          @CanIgnoreReturnValue
          public ImaAdsLoader.Builder setImaSdkSettings​(com.google.ads.interactivemedia.v3.api.ImaSdkSettings imaSdkSettings)

      Sets the IMA SDK settings. The provided settings instance's player type and version fields may be overwritten.

      If this method is not called the default settings will be used.

      Parameters:
        `imaSdkSettings` - The `ImaSdkSettings`.
      Returns:
        This builder, for convenience.

    - #### setAdErrorListener

          @CanIgnoreReturnValue
          public ImaAdsLoader.Builder setAdErrorListener​(com.google.ads.interactivemedia.v3.api.AdErrorEvent.AdErrorListener adErrorListener)

      Sets a listener for ad errors that will be passed to `AdsLoader.addAdErrorListener(AdErrorListener)` and `BaseManager.addAdErrorListener(AdErrorListener)`.
      Parameters:
        `adErrorListener` - The ad error listener.
      Returns:
        This builder, for convenience.

    - #### setAdEventListener

          @CanIgnoreReturnValue
          public ImaAdsLoader.Builder setAdEventListener​(com.google.ads.interactivemedia.v3.api.AdEvent.AdEventListener adEventListener)

      Sets a listener for ad events that will be passed to `BaseManager.addAdEventListener(AdEventListener)`.
      Parameters:
        `adEventListener` - The ad event listener.
      Returns:
        This builder, for convenience.

    - #### setVideoAdPlayerCallback

          @CanIgnoreReturnValue
          public ImaAdsLoader.Builder setVideoAdPlayerCallback​(com.google.ads.interactivemedia.v3.api.player.VideoAdPlayer.VideoAdPlayerCallback videoAdPlayerCallback)

      Sets a callback to receive video ad player events. Note that these events are handled internally by the IMA SDK and this ads loader. For analytics and diagnostics, new implementations should generally use events from the top-level `Player` listeners instead of setting a callback via this method.
      Parameters:
        `videoAdPlayerCallback` - The callback to receive video ad player events.
      Returns:
        This builder, for convenience.
      See Also:
        `VideoAdPlayer.VideoAdPlayerCallback`

    - #### setAdUiElements

          @CanIgnoreReturnValue
          public ImaAdsLoader.Builder setAdUiElements​(Set<com.google.ads.interactivemedia.v3.api.UiElement> adUiElements)

      Sets the ad UI elements to be rendered by the IMA SDK.
      Parameters:
        `adUiElements` - The ad UI elements to be rendered by the IMA SDK.
      Returns:
        This builder, for convenience.
      See Also:
        `AdsRenderingSettings.setUiElements(Set)`

    - #### setCompanionAdSlots

          @CanIgnoreReturnValue
          public ImaAdsLoader.Builder setCompanionAdSlots​(Collection<com.google.ads.interactivemedia.v3.api.CompanionAdSlot> companionAdSlots)

      Sets the slots to use for companion ads, if they are present in the loaded ad.
      Parameters:
        `companionAdSlots` - The slots to use for companion ads.
      Returns:
        This builder, for convenience.
      See Also:
        `BaseDisplayContainer.setCompanionSlots(Collection)`

    - #### setAdMediaMimeTypes

          @CanIgnoreReturnValue
          public ImaAdsLoader.Builder setAdMediaMimeTypes​(List<String> adMediaMimeTypes)

      Sets the MIME types to prioritize for linear ad media. If not specified, MIME types supported by the `adMediaSourceFactory` used to construct the `AdsMediaSource` will be used.
      Parameters:
        `adMediaMimeTypes` - The MIME types to prioritize for linear ad media. May contain `MimeTypes.APPLICATION_MPD`, `MimeTypes.APPLICATION_M3U8`, `MimeTypes.VIDEO_MP4`, `MimeTypes.VIDEO_WEBM`, `MimeTypes.VIDEO_H263`, `MimeTypes.AUDIO_MP4` and `MimeTypes.AUDIO_MPEG`.
      Returns:
        This builder, for convenience.
      See Also:
        `AdsRenderingSettings.setMimeTypes(List)`

    - #### setEnableContinuousPlayback

          @CanIgnoreReturnValue
          public ImaAdsLoader.Builder setEnableContinuousPlayback​(boolean enableContinuousPlayback)

      Sets whether to enable continuous playback. Pass `true` if content videos will be played continuously, similar to a TV broadcast. This setting may modify the ads request but does not affect ad playback behavior. The requested value is unknown by default.
      Parameters:
        `enableContinuousPlayback` - Whether to enable continuous playback.
      Returns:
        This builder, for convenience.
      See Also:
        `AdsRequest.setContinuousPlayback(boolean)`

    - #### setAdPreloadTimeoutMs

          @CanIgnoreReturnValue
          public ImaAdsLoader.Builder setAdPreloadTimeoutMs​(long adPreloadTimeoutMs)

      Sets the duration in milliseconds for which the player must buffer while preloading an ad group before that ad group is skipped and marked as having failed to load. Pass `C.TIME_UNSET` if there should be no such timeout. The default value is 10000L ms.

      The purpose of this timeout is to avoid playback getting stuck in the unexpected case that the IMA SDK does not load an ad break based on the player's reported content position.

      Parameters:
        `adPreloadTimeoutMs` - The timeout buffering duration in milliseconds, or `C.TIME_UNSET` for no timeout.
      Returns:
        This builder, for convenience.

    - #### setVastLoadTimeoutMs

          @CanIgnoreReturnValue
          public ImaAdsLoader.Builder setVastLoadTimeoutMs​(@IntRange(from=1L)
                                                           int vastLoadTimeoutMs)

      Sets the VAST load timeout, in milliseconds.
      Parameters:
        `vastLoadTimeoutMs` - The VAST load timeout, in milliseconds.
      Returns:
        This builder, for convenience.
      See Also:
        `AdsRequest.setVastLoadTimeout(float)`

    - #### setMediaLoadTimeoutMs

          @CanIgnoreReturnValue
          public ImaAdsLoader.Builder setMediaLoadTimeoutMs​(@IntRange(from=1L)
                                                            int mediaLoadTimeoutMs)

      Sets the ad media load timeout, in milliseconds.
      Parameters:
        `mediaLoadTimeoutMs` - The ad media load timeout, in milliseconds.
      Returns:
        This builder, for convenience.
      See Also:
        `AdsRenderingSettings.setLoadVideoTimeout(int)`

    - #### setMaxMediaBitrate

          @CanIgnoreReturnValue
          public ImaAdsLoader.Builder setMaxMediaBitrate​(@IntRange(from=1L)
                                                         int bitrate)

      Sets the media maximum recommended bitrate for ads, in bps.
      Parameters:
        `bitrate` - The media maximum recommended bitrate for ads, in bps.
      Returns:
        This builder, for convenience.
      See Also:
        `AdsRenderingSettings.setBitrateKbps(int)`

    - #### setFocusSkipButtonWhenAvailable

          @CanIgnoreReturnValue
          public ImaAdsLoader.Builder setFocusSkipButtonWhenAvailable​(boolean focusSkipButtonWhenAvailable)

      Sets whether to focus the skip button (when available) on Android TV devices. The default setting is `true`.
      Parameters:
        `focusSkipButtonWhenAvailable` - Whether to focus the skip button (when available) on Android TV devices.
      Returns:
        This builder, for convenience.
      See Also:
        `AdsRenderingSettings.setFocusSkipButtonWhenAvailable(boolean)`

    - #### setPlayAdBeforeStartPosition

          @CanIgnoreReturnValue
          public ImaAdsLoader.Builder setPlayAdBeforeStartPosition​(boolean playAdBeforeStartPosition)

      Sets whether to play an ad before the start position when beginning playback. If `true`, an ad will be played if there is one at or before the start position. If `false`, an ad will be played only if there is one exactly at the start position. The default setting is `true`.
      Parameters:
        `playAdBeforeStartPosition` - Whether to play an ad before the start position when beginning playback.
      Returns:
        This builder, for convenience.

    - #### setDebugModeEnabled

          @CanIgnoreReturnValue
          public ImaAdsLoader.Builder setDebugModeEnabled​(boolean debugModeEnabled)

      Sets whether to enable outputting verbose logs for the IMA extension and IMA SDK. The default value is `false`. This setting is intended for debugging only, and should not be enabled in production applications.
      Parameters:
        `debugModeEnabled` - Whether to enable outputting verbose logs for the IMA extension and IMA SDK.
      Returns:
        This builder, for convenience.
      See Also:
        `ImaSdkSettings.setDebugMode(boolean)`

    - #### build

          public ImaAdsLoader build()

      Returns a new `ImaAdsLoader`.