public final class ImaAdsMediaSource extends Object implements MediaSource
MediaSource that inserts ads linearly with a provided content media source using the
Interactive Media Ads SDK for ad loading and tracking.| Modifier and Type | Class and Description |
|---|---|
static interface |
ImaAdsMediaSource.AdsListener
Listener for events relating to ad loading.
|
MediaSource.Listener, MediaSource.MediaPeriodId| Constructor and Description |
|---|
ImaAdsMediaSource(MediaSource contentMediaSource,
DataSource.Factory dataSourceFactory,
ImaAdsLoader imaAdsLoader,
ViewGroup adUiViewGroup)
Constructs a new source that inserts ads linearly with the content specified by
contentMediaSource. |
ImaAdsMediaSource(MediaSource contentMediaSource,
DataSource.Factory dataSourceFactory,
ImaAdsLoader imaAdsLoader,
ViewGroup adUiViewGroup,
Handler eventHandler,
ImaAdsMediaSource.AdsListener eventListener)
Constructs a new source that inserts ads linearly with the content specified by
contentMediaSource. |
| Modifier and Type | Method and Description |
|---|---|
MediaPeriod |
createPeriod(MediaSource.MediaPeriodId id,
Allocator allocator)
Returns a new
MediaPeriod identified by periodId. |
void |
maybeThrowSourceInfoRefreshError()
Throws any pending error encountered while loading or refreshing source information.
|
void |
prepareSource(ExoPlayer player,
boolean isTopLevelSource,
MediaSource.Listener listener)
Starts preparation of the source.
|
void |
releasePeriod(MediaPeriod mediaPeriod)
Releases the period.
|
void |
releaseSource()
Releases the source.
|
public ImaAdsMediaSource(MediaSource contentMediaSource, DataSource.Factory dataSourceFactory, ImaAdsLoader imaAdsLoader, ViewGroup adUiViewGroup)
contentMediaSource.contentMediaSource - The MediaSource providing the content to play.dataSourceFactory - Factory for data sources used to load ad media.imaAdsLoader - The loader for ads.adUiViewGroup - A ViewGroup on top of the player that will show any ad UI.public ImaAdsMediaSource(MediaSource contentMediaSource, DataSource.Factory dataSourceFactory, ImaAdsLoader imaAdsLoader, ViewGroup adUiViewGroup, @Nullable Handler eventHandler, @Nullable ImaAdsMediaSource.AdsListener eventListener)
contentMediaSource.contentMediaSource - The MediaSource providing the content to play.dataSourceFactory - Factory for data sources used to load ad media.imaAdsLoader - The loader for ads.adUiViewGroup - A ViewGroup on top of the player that will show any ad UI.eventHandler - A handler for events. May be null if delivery of events is not required.eventListener - A listener of events. May be null if delivery of events is not required.public void prepareSource(ExoPlayer player, boolean isTopLevelSource, MediaSource.Listener listener)
MediaSourceprepareSource in interface MediaSourceplayer - The player for which this source is being prepared.isTopLevelSource - Whether this source has been passed directly to
ExoPlayer.prepare(MediaSource) or
ExoPlayer.prepare(MediaSource, boolean, boolean). If false, this source is
being prepared by another source (e.g. ConcatenatingMediaSource) for composition.listener - The listener for source events.public void maybeThrowSourceInfoRefreshError()
throws IOException
MediaSourcemaybeThrowSourceInfoRefreshError in interface MediaSourceIOExceptionpublic MediaPeriod createPeriod(MediaSource.MediaPeriodId id, Allocator allocator)
MediaSourceMediaPeriod identified by periodId. This method may be called
multiple times with the same period identifier without an intervening call to
MediaSource.releasePeriod(MediaPeriod).createPeriod in interface MediaSourceid - The identifier of the period.allocator - An Allocator from which to obtain media buffer allocations.MediaPeriod.public void releasePeriod(MediaPeriod mediaPeriod)
MediaSourcereleasePeriod in interface MediaSourcemediaPeriod - The period to release.public void releaseSource()
MediaSourceThis method should be called when the source is no longer required. It may be called in any state.
releaseSource in interface MediaSource