Class BaseMediaSource
- java.lang.Object
-
- com.google.android.exoplayer2.source.BaseMediaSource
-
- All Implemented Interfaces:
MediaSource
- Direct Known Subclasses:
CompositeMediaSource,DashMediaSource,FakeMediaSource,HlsMediaSource,ProgressiveMediaSource,RtspMediaSource,ServerSideInsertedAdsMediaSource,SilenceMediaSource,SingleSampleMediaSource,SsMediaSource
public abstract class BaseMediaSource extends Object implements MediaSource
BaseMediaSourceimplementation to handle parallel reuse and to keep a list ofMediaSourceEventListeners.Whenever an implementing subclass needs to provide a new timeline, it must call
refreshSourceInfo(Timeline)to notify all listeners.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.google.android.exoplayer2.source.MediaSource
MediaSource.MediaPeriodId, MediaSource.MediaSourceCaller
-
-
Constructor Summary
Constructors Constructor Description BaseMediaSource()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddDrmEventListener(Handler handler, DrmSessionEventListener eventListener)Adds aDrmSessionEventListenerto the list of listeners which are notified of DRM events for this media source.voidaddEventListener(Handler handler, MediaSourceEventListener eventListener)Adds aMediaSourceEventListenerto the list of listeners which are notified of media source events.protected DrmSessionEventListener.EventDispatchercreateDrmEventDispatcher(int windowIndex, MediaSource.MediaPeriodId mediaPeriodId)Returns aDrmSessionEventListener.EventDispatcherwhich dispatches all events to the registered listeners with the specified window index andMediaSource.MediaPeriodId.protected DrmSessionEventListener.EventDispatchercreateDrmEventDispatcher(MediaSource.MediaPeriodId mediaPeriodId)Returns aDrmSessionEventListener.EventDispatcherwhich dispatches all events to the registered listeners with the specifiedMediaSource.MediaPeriodIdprotected MediaSourceEventListener.EventDispatchercreateEventDispatcher(int windowIndex, MediaSource.MediaPeriodId mediaPeriodId, long mediaTimeOffsetMs)Returns aMediaSourceEventListener.EventDispatcherwhich dispatches all events to the registered listeners with the specified window index,MediaSource.MediaPeriodIdand time offset.protected MediaSourceEventListener.EventDispatchercreateEventDispatcher(MediaSource.MediaPeriodId mediaPeriodId)Returns aMediaSourceEventListener.EventDispatcherwhich dispatches all events to the registered listeners with the specifiedMediaSource.MediaPeriodId.protected MediaSourceEventListener.EventDispatchercreateEventDispatcher(MediaSource.MediaPeriodId mediaPeriodId, long mediaTimeOffsetMs)Returns aMediaSourceEventListener.EventDispatcherwhich dispatches all events to the registered listeners with the specifiedMediaSource.MediaPeriodIdand time offset.voiddisable(MediaSource.MediaSourceCaller caller)Disables the source for the creation ofMediaPeriods.protected voiddisableInternal()Disables the source, seedisable(MediaSourceCaller).voidenable(MediaSource.MediaSourceCaller caller)Enables the source for the creation ofMediaPeriods.protected voidenableInternal()Enables the source, seeenable(MediaSourceCaller).protected booleanisEnabled()Returns whether the source is enabled.voidprepareSource(MediaSource.MediaSourceCaller caller, TransferListener mediaTransferListener)Registers aMediaSource.MediaSourceCaller.protected abstract voidprepareSourceInternal(TransferListener mediaTransferListener)Starts source preparation and enables the source, seeprepareSource(MediaSourceCaller, TransferListener).protected voidrefreshSourceInfo(Timeline timeline)Updates timeline and manifest and notifies all listeners of the update.voidreleaseSource(MediaSource.MediaSourceCaller caller)Unregisters a caller, and disables and releases the source if no longer required.protected abstract voidreleaseSourceInternal()Releases the source, seereleaseSource(MediaSourceCaller).voidremoveDrmEventListener(DrmSessionEventListener eventListener)Removes aDrmSessionEventListenerfrom the list of listeners which are notified of DRM events for this media source.voidremoveEventListener(MediaSourceEventListener eventListener)Removes aMediaSourceEventListenerfrom the list of listeners which are notified of media source events.-
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.source.MediaSource
createPeriod, getInitialTimeline, getMediaItem, isSingleWindow, maybeThrowSourceInfoRefreshError, releasePeriod
-
-
-
-
Method Detail
-
prepareSourceInternal
protected abstract void prepareSourceInternal(@Nullable TransferListener mediaTransferListener)Starts source preparation and enables the source, seeprepareSource(MediaSourceCaller, TransferListener). This method is called at most once until the next call toreleaseSourceInternal().- 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.
-
enableInternal
protected void enableInternal()
Enables the source, seeenable(MediaSourceCaller).
-
disableInternal
protected void disableInternal()
Disables the source, seedisable(MediaSourceCaller).
-
releaseSourceInternal
protected abstract void releaseSourceInternal()
Releases the source, seereleaseSource(MediaSourceCaller). This method is called exactly once after each call toprepareSourceInternal(TransferListener).
-
refreshSourceInfo
protected final void refreshSourceInfo(Timeline timeline)
Updates timeline and manifest and notifies all listeners of the update.- Parameters:
timeline- The newTimeline.
-
createEventDispatcher
protected final MediaSourceEventListener.EventDispatcher createEventDispatcher(@Nullable MediaSource.MediaPeriodId mediaPeriodId)
Returns aMediaSourceEventListener.EventDispatcherwhich dispatches all events to the registered listeners with the specifiedMediaSource.MediaPeriodId.- Parameters:
mediaPeriodId- TheMediaSource.MediaPeriodIdto be reported with the events. May be null, if the events do not belong to a specific media period.- Returns:
- An event dispatcher with pre-configured media period id.
-
createEventDispatcher
protected final MediaSourceEventListener.EventDispatcher createEventDispatcher(MediaSource.MediaPeriodId mediaPeriodId, long mediaTimeOffsetMs)
Returns aMediaSourceEventListener.EventDispatcherwhich dispatches all events to the registered listeners with the specifiedMediaSource.MediaPeriodIdand time offset.- Parameters:
mediaPeriodId- TheMediaSource.MediaPeriodIdto be reported with the events.mediaTimeOffsetMs- The offset to be added to all media times, in milliseconds.- Returns:
- An event dispatcher with pre-configured media period id and time offset.
-
createEventDispatcher
protected final MediaSourceEventListener.EventDispatcher createEventDispatcher(int windowIndex, @Nullable MediaSource.MediaPeriodId mediaPeriodId, long mediaTimeOffsetMs)
Returns aMediaSourceEventListener.EventDispatcherwhich dispatches all events to the registered listeners with the specified window index,MediaSource.MediaPeriodIdand time offset.- Parameters:
windowIndex- The timeline window index to be reported with the events.mediaPeriodId- TheMediaSource.MediaPeriodIdto be reported with the events. May be null, if the events do not belong to a specific media period.mediaTimeOffsetMs- The offset to be added to all media times, in milliseconds.- Returns:
- An event dispatcher with pre-configured media period id and time offset.
-
createDrmEventDispatcher
protected final DrmSessionEventListener.EventDispatcher createDrmEventDispatcher(@Nullable MediaSource.MediaPeriodId mediaPeriodId)
Returns aDrmSessionEventListener.EventDispatcherwhich dispatches all events to the registered listeners with the specifiedMediaSource.MediaPeriodId- Parameters:
mediaPeriodId- TheMediaSource.MediaPeriodIdto be reported with the events. May be null, if the events do not belong to a specific media period.- Returns:
- An event dispatcher with pre-configured media period id.
-
createDrmEventDispatcher
protected final DrmSessionEventListener.EventDispatcher createDrmEventDispatcher(int windowIndex, @Nullable MediaSource.MediaPeriodId mediaPeriodId)
Returns aDrmSessionEventListener.EventDispatcherwhich dispatches all events to the registered listeners with the specified window index andMediaSource.MediaPeriodId.- Parameters:
windowIndex- The timeline window index to be reported with the events.mediaPeriodId- TheMediaSource.MediaPeriodIdto be reported with the events. May be null, if the events do not belong to a specific media period.- Returns:
- An event dispatcher with pre-configured media period id and time offset.
-
isEnabled
protected final boolean isEnabled()
Returns whether the source is enabled.
-
addEventListener
public final void addEventListener(Handler handler, MediaSourceEventListener eventListener)
Description copied from interface:MediaSourceAdds aMediaSourceEventListenerto the list of listeners which are notified of media source events.- Specified by:
addEventListenerin interfaceMediaSource- Parameters:
handler- A handler on the which listener events will be posted.eventListener- The listener to be added.
-
removeEventListener
public final void removeEventListener(MediaSourceEventListener eventListener)
Description copied from interface:MediaSourceRemoves aMediaSourceEventListenerfrom the list of listeners which are notified of media source events.- Specified by:
removeEventListenerin interfaceMediaSource- Parameters:
eventListener- The listener to be removed.
-
addDrmEventListener
public final void addDrmEventListener(Handler handler, DrmSessionEventListener eventListener)
Description copied from interface:MediaSourceAdds aDrmSessionEventListenerto the list of listeners which are notified of DRM events for this media source.- Specified by:
addDrmEventListenerin interfaceMediaSource- Parameters:
handler- A handler on the which listener events will be posted.eventListener- The listener to be added.
-
removeDrmEventListener
public final void removeDrmEventListener(DrmSessionEventListener eventListener)
Description copied from interface:MediaSourceRemoves aDrmSessionEventListenerfrom the list of listeners which are notified of DRM events for this media source.- Specified by:
removeDrmEventListenerin interfaceMediaSource- Parameters:
eventListener- The listener to be removed.
-
prepareSource
public final void prepareSource(MediaSource.MediaSourceCaller caller, @Nullable TransferListener mediaTransferListener)
Description copied from interface:MediaSourceRegisters aMediaSource.MediaSourceCaller. Starts source preparation if needed and enables the source for the creation ofMediaPerods.Should not be called directly from application code.
MediaSource.MediaSourceCaller.onSourceInfoRefreshed(MediaSource, Timeline)will be called once the source has aTimeline.For each call to this method, a call to
MediaSource.releaseSource(MediaSourceCaller)is needed to remove the caller and to release the source if no longer required.- Specified by:
prepareSourcein interfaceMediaSource- Parameters:
caller- TheMediaSource.MediaSourceCallerto be registered.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 be only informed of transfers related to the media loads and not of auxiliary loads for manifests and other data.
-
enable
public final void enable(MediaSource.MediaSourceCaller caller)
Description copied from interface:MediaSourceEnables the source for the creation ofMediaPeriods.Should not be called directly from application code.
Must only be called after
MediaSource.prepareSource(MediaSourceCaller, TransferListener).- Specified by:
enablein interfaceMediaSource- Parameters:
caller- TheMediaSource.MediaSourceCallerenabling the source.
-
disable
public final void disable(MediaSource.MediaSourceCaller caller)
Description copied from interface:MediaSourceDisables the source for the creation ofMediaPeriods. The implementation should not hold onto limited resources used for the creation of media periods.Should not be called directly from application code.
Must only be called after all
MediaPeriodspreviously created byMediaSource.createPeriod(MediaPeriodId, Allocator, long)have been released byMediaSource.releasePeriod(MediaPeriod).- Specified by:
disablein interfaceMediaSource- Parameters:
caller- TheMediaSource.MediaSourceCallerdisabling the source.
-
releaseSource
public final void releaseSource(MediaSource.MediaSourceCaller caller)
Description copied from interface:MediaSourceUnregisters a caller, and disables and releases the source if no longer required.Should not be called directly from application code.
Must only be called if all created
MediaPeriodshave been released byMediaSource.releasePeriod(MediaPeriod).- Specified by:
releaseSourcein interfaceMediaSource- Parameters:
caller- TheMediaSource.MediaSourceCallerto be unregistered.
-
-