Class ServerSideAdInsertionMediaSource
- java.lang.Object
-
- com.google.android.exoplayer2.source.BaseMediaSource
-
- com.google.android.exoplayer2.source.ads.ServerSideAdInsertionMediaSource
-
- All Implemented Interfaces:
DrmSessionEventListener
,MediaSource
,MediaSource.MediaSourceCaller
,MediaSourceEventListener
@Deprecated public final class ServerSideAdInsertionMediaSource extends BaseMediaSource implements MediaSource.MediaSourceCaller, MediaSourceEventListener, DrmSessionEventListener
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.AMediaSource
for server-side inserted ad breaks.The media source publishes a
Timeline
for the wrappedMediaSource
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 Class Summary
Nested Classes Modifier and Type Class Description static interface
ServerSideAdInsertionMediaSource.AdPlaybackStateUpdater
Deprecated.Receives ad playback state update requests when theTimeline
of the content media source has changed.-
Nested classes/interfaces inherited from interface com.google.android.exoplayer2.drm.DrmSessionEventListener
DrmSessionEventListener.EventDispatcher
-
Nested classes/interfaces inherited from interface com.google.android.exoplayer2.source.MediaSource
MediaSource.Factory, MediaSource.MediaPeriodId, MediaSource.MediaSourceCaller
-
Nested classes/interfaces inherited from interface com.google.android.exoplayer2.source.MediaSourceEventListener
MediaSourceEventListener.EventDispatcher
-
-
Constructor Summary
Constructors Constructor Description ServerSideAdInsertionMediaSource(MediaSource mediaSource, ServerSideAdInsertionMediaSource.AdPlaybackStateUpdater adPlaybackStateUpdater)
Deprecated.Creates the media source.
-
Method Summary
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 newMediaPeriod
identified byperiodId
.protected void
disableInternal()
Deprecated.Disables the source, seeBaseMediaSource.disable(MediaSourceCaller)
.protected void
enableInternal()
Deprecated.Enables the source, seeBaseMediaSource.enable(MediaSourceCaller)
.MediaItem
getMediaItem()
Deprecated.Returns theMediaItem
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 theTimeline
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, seeBaseMediaSource.prepareSource(MediaSourceCaller, TransferListener, PlayerId)
.void
releasePeriod(MediaPeriod mediaPeriod)
Deprecated.Releases the period.protected void
releaseSourceInternal()
Deprecated.Releases the source, seeBaseMediaSource.releaseSource(MediaSourceCaller)
.void
setAdPlaybackStates(ImmutableMap<Object,AdPlaybackState> adPlaybackStates, Timeline contentTimeline)
Deprecated.Sets the map ofad playback states
published by this source.-
Methods inherited from class com.google.android.exoplayer2.source.BaseMediaSource
addDrmEventListener, addEventListener, createDrmEventDispatcher, createDrmEventDispatcher, createEventDispatcher, createEventDispatcher, createEventDispatcher, createEventDispatcher, disable, enable, getPlayerId, isEnabled, prepareSource, prepareSource, refreshSourceInfo, releaseSource, removeDrmEventListener, removeEventListener
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.google.android.exoplayer2.drm.DrmSessionEventListener
onDrmSessionAcquired
-
Methods inherited from interface com.google.android.exoplayer2.source.MediaSource
getInitialTimeline, isSingleWindow
-
-
-
-
Constructor Detail
-
ServerSideAdInsertionMediaSource
public ServerSideAdInsertionMediaSource(MediaSource mediaSource, @Nullable ServerSideAdInsertionMediaSource.AdPlaybackStateUpdater adPlaybackStateUpdater)
Deprecated.Creates the media source.- Parameters:
mediaSource
- TheMediaSource
to wrap.adPlaybackStateUpdater
- The optionalServerSideAdInsertionMediaSource.AdPlaybackStateUpdater
to be called before a source refresh is published.
-
-
Method Detail
-
setAdPlaybackStates
public void setAdPlaybackStates(ImmutableMap<Object,AdPlaybackState> adPlaybackStates, Timeline contentTimeline)
Deprecated.Sets the map ofad playback states
published by this source. The key is the period UID of a period in thecontentTimeline
.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 withC.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 ofAdPlaybackState
keyed by their period UID.contentTimeline
- The content timeline containing the periods with the UIDs used as keys in the map of playback states.
-
getMediaItem
public MediaItem getMediaItem()
Deprecated.Description copied from interface:MediaSource
Returns theMediaItem
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 interfaceMediaSource
-
prepareSourceInternal
protected void prepareSourceInternal(@Nullable TransferListener mediaTransferListener)
Deprecated.Description copied from class:BaseMediaSource
Starts source preparation and enables the source, seeBaseMediaSource.prepareSource(MediaSourceCaller, TransferListener, PlayerId)
. This method is called at most once until the next call toBaseMediaSource.releaseSourceInternal()
.- Specified by:
prepareSourceInternal
in classBaseMediaSource
- Parameters:
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.
-
maybeThrowSourceInfoRefreshError
public void maybeThrowSourceInfoRefreshError() throws IOException
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 interfaceMediaSource
- Throws:
IOException
-
enableInternal
protected void enableInternal()
Deprecated.Description copied from class:BaseMediaSource
Enables the source, seeBaseMediaSource.enable(MediaSourceCaller)
.- Overrides:
enableInternal
in classBaseMediaSource
-
disableInternal
protected void disableInternal()
Deprecated.Description copied from class:BaseMediaSource
Disables the source, seeBaseMediaSource.disable(MediaSourceCaller)
.- Overrides:
disableInternal
in classBaseMediaSource
-
onSourceInfoRefreshed
public void onSourceInfoRefreshed(MediaSource source, Timeline timeline)
Deprecated.Description copied from interface:MediaSource.MediaSourceCaller
Called when theTimeline
has been refreshed.Called on the playback thread.
- Specified by:
onSourceInfoRefreshed
in interfaceMediaSource.MediaSourceCaller
- Parameters:
source
- TheMediaSource
whose info has been refreshed.timeline
- The source's timeline.
-
releaseSourceInternal
protected void releaseSourceInternal()
Deprecated.Description copied from class:BaseMediaSource
Releases the source, seeBaseMediaSource.releaseSource(MediaSourceCaller)
. This method is called exactly once after each call toBaseMediaSource.prepareSourceInternal(TransferListener)
.- Specified by:
releaseSourceInternal
in classBaseMediaSource
-
createPeriod
public MediaPeriod createPeriod(MediaSource.MediaPeriodId id, Allocator allocator, long startPositionUs)
Deprecated.Description copied from interface:MediaSource
Returns a newMediaPeriod
identified byperiodId
.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 interfaceMediaSource
- Parameters:
id
- The identifier of the period.allocator
- AnAllocator
from which to obtain media buffer allocations.startPositionUs
- The expected start position, in microseconds.- Returns:
- A new
MediaPeriod
.
-
releasePeriod
public void releasePeriod(MediaPeriod 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 interfaceMediaSource
- Parameters:
mediaPeriod
- The period to release.
-
onDrmSessionAcquired
public void onDrmSessionAcquired(int windowIndex, @Nullable MediaSource.MediaPeriodId mediaPeriodId, @State @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 interfaceDrmSessionEventListener
- Parameters:
windowIndex
- The window index in the timeline this media period belongs to.mediaPeriodId
- TheMediaSource.MediaPeriodId
associated with the drm session.state
- TheDrmSession.State
of the session when the acquisition completed.
-
onDrmKeysLoaded
public void onDrmKeysLoaded(int windowIndex, @Nullable MediaSource.MediaPeriodId mediaPeriodId)
Deprecated.Description copied from interface:DrmSessionEventListener
Called each time keys are loaded.- Specified by:
onDrmKeysLoaded
in interfaceDrmSessionEventListener
- Parameters:
windowIndex
- The window index in the timeline this media period belongs to.mediaPeriodId
- TheMediaSource.MediaPeriodId
associated with the drm session.
-
onDrmSessionManagerError
public void onDrmSessionManagerError(int windowIndex, @Nullable MediaSource.MediaPeriodId mediaPeriodId, Exception 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 interfaceDrmSessionEventListener
- Parameters:
windowIndex
- The window index in the timeline this media period belongs to.mediaPeriodId
- TheMediaSource.MediaPeriodId
associated with the drm session.error
- The corresponding exception.
-
onDrmKeysRestored
public void onDrmKeysRestored(int windowIndex, @Nullable MediaSource.MediaPeriodId mediaPeriodId)
Deprecated.Description copied from interface:DrmSessionEventListener
Called each time offline keys are restored.- Specified by:
onDrmKeysRestored
in interfaceDrmSessionEventListener
- Parameters:
windowIndex
- The window index in the timeline this media period belongs to.mediaPeriodId
- TheMediaSource.MediaPeriodId
associated with the drm session.
-
onDrmKeysRemoved
public void onDrmKeysRemoved(int windowIndex, @Nullable MediaSource.MediaPeriodId mediaPeriodId)
Deprecated.Description copied from interface:DrmSessionEventListener
Called each time offline keys are removed.- Specified by:
onDrmKeysRemoved
in interfaceDrmSessionEventListener
- Parameters:
windowIndex
- The window index in the timeline this media period belongs to.mediaPeriodId
- TheMediaSource.MediaPeriodId
associated with the drm session.
-
onDrmSessionReleased
public void onDrmSessionReleased(int windowIndex, @Nullable MediaSource.MediaPeriodId mediaPeriodId)
Deprecated.Description copied from interface:DrmSessionEventListener
Called each time a drm session is released.- Specified by:
onDrmSessionReleased
in interfaceDrmSessionEventListener
- Parameters:
windowIndex
- The window index in the timeline this media period belongs to.mediaPeriodId
- TheMediaSource.MediaPeriodId
associated with the drm session.
-
onLoadStarted
public void onLoadStarted(int windowIndex, @Nullable MediaSource.MediaPeriodId mediaPeriodId, LoadEventInfo loadEventInfo, MediaLoadData mediaLoadData)
Deprecated.Description copied from interface:MediaSourceEventListener
Called when a load begins.- Specified by:
onLoadStarted
in interfaceMediaSourceEventListener
- Parameters:
windowIndex
- The window index in the timeline of the media source this load belongs to.mediaPeriodId
- TheMediaSource.MediaPeriodId
this load belongs to. Null if the load does not belong to a specific media period.loadEventInfo
- TheLoadEventInfo
corresponding to the event. The value ofLoadEventInfo.uri
won't reflect potential redirection yet andLoadEventInfo.responseHeaders
will be empty.mediaLoadData
- TheMediaLoadData
defining the data being loaded.
-
onLoadCompleted
public void onLoadCompleted(int windowIndex, @Nullable MediaSource.MediaPeriodId mediaPeriodId, LoadEventInfo loadEventInfo, MediaLoadData mediaLoadData)
Deprecated.Description copied from interface:MediaSourceEventListener
Called when a load ends.- Specified by:
onLoadCompleted
in interfaceMediaSourceEventListener
- Parameters:
windowIndex
- The window index in the timeline of the media source this load belongs to.mediaPeriodId
- TheMediaSource.MediaPeriodId
this load belongs to. Null if the load does not belong to a specific media period.loadEventInfo
- TheLoadEventInfo
corresponding to the event. The values ofLoadEventInfo.elapsedRealtimeMs
andLoadEventInfo.bytesLoaded
are relative to the correspondingMediaSourceEventListener.onLoadStarted(int, MediaPeriodId, LoadEventInfo, MediaLoadData)
event.mediaLoadData
- TheMediaLoadData
defining the data being loaded.
-
onLoadCanceled
public void onLoadCanceled(int windowIndex, @Nullable MediaSource.MediaPeriodId mediaPeriodId, LoadEventInfo loadEventInfo, MediaLoadData mediaLoadData)
Deprecated.Description copied from interface:MediaSourceEventListener
Called when a load is canceled.- Specified by:
onLoadCanceled
in interfaceMediaSourceEventListener
- Parameters:
windowIndex
- The window index in the timeline of the media source this load belongs to.mediaPeriodId
- TheMediaSource.MediaPeriodId
this load belongs to. Null if the load does not belong to a specific media period.loadEventInfo
- TheLoadEventInfo
corresponding to the event. The values ofLoadEventInfo.elapsedRealtimeMs
andLoadEventInfo.bytesLoaded
are relative to the correspondingMediaSourceEventListener.onLoadStarted(int, MediaPeriodId, LoadEventInfo, MediaLoadData)
event.mediaLoadData
- TheMediaLoadData
defining the data being loaded.
-
onLoadError
public void onLoadError(int windowIndex, @Nullable MediaSource.MediaPeriodId mediaPeriodId, LoadEventInfo loadEventInfo, MediaLoadData mediaLoadData, IOException 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 interfaceMediaSourceEventListener
- Parameters:
windowIndex
- The window index in the timeline of the media source this load belongs to.mediaPeriodId
- TheMediaSource.MediaPeriodId
this load belongs to. Null if the load does not belong to a specific media period.loadEventInfo
- TheLoadEventInfo
corresponding to the event. The values ofLoadEventInfo.elapsedRealtimeMs
andLoadEventInfo.bytesLoaded
are relative to the correspondingMediaSourceEventListener.onLoadStarted(int, MediaPeriodId, LoadEventInfo, MediaLoadData)
event.mediaLoadData
- TheMediaLoadData
defining the data being loaded.error
- The load error.wasCanceled
- Whether the load was canceled as a result of the error.
-
onUpstreamDiscarded
public void onUpstreamDiscarded(int windowIndex, MediaSource.MediaPeriodId mediaPeriodId, MediaLoadData 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 interfaceMediaSourceEventListener
- Parameters:
windowIndex
- The window index in the timeline of the media source this load belongs to.mediaPeriodId
- TheMediaSource.MediaPeriodId
the media belongs to.mediaLoadData
- TheMediaLoadData
defining the media being discarded.
-
onDownstreamFormatChanged
public void onDownstreamFormatChanged(int windowIndex, @Nullable MediaSource.MediaPeriodId mediaPeriodId, MediaLoadData 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 moreSampleStream
s provided by the source changes).- Specified by:
onDownstreamFormatChanged
in interfaceMediaSourceEventListener
- Parameters:
windowIndex
- The window index in the timeline of the media source this load belongs to.mediaPeriodId
- TheMediaSource.MediaPeriodId
the media belongs to.mediaLoadData
- TheMediaLoadData
defining the newly selected downstream data.
-
-