docs/doc/reference/com/google/android/exoplayer2/source/ads/ServerSideAdInsertionMediaSource.html
Package com.google.android.exoplayer2.source.ads
All Implemented Interfaces:DrmSessionEventListener, MediaSource, MediaSource.MediaSourceCaller, MediaSourceEventListener
[@Deprecated](https://developer.android.com/reference/java/lang/Deprecated.html "class or interface in java.lang")public final classServerSideAdInsertionMediaSourceextends[BaseMediaSource](../BaseMediaSource.html "class in com.google.android.exoplayer2.source")implements[MediaSource.MediaSourceCaller](../MediaSource.MediaSourceCaller.html "interface in com.google.android.exoplayer2.source"),[MediaSourceEventListener](../MediaSourceEventListener.html "interface in com.google.android.exoplayer2.source"),[DrmSessionEventListener](../../drm/DrmSessionEventListener.html "interface in com.google.android.exoplayer2.drm")
Deprecated. com.google.android.exoplayer2 is deprecated. Please migrate to androidx.media3 (which contains the same ExoPlayer code). See the migration guide for more details, including a script to help with the migration.
A MediaSource for server-side inserted ad breaks.
The media source publishes a Timeline for the wrapped MediaSource with the server-side inserted ad breaks and ensures that playback continues seamlessly with the wrapped media across all transitions.
The ad breaks need to be specified using setAdPlaybackStates(com.google.common.collect.ImmutableMap<java.lang.Object, com.google.android.exoplayer2.source.ads.AdPlaybackState>, com.google.android.exoplayer2.Timeline) and can be updated during playback.
Nested Classes | Modifier and Type | Class | Description |
| --- | --- | --- |
| static interface | ServerSideAdInsertionMediaSource.AdPlaybackStateUpdater |
Deprecated.
Receives ad playback state update requests when the Timeline of the content media source has changed.
|
-
DrmSessionEventListener.EventDispatcher
-
MediaSource.Factory, MediaSource.MediaPeriodId, MediaSource.MediaSourceCaller
-
MediaSourceEventListener.EventDispatcher
Constructors | Constructor | Description |
| --- | --- |
| ServerSideAdInsertionMediaSource(MediaSource mediaSource, ServerSideAdInsertionMediaSource.AdPlaybackStateUpdater adPlaybackStateUpdater) |
Deprecated.
Creates the media source. |
All Methods Instance Methods Concrete Methods Deprecated Methods | Modifier and Type | Method | Description |
| --- | --- | --- |
| MediaPeriod | createPeriod(MediaSource.MediaPeriodId id, Allocator allocator, long startPositionUs) |
Deprecated.
Returns a new MediaPeriod identified by periodId.
|
| protected void | disableInternal() |
Deprecated.
Disables the source, see BaseMediaSource.disable(MediaSourceCaller).
|
| protected void | enableInternal() |
Deprecated.
Enables the source, see BaseMediaSource.enable(MediaSourceCaller).
|
| MediaItem | getMediaItem() |
Deprecated.
Returns the MediaItem whose media is provided by the source.
|
| void | maybeThrowSourceInfoRefreshError() |
Deprecated.
Throws any pending error encountered while loading or refreshing source information.
|
| void | onDownstreamFormatChanged(int windowIndex, MediaSource.MediaPeriodId mediaPeriodId, MediaLoadData mediaLoadData) |
Deprecated.
Called when a downstream format change occurs (i.e.
|
| void | onDrmKeysLoaded(int windowIndex, MediaSource.MediaPeriodId mediaPeriodId) |
Deprecated.
Called each time keys are loaded.
|
| void | onDrmKeysRemoved(int windowIndex, MediaSource.MediaPeriodId mediaPeriodId) |
Deprecated.
Called each time offline keys are removed.
|
| void | onDrmKeysRestored(int windowIndex, MediaSource.MediaPeriodId mediaPeriodId) |
Deprecated.
Called each time offline keys are restored.
|
| void | onDrmSessionAcquired(int windowIndex, MediaSource.MediaPeriodId mediaPeriodId, @com.google.android.exoplayer2.drm.DrmSession.State int state) |
Deprecated.
Called each time a drm session is acquired.
|
| void | onDrmSessionManagerError(int windowIndex, MediaSource.MediaPeriodId mediaPeriodId, Exception error) |
Deprecated.
Called when a drm error occurs.
|
| void | onDrmSessionReleased(int windowIndex, MediaSource.MediaPeriodId mediaPeriodId) |
Deprecated.
Called each time a drm session is released.
|
| void | onLoadCanceled(int windowIndex, MediaSource.MediaPeriodId mediaPeriodId, LoadEventInfo loadEventInfo, MediaLoadData mediaLoadData) |
Deprecated.
Called when a load is canceled.
|
| void | onLoadCompleted(int windowIndex, MediaSource.MediaPeriodId mediaPeriodId, LoadEventInfo loadEventInfo, MediaLoadData mediaLoadData) |
Deprecated.
Called when a load ends.
|
| void | onLoadError(int windowIndex, MediaSource.MediaPeriodId mediaPeriodId, LoadEventInfo loadEventInfo, MediaLoadData mediaLoadData, IOException error, boolean wasCanceled) |
Deprecated.
Called when a load error occurs.
|
| void | onLoadStarted(int windowIndex, MediaSource.MediaPeriodId mediaPeriodId, LoadEventInfo loadEventInfo, MediaLoadData mediaLoadData) |
Deprecated.
Called when a load begins.
|
| void | onSourceInfoRefreshed(MediaSource source, Timeline timeline) |
Deprecated.
Called when the Timeline has been refreshed.
|
| void | onUpstreamDiscarded(int windowIndex, MediaSource.MediaPeriodId mediaPeriodId, MediaLoadData mediaLoadData) |
Deprecated.
Called when data is removed from the back of a media buffer, typically so that it can be re-buffered in a different format.
|
| protected void | prepareSourceInternal(TransferListener mediaTransferListener) |
Deprecated.
Starts source preparation and enables the source, see BaseMediaSource.prepareSource(MediaSourceCaller, TransferListener, PlayerId).
|
| void | releasePeriod(MediaPeriod mediaPeriod) |
Deprecated.
Releases the period.
|
| protected void | releaseSourceInternal() |
Deprecated.
Releases the source, see BaseMediaSource.releaseSource(MediaSourceCaller).
|
| void | setAdPlaybackStates(ImmutableMap<Object,AdPlaybackState> adPlaybackStates, Timeline contentTimeline) |
Deprecated.
Sets the map of ad playback states published by this source.
|
-
addDrmEventListener, addEventListener, createDrmEventDispatcher, createDrmEventDispatcher, createEventDispatcher, createEventDispatcher, createEventDispatcher, createEventDispatcher, disable, enable, getPlayerId, isEnabled, prepareSource, prepareSource, refreshSourceInfo, releaseSource, removeDrmEventListener, removeEventListener
-
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
onDrmSessionAcquired
-
getInitialTimeline, isSingleWindow
-
public ServerSideAdInsertionMediaSource([MediaSource](../MediaSource.html "interface in com.google.android.exoplayer2.source")mediaSource,
@Nullable[ServerSideAdInsertionMediaSource.AdPlaybackStateUpdater](ServerSideAdInsertionMediaSource.AdPlaybackStateUpdater.html "interface in com.google.android.exoplayer2.source.ads")adPlaybackStateUpdater)
Deprecated.
Creates the media source.
Parameters:mediaSource - The MediaSource to wrap.adPlaybackStateUpdater - The optional ServerSideAdInsertionMediaSource.AdPlaybackStateUpdater to be called before a source refresh is published.
-
public void setAdPlaybackStates([ImmutableMap](https://guava.dev/releases/31.1-android/api/docs/com/google/common/collect/ImmutableMap.html?is-external=true "class or interface in com.google.common.collect")<[Object](https://developer.android.com/reference/java/lang/Object.html "class or interface in java.lang"),[AdPlaybackState](AdPlaybackState.html "class in com.google.android.exoplayer2.source.ads")> adPlaybackStates,[Timeline](../../Timeline.html "class in com.google.android.exoplayer2")contentTimeline)
Deprecated.
Sets the map of ad playback states published by this source. The key is the period UID of a period in the contentTimeline.
Each period has an AdPlaybackState that tells where in the period the ad groups start and end. Must only contain server-side inserted ad groups. The number of ad groups and the number of ads within an ad group may only increase. The durations of ads may change and the positions of future ad groups may change. Post-roll ad groups with C.TIME_END_OF_SOURCE must be empty and can be used as a placeholder for a future ad group.
May be called from any thread.
Parameters:adPlaybackStates - The map of AdPlaybackState keyed by their period UID.contentTimeline - The content timeline containing the periods with the UIDs used as keys in the map of playback states.
-
public[MediaItem](../../MediaItem.html "class in com.google.android.exoplayer2")getMediaItem()
Deprecated.
Description copied from interface: MediaSource
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.
Specified by:getMediaItem in interface MediaSource
-
protected void prepareSourceInternal(@Nullable[TransferListener](../../upstream/TransferListener.html "interface in com.google.android.exoplayer2.upstream")mediaTransferListener)
Deprecated.
Description copied from class: BaseMediaSource
Starts source preparation and enables the source, see BaseMediaSource.prepareSource(MediaSourceCaller, TransferListener, PlayerId). This method is called at most once until the next call to BaseMediaSource.releaseSourceInternal().
Specified by:prepareSourceInternal in class BaseMediaSourceParameters: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.
-
public void maybeThrowSourceInfoRefreshError()
throws[IOException](https://developer.android.com/reference/java/io/IOException.html "class or interface in java.io")
Deprecated.
Description copied from interface: MediaSource
Throws any pending error encountered while loading or refreshing source information.
Should not be called directly from application code.
This method must be called on the playback thread and only after MediaSource.prepareSource(MediaSourceCaller, TransferListener, PlayerId).
Specified by:maybeThrowSourceInfoRefreshError in interface MediaSourceThrows:IOException
-
protected void enableInternal()
Deprecated.
Description copied from class: BaseMediaSource
Enables the source, see BaseMediaSource.enable(MediaSourceCaller).
Overrides:enableInternal in class BaseMediaSource
-
protected void disableInternal()
Deprecated.
Description copied from class: BaseMediaSource
Disables the source, see BaseMediaSource.disable(MediaSourceCaller).
Overrides:disableInternal in class BaseMediaSource
-
public void onSourceInfoRefreshed([MediaSource](../MediaSource.html "interface in com.google.android.exoplayer2.source")source,[Timeline](../../Timeline.html "class in com.google.android.exoplayer2")timeline)
Deprecated.
Description copied from interface: MediaSource.MediaSourceCaller
Called when the Timeline has been refreshed.
Called on the playback thread.
Specified by:onSourceInfoRefreshed in interface MediaSource.MediaSourceCallerParameters:source - The MediaSource whose info has been refreshed.timeline - The source's timeline.
-
protected void releaseSourceInternal()
Deprecated.
Description copied from class: BaseMediaSource
Releases the source, see BaseMediaSource.releaseSource(MediaSourceCaller). This method is called exactly once after each call to BaseMediaSource.prepareSourceInternal(TransferListener).
Specified by:releaseSourceInternal in class BaseMediaSource
-
public[MediaPeriod](../MediaPeriod.html "interface in com.google.android.exoplayer2.source")createPeriod([MediaSource.MediaPeriodId](../MediaSource.MediaPeriodId.html "class in com.google.android.exoplayer2.source")id,[Allocator](../../upstream/Allocator.html "interface in com.google.android.exoplayer2.upstream")allocator,
long startPositionUs)
Deprecated.
Description copied from interface: MediaSource
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.
Specified by:createPeriod in interface MediaSourceParameters:id - The identifier of the period.allocator - An Allocator from which to obtain media buffer allocations.startPositionUs - The expected start position, in microseconds.Returns:A new MediaPeriod.
-
public void releasePeriod([MediaPeriod](../MediaPeriod.html "interface in com.google.android.exoplayer2.source")mediaPeriod)
Deprecated.
Description copied from interface: MediaSource
Releases the period.
Should not be called directly from application code.
This method must be called on the playback thread.
Specified by:releasePeriod in interface MediaSourceParameters:mediaPeriod - The period to release.
-
public void onDrmSessionAcquired(int windowIndex,
@Nullable[MediaSource.MediaPeriodId](../MediaSource.MediaPeriodId.html "class in com.google.android.exoplayer2.source")mediaPeriodId,[@State](../../drm/DrmSession.State.html "annotation in com.google.android.exoplayer2.drm")@com.google.android.exoplayer2.drm.DrmSession.State int state)
Deprecated.
Description copied from interface: DrmSessionEventListener
Called each time a drm session is acquired.
Specified by:onDrmSessionAcquired in interface DrmSessionEventListenerParameters:windowIndex - The window index in the timeline this media period belongs to.mediaPeriodId - The MediaSource.MediaPeriodId associated with the drm session.state - The DrmSession.State of the session when the acquisition completed.
-
public void onDrmKeysLoaded(int windowIndex,
@Nullable[MediaSource.MediaPeriodId](../MediaSource.MediaPeriodId.html "class in com.google.android.exoplayer2.source")mediaPeriodId)
Deprecated.
Description copied from interface: DrmSessionEventListener
Called each time keys are loaded.
Specified by:onDrmKeysLoaded in interface DrmSessionEventListenerParameters:windowIndex - The window index in the timeline this media period belongs to.mediaPeriodId - The MediaSource.MediaPeriodId associated with the drm session.
-
public void onDrmSessionManagerError(int windowIndex,
@Nullable[MediaSource.MediaPeriodId](../MediaSource.MediaPeriodId.html "class in com.google.android.exoplayer2.source")mediaPeriodId,[Exception](https://developer.android.com/reference/java/lang/Exception.html "class or interface in java.lang")error)
Deprecated.
Description copied from interface: DrmSessionEventListener
Called when a drm error occurs.
This method being called does not indicate that playback has failed, or that it will fail. The player may be able to recover from the error and continue. Hence applications should not implement this method to display a user visible error or initiate an application level retry (Player.Listener.onPlayerError(com.google.android.exoplayer2.PlaybackException) is the appropriate place to implement such behavior). This method is called to provide the application with an opportunity to log the error if it wishes to do so.
Specified by:onDrmSessionManagerError in interface DrmSessionEventListenerParameters:windowIndex - The window index in the timeline this media period belongs to.mediaPeriodId - The MediaSource.MediaPeriodId associated with the drm session.error - The corresponding exception.
-
public void onDrmKeysRestored(int windowIndex,
@Nullable[MediaSource.MediaPeriodId](../MediaSource.MediaPeriodId.html "class in com.google.android.exoplayer2.source")mediaPeriodId)
Deprecated.
Description copied from interface: DrmSessionEventListener
Called each time offline keys are restored.
Specified by:onDrmKeysRestored in interface DrmSessionEventListenerParameters:windowIndex - The window index in the timeline this media period belongs to.mediaPeriodId - The MediaSource.MediaPeriodId associated with the drm session.
-
public void onDrmKeysRemoved(int windowIndex,
@Nullable[MediaSource.MediaPeriodId](../MediaSource.MediaPeriodId.html "class in com.google.android.exoplayer2.source")mediaPeriodId)
Deprecated.
Description copied from interface: DrmSessionEventListener
Called each time offline keys are removed.
Specified by:onDrmKeysRemoved in interface DrmSessionEventListenerParameters:windowIndex - The window index in the timeline this media period belongs to.mediaPeriodId - The MediaSource.MediaPeriodId associated with the drm session.
-
public void onDrmSessionReleased(int windowIndex,
@Nullable[MediaSource.MediaPeriodId](../MediaSource.MediaPeriodId.html "class in com.google.android.exoplayer2.source")mediaPeriodId)
Deprecated.
Description copied from interface: DrmSessionEventListener
Called each time a drm session is released.
Specified by:onDrmSessionReleased in interface DrmSessionEventListenerParameters:windowIndex - The window index in the timeline this media period belongs to.mediaPeriodId - The MediaSource.MediaPeriodId associated with the drm session.
-
public void onLoadStarted(int windowIndex,
@Nullable[MediaSource.MediaPeriodId](../MediaSource.MediaPeriodId.html "class in com.google.android.exoplayer2.source")mediaPeriodId,[LoadEventInfo](../LoadEventInfo.html "class in com.google.android.exoplayer2.source")loadEventInfo,[MediaLoadData](../MediaLoadData.html "class in com.google.android.exoplayer2.source")mediaLoadData)
Deprecated.
Description copied from interface: MediaSourceEventListener
Called when a load begins.
Specified by:onLoadStarted in interface MediaSourceEventListenerParameters:windowIndex - The window index in the timeline of the media source this load belongs to.mediaPeriodId - The MediaSource.MediaPeriodId this load belongs to. Null if the load does not belong to a specific media period.loadEventInfo - The LoadEventInfo corresponding to the event. The value of LoadEventInfo.uri won't reflect potential redirection yet and LoadEventInfo.responseHeaders will be empty.mediaLoadData - The MediaLoadData defining the data being loaded.
-
public void onLoadCompleted(int windowIndex,
@Nullable[MediaSource.MediaPeriodId](../MediaSource.MediaPeriodId.html "class in com.google.android.exoplayer2.source")mediaPeriodId,[LoadEventInfo](../LoadEventInfo.html "class in com.google.android.exoplayer2.source")loadEventInfo,[MediaLoadData](../MediaLoadData.html "class in com.google.android.exoplayer2.source")mediaLoadData)
Deprecated.
Description copied from interface: MediaSourceEventListener
Called when a load ends.
Specified by:onLoadCompleted in interface MediaSourceEventListenerParameters:windowIndex - The window index in the timeline of the media source this load belongs to.mediaPeriodId - The MediaSource.MediaPeriodId this load belongs to. Null if the load does not belong to a specific media period.loadEventInfo - The LoadEventInfo corresponding to the event. The values of LoadEventInfo.elapsedRealtimeMs and LoadEventInfo.bytesLoaded are relative to the corresponding MediaSourceEventListener.onLoadStarted(int, MediaPeriodId, LoadEventInfo, MediaLoadData) event.mediaLoadData - The MediaLoadData defining the data being loaded.
-
public void onLoadCanceled(int windowIndex,
@Nullable[MediaSource.MediaPeriodId](../MediaSource.MediaPeriodId.html "class in com.google.android.exoplayer2.source")mediaPeriodId,[LoadEventInfo](../LoadEventInfo.html "class in com.google.android.exoplayer2.source")loadEventInfo,[MediaLoadData](../MediaLoadData.html "class in com.google.android.exoplayer2.source")mediaLoadData)
Deprecated.
Description copied from interface: MediaSourceEventListener
Called when a load is canceled.
Specified by:onLoadCanceled in interface MediaSourceEventListenerParameters:windowIndex - The window index in the timeline of the media source this load belongs to.mediaPeriodId - The MediaSource.MediaPeriodId this load belongs to. Null if the load does not belong to a specific media period.loadEventInfo - The LoadEventInfo corresponding to the event. The values of LoadEventInfo.elapsedRealtimeMs and LoadEventInfo.bytesLoaded are relative to the corresponding MediaSourceEventListener.onLoadStarted(int, MediaPeriodId, LoadEventInfo, MediaLoadData) event.mediaLoadData - The MediaLoadData defining the data being loaded.
-
public void onLoadError(int windowIndex,
@Nullable[MediaSource.MediaPeriodId](../MediaSource.MediaPeriodId.html "class in com.google.android.exoplayer2.source")mediaPeriodId,[LoadEventInfo](../LoadEventInfo.html "class in com.google.android.exoplayer2.source")loadEventInfo,[MediaLoadData](../MediaLoadData.html "class in com.google.android.exoplayer2.source")mediaLoadData,[IOException](https://developer.android.com/reference/java/io/IOException.html "class or interface in java.io")error,
boolean wasCanceled)
Deprecated.
Description copied from interface: MediaSourceEventListener
Called when a load error occurs.
The error may or may not have resulted in the load being canceled, as indicated by the wasCanceled parameter. If the load was canceled, MediaSourceEventListener.onLoadCanceled(int, com.google.android.exoplayer2.source.MediaSource.MediaPeriodId, com.google.android.exoplayer2.source.LoadEventInfo, com.google.android.exoplayer2.source.MediaLoadData) will not be called in addition to this method.
This method being called does not indicate that playback has failed, or that it will fail. The player may be able to recover from the error. Hence applications should not implement this method to display a user visible error or initiate an application level retry. Player.Listener.onPlayerError(com.google.android.exoplayer2.PlaybackException) is the appropriate place to implement such behavior. This method is called to provide the application with an opportunity to log the error if it wishes to do so.
Specified by:onLoadError in interface MediaSourceEventListenerParameters:windowIndex - The window index in the timeline of the media source this load belongs to.mediaPeriodId - The MediaSource.MediaPeriodId this load belongs to. Null if the load does not belong to a specific media period.loadEventInfo - The LoadEventInfo corresponding to the event. The values of LoadEventInfo.elapsedRealtimeMs and LoadEventInfo.bytesLoaded are relative to the corresponding MediaSourceEventListener.onLoadStarted(int, MediaPeriodId, LoadEventInfo, MediaLoadData) event.mediaLoadData - The MediaLoadData defining the data being loaded.error - The load error.wasCanceled - Whether the load was canceled as a result of the error.
-
public void onUpstreamDiscarded(int windowIndex,[MediaSource.MediaPeriodId](../MediaSource.MediaPeriodId.html "class in com.google.android.exoplayer2.source")mediaPeriodId,[MediaLoadData](../MediaLoadData.html "class in com.google.android.exoplayer2.source")mediaLoadData)
Deprecated.
Description copied from interface: MediaSourceEventListener
Called when data is removed from the back of a media buffer, typically so that it can be re-buffered in a different format.
Specified by:onUpstreamDiscarded in interface MediaSourceEventListenerParameters:windowIndex - The window index in the timeline of the media source this load belongs to.mediaPeriodId - The MediaSource.MediaPeriodId the media belongs to.mediaLoadData - The MediaLoadData defining the media being discarded.
-
public void onDownstreamFormatChanged(int windowIndex,
@Nullable[MediaSource.MediaPeriodId](../MediaSource.MediaPeriodId.html "class in com.google.android.exoplayer2.source")mediaPeriodId,[MediaLoadData](../MediaLoadData.html "class in com.google.android.exoplayer2.source")mediaLoadData)
Deprecated.
Description copied from interface: MediaSourceEventListener
Called when a downstream format change occurs (i.e. when the format of the media being read from one or more SampleStreams provided by the source changes).
Specified by:onDownstreamFormatChanged in interface MediaSourceEventListenerParameters:windowIndex - The window index in the timeline of the media source this load belongs to.mediaPeriodId - The MediaSource.MediaPeriodId the media belongs to.mediaLoadData - The MediaLoadData defining the newly selected downstream data.