AdsMediaSource
@UnstableApi
public final class AdsMediaSource extends CompositeMediaSource
| java.lang.Object | |||
| ↳ | 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 |
|---|
public final class AdsMediaSource.AdLoadException extends IOExceptionWrapper 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 methods |
|
|---|---|
boolean |
canUpdateMediaItem(MediaItem mediaItem)Returns whether the |
MediaPeriod |
createPeriod(Returns a new |
Object |
getAdsId()Returns the ads ID this source is serving. |
MediaItem |
Returns the |
void |
releasePeriod(MediaPeriod mediaPeriod)Releases the period. |
void |
updateMediaItem(MediaItem mediaItem)Updates the |
Protected methods |
|
|---|---|
MediaSource.MediaPeriodId |
getMediaPeriodIdForChildMediaPeriodId(Returns the |
void |
onChildSourceInfoRefreshed(Called when the source info of a child source has been refreshed. |
void |
prepareSourceInternal(@Nullable TransferListener mediaTransferListener)Starts source preparation and enables the source, see |
void |
Releases the source, see |
Inherited methods |
||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
Public constructors
AdsMediaSource
public AdsMediaSource(
MediaSource contentMediaSource,
DataSpec adTagDataSpec,
Object adsId,
MediaSource.Factory adMediaSourceFactory,
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 | |
|---|---|
MediaSource contentMediaSource |
The |
DataSpec adTagDataSpec |
The data specification of the ad tag to load. |
Object adsId |
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 |
MediaSource.Factory adMediaSourceFactory |
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
public AdsMediaSource(
MediaSource contentMediaSource,
DataSpec adTagDataSpec,
Object adsId,
MediaSource.Factory adMediaSourceFactory,
AdsLoader adsLoader,
AdViewProvider adViewProvider,
boolean useLazyContentSourcePreparation
)
Constructs a new source that inserts ads linearly with the content specified by
contentMediaSource.
| Parameters | |
|---|---|
MediaSource contentMediaSource |
The |
DataSpec adTagDataSpec |
The data specification of the ad tag to load. |
Object adsId |
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 |
MediaSource.Factory adMediaSourceFactory |
Factory for media sources used to load ad media. |
AdsLoader adsLoader |
The loader for ads. |
AdViewProvider adViewProvider |
Provider of views for the ad UI. |
boolean useLazyContentSourcePreparation |
True if the content source should be prepared lazily and wait for an |
Public methods
canUpdateMediaItem
public boolean canUpdateMediaItem(MediaItem mediaItem)
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
public MediaPeriod createPeriod(
MediaSource.MediaPeriodId id,
Allocator allocator,
long startPositionUs
)
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 | |
|---|---|
MediaSource.MediaPeriodId id |
The identifier of the period. |
Allocator allocator |
An |
long startPositionUs |
The expected start position, in microseconds. |
| Returns | |
|---|---|
MediaPeriod |
A new |
getMediaItem
public MediaItem getMediaItem()
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
public void releasePeriod(MediaPeriod mediaPeriod)
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
public void updateMediaItem(MediaItem mediaItem)
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 methods
getMediaPeriodIdForChildMediaPeriodId
protected MediaSource.MediaPeriodId getMediaPeriodIdForChildMediaPeriodId(
MediaSource.MediaPeriodId childSourceId,
MediaSource.MediaPeriodId 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 | |
|---|---|
MediaSource.MediaPeriodId childSourceId |
The unique id used to prepare the child source. |
MediaSource.MediaPeriodId mediaPeriodId |
A |
| Returns | |
|---|---|
MediaSource.MediaPeriodId |
The corresponding |
onChildSourceInfoRefreshed
protected void onChildSourceInfoRefreshed(
MediaSource.MediaPeriodId childSourceId,
MediaSource mediaSource,
Timeline newTimeline
)
Called when the source info of a child source has been refreshed.
| Parameters | |
|---|---|
MediaSource.MediaPeriodId childSourceId |
The unique id used to prepare the child source. |
MediaSource mediaSource |
The child source whose source info has been refreshed. |
Timeline newTimeline |
The timeline of the child source. |
prepareSourceInternal
protected void prepareSourceInternal(@Nullable TransferListener mediaTransferListener)
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 | |
|---|---|
@Nullable TransferListener mediaTransferListener |
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 void releaseSourceInternal()
Releases the source, see releaseSource. This method is called exactly once after each call to prepareSourceInternal.
This method is called on the playback thread.