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.AMediaSourcefor server-side inserted ad breaks.The media source publishes a
Timelinefor the wrappedMediaSourcewith 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 interfaceServerSideAdInsertionMediaSource.AdPlaybackStateUpdaterDeprecated.Receives ad playback state update requests when theTimelineof 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 MediaPeriodcreatePeriod(MediaSource.MediaPeriodId id, Allocator allocator, long startPositionUs)Deprecated.Returns a newMediaPeriodidentified byperiodId.protected voiddisableInternal()Deprecated.Disables the source, seeBaseMediaSource.disable(MediaSourceCaller).protected voidenableInternal()Deprecated.Enables the source, seeBaseMediaSource.enable(MediaSourceCaller).MediaItemgetMediaItem()Deprecated.Returns theMediaItemwhose media is provided by the source.voidmaybeThrowSourceInfoRefreshError()Deprecated.Throws any pending error encountered while loading or refreshing source information.voidonDownstreamFormatChanged(int windowIndex, MediaSource.MediaPeriodId mediaPeriodId, MediaLoadData mediaLoadData)Deprecated.Called when a downstream format change occurs (i.e.voidonDrmKeysLoaded(int windowIndex, MediaSource.MediaPeriodId mediaPeriodId)Deprecated.Called each time keys are loaded.voidonDrmKeysRemoved(int windowIndex, MediaSource.MediaPeriodId mediaPeriodId)Deprecated.Called each time offline keys are removed.voidonDrmKeysRestored(int windowIndex, MediaSource.MediaPeriodId mediaPeriodId)Deprecated.Called each time offline keys are restored.voidonDrmSessionAcquired(int windowIndex, MediaSource.MediaPeriodId mediaPeriodId, @com.google.android.exoplayer2.drm.DrmSession.State int state)Deprecated.Called each time a drm session is acquired.voidonDrmSessionManagerError(int windowIndex, MediaSource.MediaPeriodId mediaPeriodId, Exception error)Deprecated.Called when a drm error occurs.voidonDrmSessionReleased(int windowIndex, MediaSource.MediaPeriodId mediaPeriodId)Deprecated.Called each time a drm session is released.voidonLoadCanceled(int windowIndex, MediaSource.MediaPeriodId mediaPeriodId, LoadEventInfo loadEventInfo, MediaLoadData mediaLoadData)Deprecated.Called when a load is canceled.voidonLoadCompleted(int windowIndex, MediaSource.MediaPeriodId mediaPeriodId, LoadEventInfo loadEventInfo, MediaLoadData mediaLoadData)Deprecated.Called when a load ends.voidonLoadError(int windowIndex, MediaSource.MediaPeriodId mediaPeriodId, LoadEventInfo loadEventInfo, MediaLoadData mediaLoadData, IOException error, boolean wasCanceled)Deprecated.Called when a load error occurs.voidonLoadStarted(int windowIndex, MediaSource.MediaPeriodId mediaPeriodId, LoadEventInfo loadEventInfo, MediaLoadData mediaLoadData)Deprecated.Called when a load begins.voidonSourceInfoRefreshed(MediaSource source, Timeline timeline)Deprecated.Called when theTimelinehas been refreshed.voidonUpstreamDiscarded(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 voidprepareSourceInternal(TransferListener mediaTransferListener)Deprecated.Starts source preparation and enables the source, seeBaseMediaSource.prepareSource(MediaSourceCaller, TransferListener, PlayerId).voidreleasePeriod(MediaPeriod mediaPeriod)Deprecated.Releases the period.protected voidreleaseSourceInternal()Deprecated.Releases the source, seeBaseMediaSource.releaseSource(MediaSourceCaller).voidsetAdPlaybackStates(ImmutableMap<Object,AdPlaybackState> adPlaybackStates, Timeline contentTimeline)Deprecated.Sets the map ofad playback statespublished 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- TheMediaSourceto wrap.adPlaybackStateUpdater- The optionalServerSideAdInsertionMediaSource.AdPlaybackStateUpdaterto 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 statespublished by this source. The key is the period UID of a period in thecontentTimeline.Each period has an
AdPlaybackStatethat 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_SOURCEmust be empty and can be used as a placeholder for a future ad group.May be called from any thread.
- Parameters:
adPlaybackStates- The map ofAdPlaybackStatekeyed 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:MediaSourceReturns theMediaItemwhose 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:
getMediaItemin interfaceMediaSource
-
prepareSourceInternal
protected void prepareSourceInternal(@Nullable TransferListener mediaTransferListener)Deprecated.Description copied from class:BaseMediaSourceStarts 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:
prepareSourceInternalin 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 IOExceptionDeprecated.Description copied from interface:MediaSourceThrows 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:
maybeThrowSourceInfoRefreshErrorin interfaceMediaSource- Throws:
IOException
-
enableInternal
protected void enableInternal()
Deprecated.Description copied from class:BaseMediaSourceEnables the source, seeBaseMediaSource.enable(MediaSourceCaller).- Overrides:
enableInternalin classBaseMediaSource
-
disableInternal
protected void disableInternal()
Deprecated.Description copied from class:BaseMediaSourceDisables the source, seeBaseMediaSource.disable(MediaSourceCaller).- Overrides:
disableInternalin classBaseMediaSource
-
onSourceInfoRefreshed
public void onSourceInfoRefreshed(MediaSource source, Timeline timeline)
Deprecated.Description copied from interface:MediaSource.MediaSourceCallerCalled when theTimelinehas been refreshed.Called on the playback thread.
- Specified by:
onSourceInfoRefreshedin interfaceMediaSource.MediaSourceCaller- Parameters:
source- TheMediaSourcewhose info has been refreshed.timeline- The source's timeline.
-
releaseSourceInternal
protected void releaseSourceInternal()
Deprecated.Description copied from class:BaseMediaSourceReleases the source, seeBaseMediaSource.releaseSource(MediaSourceCaller). This method is called exactly once after each call toBaseMediaSource.prepareSourceInternal(TransferListener).- Specified by:
releaseSourceInternalin classBaseMediaSource
-
createPeriod
public MediaPeriod createPeriod(MediaSource.MediaPeriodId id, Allocator allocator, long startPositionUs)
Deprecated.Description copied from interface:MediaSourceReturns a newMediaPeriodidentified 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:
createPeriodin interfaceMediaSource- Parameters:
id- The identifier of the period.allocator- AnAllocatorfrom 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:MediaSourceReleases the period.Should not be called directly from application code.
This method must be called on the playback thread.
- Specified by:
releasePeriodin 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:DrmSessionEventListenerCalled each time a drm session is acquired.- Specified by:
onDrmSessionAcquiredin interfaceDrmSessionEventListener- Parameters:
windowIndex- The window index in the timeline this media period belongs to.mediaPeriodId- TheMediaSource.MediaPeriodIdassociated with the drm session.state- TheDrmSession.Stateof the session when the acquisition completed.
-
onDrmKeysLoaded
public void onDrmKeysLoaded(int windowIndex, @Nullable MediaSource.MediaPeriodId mediaPeriodId)Deprecated.Description copied from interface:DrmSessionEventListenerCalled each time keys are loaded.- Specified by:
onDrmKeysLoadedin interfaceDrmSessionEventListener- Parameters:
windowIndex- The window index in the timeline this media period belongs to.mediaPeriodId- TheMediaSource.MediaPeriodIdassociated with the drm session.
-
onDrmSessionManagerError
public void onDrmSessionManagerError(int windowIndex, @Nullable MediaSource.MediaPeriodId mediaPeriodId, Exception error)Deprecated.Description copied from interface:DrmSessionEventListenerCalled 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:
onDrmSessionManagerErrorin interfaceDrmSessionEventListener- Parameters:
windowIndex- The window index in the timeline this media period belongs to.mediaPeriodId- TheMediaSource.MediaPeriodIdassociated with the drm session.error- The corresponding exception.
-
onDrmKeysRestored
public void onDrmKeysRestored(int windowIndex, @Nullable MediaSource.MediaPeriodId mediaPeriodId)Deprecated.Description copied from interface:DrmSessionEventListenerCalled each time offline keys are restored.- Specified by:
onDrmKeysRestoredin interfaceDrmSessionEventListener- Parameters:
windowIndex- The window index in the timeline this media period belongs to.mediaPeriodId- TheMediaSource.MediaPeriodIdassociated with the drm session.
-
onDrmKeysRemoved
public void onDrmKeysRemoved(int windowIndex, @Nullable MediaSource.MediaPeriodId mediaPeriodId)Deprecated.Description copied from interface:DrmSessionEventListenerCalled each time offline keys are removed.- Specified by:
onDrmKeysRemovedin interfaceDrmSessionEventListener- Parameters:
windowIndex- The window index in the timeline this media period belongs to.mediaPeriodId- TheMediaSource.MediaPeriodIdassociated with the drm session.
-
onDrmSessionReleased
public void onDrmSessionReleased(int windowIndex, @Nullable MediaSource.MediaPeriodId mediaPeriodId)Deprecated.Description copied from interface:DrmSessionEventListenerCalled each time a drm session is released.- Specified by:
onDrmSessionReleasedin interfaceDrmSessionEventListener- Parameters:
windowIndex- The window index in the timeline this media period belongs to.mediaPeriodId- TheMediaSource.MediaPeriodIdassociated with the drm session.
-
onLoadStarted
public void onLoadStarted(int windowIndex, @Nullable MediaSource.MediaPeriodId mediaPeriodId, LoadEventInfo loadEventInfo, MediaLoadData mediaLoadData)Deprecated.Description copied from interface:MediaSourceEventListenerCalled when a load begins.- Specified by:
onLoadStartedin interfaceMediaSourceEventListener- Parameters:
windowIndex- The window index in the timeline of the media source this load belongs to.mediaPeriodId- TheMediaSource.MediaPeriodIdthis load belongs to. Null if the load does not belong to a specific media period.loadEventInfo- TheLoadEventInfocorresponding to the event. The value ofLoadEventInfo.uriwon't reflect potential redirection yet andLoadEventInfo.responseHeaderswill be empty.mediaLoadData- TheMediaLoadDatadefining the data being loaded.
-
onLoadCompleted
public void onLoadCompleted(int windowIndex, @Nullable MediaSource.MediaPeriodId mediaPeriodId, LoadEventInfo loadEventInfo, MediaLoadData mediaLoadData)Deprecated.Description copied from interface:MediaSourceEventListenerCalled when a load ends.- Specified by:
onLoadCompletedin interfaceMediaSourceEventListener- Parameters:
windowIndex- The window index in the timeline of the media source this load belongs to.mediaPeriodId- TheMediaSource.MediaPeriodIdthis load belongs to. Null if the load does not belong to a specific media period.loadEventInfo- TheLoadEventInfocorresponding to the event. The values ofLoadEventInfo.elapsedRealtimeMsandLoadEventInfo.bytesLoadedare relative to the correspondingMediaSourceEventListener.onLoadStarted(int, MediaPeriodId, LoadEventInfo, MediaLoadData)event.mediaLoadData- TheMediaLoadDatadefining the data being loaded.
-
onLoadCanceled
public void onLoadCanceled(int windowIndex, @Nullable MediaSource.MediaPeriodId mediaPeriodId, LoadEventInfo loadEventInfo, MediaLoadData mediaLoadData)Deprecated.Description copied from interface:MediaSourceEventListenerCalled when a load is canceled.- Specified by:
onLoadCanceledin interfaceMediaSourceEventListener- Parameters:
windowIndex- The window index in the timeline of the media source this load belongs to.mediaPeriodId- TheMediaSource.MediaPeriodIdthis load belongs to. Null if the load does not belong to a specific media period.loadEventInfo- TheLoadEventInfocorresponding to the event. The values ofLoadEventInfo.elapsedRealtimeMsandLoadEventInfo.bytesLoadedare relative to the correspondingMediaSourceEventListener.onLoadStarted(int, MediaPeriodId, LoadEventInfo, MediaLoadData)event.mediaLoadData- TheMediaLoadDatadefining 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:MediaSourceEventListenerCalled when a load error occurs.The error may or may not have resulted in the load being canceled, as indicated by the
wasCanceledparameter. 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:
onLoadErrorin interfaceMediaSourceEventListener- Parameters:
windowIndex- The window index in the timeline of the media source this load belongs to.mediaPeriodId- TheMediaSource.MediaPeriodIdthis load belongs to. Null if the load does not belong to a specific media period.loadEventInfo- TheLoadEventInfocorresponding to the event. The values ofLoadEventInfo.elapsedRealtimeMsandLoadEventInfo.bytesLoadedare relative to the correspondingMediaSourceEventListener.onLoadStarted(int, MediaPeriodId, LoadEventInfo, MediaLoadData)event.mediaLoadData- TheMediaLoadDatadefining 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:MediaSourceEventListenerCalled 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:
onUpstreamDiscardedin interfaceMediaSourceEventListener- Parameters:
windowIndex- The window index in the timeline of the media source this load belongs to.mediaPeriodId- TheMediaSource.MediaPeriodIdthe media belongs to.mediaLoadData- TheMediaLoadDatadefining the media being discarded.
-
onDownstreamFormatChanged
public void onDownstreamFormatChanged(int windowIndex, @Nullable MediaSource.MediaPeriodId mediaPeriodId, MediaLoadData mediaLoadData)Deprecated.Description copied from interface:MediaSourceEventListenerCalled when a downstream format change occurs (i.e. when the format of the media being read from one or moreSampleStreams provided by the source changes).- Specified by:
onDownstreamFormatChangedin interfaceMediaSourceEventListener- Parameters:
windowIndex- The window index in the timeline of the media source this load belongs to.mediaPeriodId- TheMediaSource.MediaPeriodIdthe media belongs to.mediaLoadData- TheMediaLoadDatadefining the newly selected downstream data.
-
-