HlsInterstitialsAdsLoader


@UnstableApi
class HlsInterstitialsAdsLoader : AdsLoader


An ads loader that reads interstitials from the HLS playlist, adds them to the AdPlaybackState and passes the ad playback state to onAdPlaybackState.

An ads ID must be unique within the playlist of ExoPlayer. If this is the case, a single HlsInterstitialsAdsLoader instance can be passed to multiple ads media sources. These ad media source can be added to the same playlist as far as each of the sources have a different ads IDs.

Summary

Nested types

A MediaSource.Factory to create a media source to play HLS streams with interstitials.

The state of the given ads ID to resume playback at the given AdPlaybackState.

An asset with a URI and a duration.

Holds a list of assets.

A listener to be notified of events emitted by the ads loader.

A string attribute with its name and value.

Public constructors

Creates an instance with a DefaultDataSource.Factory to read HLS X-ASSET-LIST JSON objects.

Creates an instance.

Public functions

Unit

Adds the given AdsResumptionState to resume playback of the AdsMediaSource with ads ID at the provided ad playback state.

Unit
addAdResumptionState(adsId: Any!, adPlaybackState: AdPlaybackState!)

Adds the given AdPlaybackState to resume playback of the AdsMediaSource with ads ID at the provided ad playback state.

Unit

Adds a Listener.

Unit

Clears all ad resumptions states.

ImmutableList<HlsInterstitialsAdsLoader.AdsResumptionState!>!

Returns the resumption states of the currently active ads media sources.

Boolean
handleContentTimelineChanged(
    adsMediaSource: AdsMediaSource!,
    timeline: Timeline!
)

Notifies the ads loader when the content source has changed its timeline.

Unit
handlePrepareComplete(
    adsMediaSource: AdsMediaSource!,
    adGroupIndex: Int,
    adIndexInAdGroup: Int
)

Notifies the ads loader that preparation of an ad media period is complete.

Unit
handlePrepareError(
    adsMediaSource: AdsMediaSource!,
    adGroupIndex: Int,
    adIndexInAdGroup: Int,
    exception: IOException!
)

Notifies the ads loader that the player was not able to prepare media for a given ad.

Unit

Releases the loader.

Boolean

Removes the AdsResumptionState for the given ads ID, or null if there is no active ad playback state for the given ads ID.

Unit

Removes a Listener.

Unit
setPlayer(player: Player?)

Sets the player that will play the loaded ads.

Unit

Sets the supported content types for ad media.

Unit
start(
    adsMediaSource: AdsMediaSource!,
    adTagDataSpec: DataSpec!,
    adsId: Any!,
    adViewProvider: AdViewProvider!,
    eventListener: AdsLoader.EventListener!
)

Starts using the ads loader for playback.

Unit
stop(
    adsMediaSource: AdsMediaSource!,
    eventListener: AdsLoader.EventListener!
)

Stops using the ads loader for playback and deregisters the event listener.

Public constructors

HlsInterstitialsAdsLoader

HlsInterstitialsAdsLoader(context: Context!)

Creates an instance with a DefaultDataSource.Factory to read HLS X-ASSET-LIST JSON objects.

Parameters
context: Context!

The context.

HlsInterstitialsAdsLoader

HlsInterstitialsAdsLoader(dataSourceFactory: DataSource.Factory!)

Creates an instance.

Parameters
dataSourceFactory: DataSource.Factory!

The data source factory to read HLS X-ASSET-LIST JSON objects.

Public functions

addAdResumptionState

fun addAdResumptionState(
    adsResumptionState: HlsInterstitialsAdsLoader.AdsResumptionState!
): Unit

Adds the given AdsResumptionState to resume playback of the AdsMediaSource with ads ID at the provided ad playback state.

If added while the given ads ID is active, the resumption state is ignored. The resumption state for a given ads ID must be added before start or after stop is called for that ads ID.

Parameters
adsResumptionState: HlsInterstitialsAdsLoader.AdsResumptionState!

The state to resume with.

Throws
java.lang.IllegalArgumentException

Thrown if the ad playback state ends with a live placeholder.

addAdResumptionState

fun addAdResumptionState(adsId: Any!, adPlaybackState: AdPlaybackState!): Unit

Adds the given AdPlaybackState to resume playback of the AdsMediaSource with ads ID at the provided ad playback state.

If added while the given ads ID is active, the resumption state is ignored. The resumption state for a given ads ID must be added before start or after stop is called for that ads ID.

Parameters
adsId: Any!

The ads ID identifying the AdsMediaSource to resume with the given state.

adPlaybackState: AdPlaybackState!

The state to resume with.

Throws
java.lang.IllegalArgumentException

Thrown if the ad playback state ends with a live placeholder.

addListener

fun addListener(listener: HlsInterstitialsAdsLoader.Listener!): Unit

Adds a Listener.

clearAllAdResumptionStates

fun clearAllAdResumptionStates(): Unit

Clears all ad resumptions states.

getAdsResumptionStates

fun getAdsResumptionStates(): ImmutableList<HlsInterstitialsAdsLoader.AdsResumptionState!>!

Returns the resumption states of the currently active ads media sources.

Call this method to get the resumption states before releasing the player and resume at the same state later.

Live streams and streams with an ads ID that are not of type string are ignored and are not included in the returned list of ad resumption state.

See onStop and addAdResumptionState also.

handleContentTimelineChanged

fun handleContentTimelineChanged(
    adsMediaSource: AdsMediaSource!,
    timeline: Timeline!
): Boolean

Notifies the ads loader when the content source has changed its timeline. Called on the main thread by AdsMediaSource.

The default implementation returns false which makes the content timeline immediately being reported to the player.

When overriding this method for the purpose of reading ad data from the timeline to populate the AdPlaybackState with, false needs to be passed to the constructor of AdsMediaSource to indicate that the content source needs to be prepared upfront. This way an ads loader can defer calling onAdPlaybackState until the ad data from the timeline is available and populate the initial ad playback state with that data before publishing.

For live streams, this method is called additional times when the content source reports an advancing live window with new available media and/or new ad data in the manifest. If in such a case, the ads loader as a result calls onAdPlaybackState, true must be returned. This prevents the timeline being reported with stale ad data. Conversely, when the ad playback state is not passed into onAdPlaybackState, false must be returned to not drop a timeline update that needs to be published to the player.

Generally, if the timeline is not required to populate the ad playback state, start should be used to initiate loading ad data and publish the first ad playback state as early as possible. This method can still be overridden for informational or other purpose. In this case, false is returned here and the AdsMediaSource is used with lazy preparation enabled.

Parameters
adsMediaSource: AdsMediaSource!

The ads media source for which the content timeline changed.

timeline: Timeline!

The timeline of the content source.

Returns
Boolean

true If onAdPlaybackState is or will be called, false otherwise.

handlePrepareComplete

fun handlePrepareComplete(
    adsMediaSource: AdsMediaSource!,
    adGroupIndex: Int,
    adIndexInAdGroup: Int
): Unit

Notifies the ads loader that preparation of an ad media period is complete. Called on the main thread by AdsMediaSource.

Parameters
adsMediaSource: AdsMediaSource!

The ads media source for which preparation of ad media completed.

adGroupIndex: Int

The index of the ad group.

adIndexInAdGroup: Int

The index of the ad in the ad group.

handlePrepareError

fun handlePrepareError(
    adsMediaSource: AdsMediaSource!,
    adGroupIndex: Int,
    adIndexInAdGroup: Int,
    exception: IOException!
): Unit

Notifies the ads loader that the player was not able to prepare media for a given ad. Implementations should update the ad playback state as the specified ad has failed to load. Called on the main thread by AdsMediaSource.

Parameters
adsMediaSource: AdsMediaSource!

The ads media source for which preparation of ad media failed.

adGroupIndex: Int

The index of the ad group.

adIndexInAdGroup: Int

The index of the ad in the ad group.

exception: IOException!

The preparation error.

release

fun release(): Unit

Releases the loader. Must be called by the application on the main thread when the instance is no longer needed.

removeAdResumptionState

fun removeAdResumptionState(adsId: Any!): Boolean

Removes the AdsResumptionState for the given ads ID, or null if there is no active ad playback state for the given ads ID.

Parameters
adsId: Any!

The ads ID for which to remove the resumption state.

Returns
Boolean

The removed resumption state or null.

removeListener

fun removeListener(listener: HlsInterstitialsAdsLoader.Listener!): Unit

Removes a Listener.

setPlayer

fun setPlayer(player: Player?): Unit

Sets the player that will play the loaded ads.

This method must be called before the player is prepared with media using this ads loader.

This method must also be called on the main thread and only players which are accessed on the main thread are supported ( player.getApplicationLooper() == Looper.getMainLooper()).

Throws
java.lang.IllegalStateException

If an app is attempting to set a new player instance after release was called or while ads media sources started by the old player are still active, an IllegalStateException is thrown. Release the old player first, or remove all ads media sources from it before setting another player instance.

setSupportedContentTypes

fun setSupportedContentTypes(@C.ContentType contentTypes: IntArray!): Unit

Sets the supported content types for ad media. Must be called before the first call to start. Subsequent calls may be ignored. Called on the main thread by AdsMediaSource.

Parameters
@C.ContentType contentTypes: IntArray!

The supported content types for ad media. Each element must be one of CONTENT_TYPE_DASH, CONTENT_TYPE_HLS, CONTENT_TYPE_SS and CONTENT_TYPE_OTHER.

start

fun start(
    adsMediaSource: AdsMediaSource!,
    adTagDataSpec: DataSpec!,
    adsId: Any!,
    adViewProvider: AdViewProvider!,
    eventListener: AdsLoader.EventListener!
): Unit

Starts using the ads loader for playback. Called on the main thread by AdsMediaSource.

Requests the ads loader to start loading ad data from the provided adTagDataSpec. Publishing an initial AdPlaybackState to provided eventListener is required to start playback. In the case of a pre roll, this ensures that the player doesn't briefly start playing content before ad data is available.

Parameters
adsMediaSource: AdsMediaSource!

The ads media source requesting to start loading ads.

adTagDataSpec: DataSpec!

A data spec for the ad tag to load.

adsId: Any!

An opaque identifier for the ad playback state across start/stop calls.

adViewProvider: AdViewProvider!

Provider of views for the ad UI.

eventListener: AdsLoader.EventListener!

Listener for ads loader events.

stop

fun stop(
    adsMediaSource: AdsMediaSource!,
    eventListener: AdsLoader.EventListener!
): Unit

Stops using the ads loader for playback and deregisters the event listener. Called on the main thread by AdsMediaSource.

Parameters
adsMediaSource: AdsMediaSource!

The ads media source requesting to stop loading/playing ads.

eventListener: AdsLoader.EventListener!

The ads media source's listener for ads loader events.