public final class

ImaAdsLoader.Builder

extends java.lang.Object

 java.lang.Object

↳androidx.media3.exoplayer.ima.ImaAdsLoader.Builder

Overview

Builder for ImaAdsLoader.

Summary

Fields
public static final longDEFAULT_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.

Constructors
publicBuilder(Context context)

Creates a new builder for ImaAdsLoader.

Methods
public ImaAdsLoaderbuild()

Returns a new ImaAdsLoader.

public ImaAdsLoader.BuildersetAdErrorListener(AdErrorListener adErrorListener)

Sets a listener for ad errors that will be passed to com.google.ads.interactivemedia.v3.api.AdsLoader and .

public ImaAdsLoader.BuildersetAdEventListener(AdEventListener adEventListener)

Sets a listener for ad events that will be passed to .

public ImaAdsLoader.BuildersetAdMediaMimeTypes(java.util.List<java.lang.String> adMediaMimeTypes)

Sets the MIME types to prioritize for linear ad media.

public ImaAdsLoader.BuildersetAdPreloadTimeoutMs(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.

public ImaAdsLoader.BuildersetAdUiElements(java.util.Set<UiElement> adUiElements)

Sets the ad UI elements to be rendered by the IMA SDK.

public ImaAdsLoader.BuildersetCompanionAdSlots(java.util.Collection<CompanionAdSlot> companionAdSlots)

Sets the slots to use for companion ads, if they are present in the loaded ad.

public ImaAdsLoader.BuildersetDebugModeEnabled(boolean debugModeEnabled)

Sets whether to enable outputting verbose logs for the IMA extension and IMA SDK.

public ImaAdsLoader.BuildersetEnableContinuousPlayback(boolean enableContinuousPlayback)

Sets whether to enable continuous playback.

public ImaAdsLoader.BuildersetFocusSkipButtonWhenAvailable(boolean focusSkipButtonWhenAvailable)

Sets whether to focus the skip button (when available) on Android TV devices.

public ImaAdsLoader.BuildersetImaSdkSettings(ImaSdkSettings imaSdkSettings)

Sets the IMA SDK settings.

public ImaAdsLoader.BuildersetMaxMediaBitrate(int bitrate)

Sets the media maximum recommended bitrate for ads, in bps.

public ImaAdsLoader.BuildersetMediaLoadTimeoutMs(int mediaLoadTimeoutMs)

Sets the ad media load timeout, in milliseconds.

public ImaAdsLoader.BuildersetPlayAdBeforeStartPosition(boolean playAdBeforeStartPosition)

Sets whether to play an ad before the start position when beginning playback.

public ImaAdsLoader.BuildersetVastLoadTimeoutMs(int vastLoadTimeoutMs)

Sets the VAST load timeout, in milliseconds.

public ImaAdsLoader.BuildersetVideoAdPlayerCallback(VideoAdPlayer.VideoAdPlayerCallback videoAdPlayerCallback)

Sets a callback to receive video ad player events.

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Fields

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: ImaAdsLoader.Builder.setAdPreloadTimeoutMs(long)

Constructors

public Builder(Context context)

Creates a new builder for ImaAdsLoader.

Parameters:

context: The context;

Methods

public ImaAdsLoader.Builder setImaSdkSettings(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 .

Returns:

This builder, for convenience.

public ImaAdsLoader.Builder setAdErrorListener(AdErrorListener adErrorListener)

Sets a listener for ad errors that will be passed to com.google.ads.interactivemedia.v3.api.AdsLoader and .

Parameters:

adErrorListener: The ad error listener.

Returns:

This builder, for convenience.

public ImaAdsLoader.Builder setAdEventListener(AdEventListener adEventListener)

Sets a listener for ad events that will be passed to .

Parameters:

adEventListener: The ad event listener.

Returns:

This builder, for convenience.

public ImaAdsLoader.Builder setVideoAdPlayerCallback(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:

public ImaAdsLoader.Builder setAdUiElements(java.util.Set<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:

public ImaAdsLoader.Builder setCompanionAdSlots(java.util.Collection<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:

public ImaAdsLoader.Builder setAdMediaMimeTypes(java.util.List<java.lang.String> adMediaMimeTypes)

Sets the MIME types to prioritize for linear ad media. If not specified, MIME types supported by the 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:

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:

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 ImaAdsLoader.Builder.DEFAULT_AD_PRELOAD_TIMEOUT_MS 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.

public ImaAdsLoader.Builder setVastLoadTimeoutMs(int vastLoadTimeoutMs)

Sets the VAST load timeout, in milliseconds.

Parameters:

vastLoadTimeoutMs: The VAST load timeout, in milliseconds.

Returns:

This builder, for convenience.

See also:

public ImaAdsLoader.Builder setMediaLoadTimeoutMs(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:

public ImaAdsLoader.Builder setMaxMediaBitrate(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:

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:

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.

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:

public ImaAdsLoader build()

Returns a new ImaAdsLoader.