ImaAdsLoader.Builder


public final class ImaAdsLoader.Builder


Builder for ImaAdsLoader.

Summary

Constants

static final long

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.

Public constructors

Builder(Context context)

Creates a new builder for ImaAdsLoader.

Public methods

ImaAdsLoader

Returns a new ImaAdsLoader.

ImaAdsLoader.Builder

Sets a listener for ad errors that will be passed to addAdErrorListener and addAdErrorListener.

ImaAdsLoader.Builder

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

ImaAdsLoader.Builder

Sets the MIME types to prioritize for linear ad media.

ImaAdsLoader.Builder

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

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

ImaAdsLoader.Builder

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

ImaAdsLoader.Builder

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

ImaAdsLoader.Builder

Sets whether to enable continuous playback.

ImaAdsLoader.Builder

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

ImaAdsLoader.Builder

Sets the IMA SDK settings.

ImaAdsLoader.Builder

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

ImaAdsLoader.Builder
@CanIgnoreReturnValue
@UnstableApi
setMediaLoadTimeoutMs(@IntRange(from = 1) int mediaLoadTimeoutMs)

Sets the ad media load timeout, in milliseconds.

ImaAdsLoader.Builder

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

ImaAdsLoader.Builder
@CanIgnoreReturnValue
@UnstableApi
setVastLoadTimeoutMs(@IntRange(from = 1) int vastLoadTimeoutMs)

Sets the VAST load timeout, in milliseconds.

ImaAdsLoader.Builder

Sets a callback to receive video ad player events.

Constants

DEFAULT_AD_PRELOAD_TIMEOUT_MS

@UnstableApi
public static final long DEFAULT_AD_PRELOAD_TIMEOUT_MS = 10000

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.

Public constructors

Builder

public Builder(Context context)

Creates a new builder for ImaAdsLoader.

Parameters
Context context

The context;

Public methods

build

public ImaAdsLoader build()

Returns a new ImaAdsLoader.

setAdErrorListener

@CanIgnoreReturnValue
@UnstableApi
public ImaAdsLoader.Builder setAdErrorListener(AdErrorEvent.AdErrorListener adErrorListener)

Sets a listener for ad errors that will be passed to addAdErrorListener and addAdErrorListener.

Parameters
AdErrorEvent.AdErrorListener adErrorListener

The ad error listener.

Returns
ImaAdsLoader.Builder

This builder, for convenience.

setAdEventListener

@CanIgnoreReturnValue
@UnstableApi
public ImaAdsLoader.Builder setAdEventListener(AdEvent.AdEventListener adEventListener)

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

Parameters
AdEvent.AdEventListener adEventListener

The ad event listener.

Returns
ImaAdsLoader.Builder

This builder, for convenience.

setAdMediaMimeTypes

@CanIgnoreReturnValue
@UnstableApi
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 will be used.

Parameters
List<String> adMediaMimeTypes

The MIME types to prioritize for linear ad media. May contain APPLICATION_MPD, APPLICATION_M3U8, VIDEO_MP4, VIDEO_WEBM, VIDEO_H263, AUDIO_MP4 and AUDIO_MPEG.

Returns
ImaAdsLoader.Builder

This builder, for convenience.

See also
setMimeTypes

setAdPreloadTimeoutMs

@CanIgnoreReturnValue
@UnstableApi
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 TIME_UNSET if there should be no such timeout. The default value is 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
long adPreloadTimeoutMs

The timeout buffering duration in milliseconds, or TIME_UNSET for no timeout.

Returns
ImaAdsLoader.Builder

This builder, for convenience.

setAdUiElements

@CanIgnoreReturnValue
@UnstableApi
public ImaAdsLoader.Builder setAdUiElements(Set<UiElement> adUiElements)

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

Parameters
Set<UiElement> adUiElements

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

Returns
ImaAdsLoader.Builder

This builder, for convenience.

See also
setUiElements

setCompanionAdSlots

@CanIgnoreReturnValue
@UnstableApi
public ImaAdsLoader.Builder setCompanionAdSlots(Collection<CompanionAdSlot> companionAdSlots)

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

Parameters
Collection<CompanionAdSlot> companionAdSlots

The slots to use for companion ads.

Returns
ImaAdsLoader.Builder

This builder, for convenience.

setDebugModeEnabled

@CanIgnoreReturnValue
@UnstableApi
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
boolean debugModeEnabled

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

Returns
ImaAdsLoader.Builder

This builder, for convenience.

See also
setDebugMode

setEnableContinuousPlayback

@CanIgnoreReturnValue
@UnstableApi
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
boolean enableContinuousPlayback

Whether to enable continuous playback.

Returns
ImaAdsLoader.Builder

This builder, for convenience.

setFocusSkipButtonWhenAvailable

@CanIgnoreReturnValue
@UnstableApi
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
boolean focusSkipButtonWhenAvailable

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

Returns
ImaAdsLoader.Builder

This builder, for convenience.

setImaSdkSettings

@CanIgnoreReturnValue
@UnstableApi
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 imaSdkSettings

The ImaSdkSettings.

Returns
ImaAdsLoader.Builder

This builder, for convenience.

setMaxMediaBitrate

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

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

Parameters
@IntRange(from = 1) int bitrate

The media maximum recommended bitrate for ads, in bps.

Returns
ImaAdsLoader.Builder

This builder, for convenience.

See also
setBitrateKbps

setMediaLoadTimeoutMs

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

Sets the ad media load timeout, in milliseconds.

Parameters
@IntRange(from = 1) int mediaLoadTimeoutMs

The ad media load timeout, in milliseconds.

Returns
ImaAdsLoader.Builder

This builder, for convenience.

setPlayAdBeforeStartPosition

@CanIgnoreReturnValue
@UnstableApi
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
boolean playAdBeforeStartPosition

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

Returns
ImaAdsLoader.Builder

This builder, for convenience.

setVastLoadTimeoutMs

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

Sets the VAST load timeout, in milliseconds.

Parameters
@IntRange(from = 1) int vastLoadTimeoutMs

The VAST load timeout, in milliseconds.

Returns
ImaAdsLoader.Builder

This builder, for convenience.

setVideoAdPlayerCallback

@CanIgnoreReturnValue
@UnstableApi
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
VideoAdPlayer.VideoAdPlayerCallback videoAdPlayerCallback

The callback to receive video ad player events.

Returns
ImaAdsLoader.Builder

This builder, for convenience.