AdsMediaSource
@UnstableApi
class AdsMediaSource : CompositeMediaSource
| kotlin.Any | |||
| ↳ | androidx.media3.exoplayer.source.BaseMediaSource | ||
| ↳ | androidx.media3.exoplayer.source.CompositeMediaSource | ||
| ↳ | androidx.media3.exoplayer.source.ads.AdsMediaSource |
A MediaSource that inserts ads linearly into a provided content media source.
The wrapped content media source must contain a single Timeline.Period.
Summary
Nested types |
|---|
|
Wrapper for exceptions that occur while loading ads, which are notified via |
@DocumentedTypes of ad load exceptions. |
Public constructors |
|---|
AdsMediaSource(Constructs a new source that inserts ads linearly with the content specified by |
AdsMediaSource(Constructs a new source that inserts ads linearly with the content specified by |
Public functions |
|
|---|---|
Boolean |
canUpdateMediaItem(mediaItem: MediaItem!)Returns whether the |
MediaPeriod! |
createPeriod(Returns a new |
MediaItem! |
Returns the |
Unit |
releasePeriod(mediaPeriod: MediaPeriod!)Releases the period. |
Unit |
updateMediaItem(mediaItem: MediaItem!)Updates the |
Protected functions |
|
|---|---|
MediaSource.MediaPeriodId! |
getMediaPeriodIdForChildMediaPeriodId(Returns the |
Unit |
onChildSourceInfoRefreshed(Called when the source info of a child source has been refreshed. |
Unit |
prepareSourceInternal(mediaTransferListener: TransferListener?)Starts source preparation and enables the source, see |
Unit |
Releases the source, see |
Inherited functions |
||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
Public constructors
AdsMediaSource
AdsMediaSource(
contentMediaSource: MediaSource!,
adTagDataSpec: DataSpec!,
adsId: Any!,
adMediaSourceFactory: MediaSource.Factory!,
adsLoader: AdsLoader!,
adViewProvider: AdViewProvider!
)
Constructs a new source that inserts ads linearly with the content specified by
contentMediaSource.
This is equivalent to passing true as param useLazyContentSourcePreparation when calling AdsMediaSource.
| Parameters | |
|---|---|
contentMediaSource: MediaSource! |
The |
adTagDataSpec: DataSpec! |
The data specification of the ad tag to load. |
adsId: Any! |
An opaque identifier for ad playback state associated with this instance. Ad loading and playback state is shared among all playlist items that have the same ads id (by |
adMediaSourceFactory: MediaSource.Factory! |
Factory for media sources used to load ad media. |
adsLoader: AdsLoader! |
The loader for ads. |
adViewProvider: AdViewProvider! |
Provider of views for the ad UI. |
AdsMediaSource
AdsMediaSource(
contentMediaSource: MediaSource!,
adTagDataSpec: DataSpec!,
adsId: Any!,
adMediaSourceFactory: MediaSource.Factory!,
adsLoader: AdsLoader!,
adViewProvider: AdViewProvider!,
useLazyContentSourcePreparation: Boolean
)
Constructs a new source that inserts ads linearly with the content specified by
contentMediaSource.
| Parameters | |
|---|---|
contentMediaSource: MediaSource! |
The |
adTagDataSpec: DataSpec! |
The data specification of the ad tag to load. |
adsId: Any! |
An opaque identifier for ad playback state associated with this instance. Ad loading and playback state is shared among all playlist items that have the same ads id (by |
adMediaSourceFactory: MediaSource.Factory! |
Factory for media sources used to load ad media. |
adsLoader: AdsLoader! |
The loader for ads. |
adViewProvider: AdViewProvider! |
Provider of views for the ad UI. |
useLazyContentSourcePreparation: Boolean |
True if the content source should be prepared lazily and wait for an |
Public functions
canUpdateMediaItem
fun canUpdateMediaItem(mediaItem: MediaItem!): Boolean
Returns whether the MediaItem for this source can be updated with the provided item.
Should not be called directly from application code.
This method must be called on the application thread.
| Returns | |
|---|---|
Boolean |
Whether the source can be updated using this item. |
createPeriod
fun createPeriod(
id: MediaSource.MediaPeriodId!,
allocator: Allocator!,
startPositionUs: Long
): MediaPeriod!
Returns a new MediaPeriod identified by periodId.
Should not be called directly from application code.
This method must be called on the playback thread and only if the source is enabled.
| Parameters | |
|---|---|
id: MediaSource.MediaPeriodId! |
The identifier of the period. |
allocator: Allocator! |
An |
startPositionUs: Long |
The expected start position, in microseconds. |
| Returns | |
|---|---|
MediaPeriod! |
A new |
getMediaItem
fun getMediaItem(): MediaItem!
Returns the MediaItem whose media is provided by the source.
Should not be called directly from application code.
This method must be called on the application thread.
releasePeriod
fun releasePeriod(mediaPeriod: MediaPeriod!): Unit
Releases the period.
Should not be called directly from application code.
This method must be called on the playback thread.
| Parameters | |
|---|---|
mediaPeriod: MediaPeriod! |
The period to release. |
updateMediaItem
fun updateMediaItem(mediaItem: MediaItem!): Unit
Updates the MediaItem for this source.
Should not be called directly from application code.
This method must be called on the playback thread and only if canUpdateMediaItem returns true for the new MediaItem.
Protected functions
getMediaPeriodIdForChildMediaPeriodId
protected fun getMediaPeriodIdForChildMediaPeriodId(
childSourceId: MediaSource.MediaPeriodId!,
mediaPeriodId: MediaSource.MediaPeriodId!
): MediaSource.MediaPeriodId!
Returns the MediaPeriodId in the composite source corresponding to the specified MediaPeriodId in a child source. The default implementation does not change the media period id.
| Parameters | |
|---|---|
childSourceId: MediaSource.MediaPeriodId! |
The unique id used to prepare the child source. |
mediaPeriodId: MediaSource.MediaPeriodId! |
A |
| Returns | |
|---|---|
MediaSource.MediaPeriodId! |
The corresponding |
onChildSourceInfoRefreshed
protected fun onChildSourceInfoRefreshed(
childSourceId: MediaSource.MediaPeriodId!,
mediaSource: MediaSource!,
newTimeline: Timeline!
): Unit
Called when the source info of a child source has been refreshed.
| Parameters | |
|---|---|
childSourceId: MediaSource.MediaPeriodId! |
The unique id used to prepare the child source. |
mediaSource: MediaSource! |
The child source whose source info has been refreshed. |
newTimeline: Timeline! |
The timeline of the child source. |
prepareSourceInternal
protected fun prepareSourceInternal(mediaTransferListener: TransferListener?): Unit
Starts source preparation and enables the source, see prepareSource. This method is called at most once until the next call to releaseSourceInternal.
This method is called on the playback thread.
| Parameters | |
|---|---|
mediaTransferListener: TransferListener? |
The transfer listener which should be informed of any media data transfers. May be null if no listener is available. Note that this listener should usually be only informed of transfers related to the media loads and not of auxiliary loads for manifests and other data. |
releaseSourceInternal
protected fun releaseSourceInternal(): Unit
Releases the source, see releaseSource. This method is called exactly once after each call to prepareSourceInternal.
This method is called on the playback thread.