Class BaseMediaSource
- java.lang.Object
-
- com.google.android.exoplayer2.source.BaseMediaSource
-
- All Implemented Interfaces:
MediaSource
- Direct Known Subclasses:
CompositeMediaSource
,DashMediaSource
,FakeMediaSource
,HlsMediaSource
,ProgressiveMediaSource
,RtspMediaSource
,ServerSideAdInsertionMediaSource
,SilenceMediaSource
,SingleSampleMediaSource
,SsMediaSource
public abstract class BaseMediaSource extends Object implements MediaSource
BaseMediaSource
implementation to handle parallel reuse and to keep a list ofMediaSourceEventListener
s.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.Factory, 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 void
addDrmEventListener(Handler handler, DrmSessionEventListener eventListener)
Adds aDrmSessionEventListener
to the list of listeners which are notified of DRM events for this media source.void
addEventListener(Handler handler, MediaSourceEventListener eventListener)
Adds aMediaSourceEventListener
to the list of listeners which are notified of media source events.protected DrmSessionEventListener.EventDispatcher
createDrmEventDispatcher(int windowIndex, MediaSource.MediaPeriodId mediaPeriodId)
Returns aDrmSessionEventListener.EventDispatcher
which dispatches all events to the registered listeners with the specified window index andMediaSource.MediaPeriodId
.protected DrmSessionEventListener.EventDispatcher
createDrmEventDispatcher(MediaSource.MediaPeriodId mediaPeriodId)
Returns aDrmSessionEventListener.EventDispatcher
which dispatches all events to the registered listeners with the specifiedMediaSource.MediaPeriodId
protected MediaSourceEventListener.EventDispatcher
createEventDispatcher(int windowIndex, MediaSource.MediaPeriodId mediaPeriodId, long mediaTimeOffsetMs)
Returns aMediaSourceEventListener.EventDispatcher
which dispatches all events to the registered listeners with the specified window index,MediaSource.MediaPeriodId
and time offset.protected MediaSourceEventListener.EventDispatcher
createEventDispatcher(MediaSource.MediaPeriodId mediaPeriodId)
Returns aMediaSourceEventListener.EventDispatcher
which dispatches all events to the registered listeners with the specifiedMediaSource.MediaPeriodId
.protected MediaSourceEventListener.EventDispatcher
createEventDispatcher(MediaSource.MediaPeriodId mediaPeriodId, long mediaTimeOffsetMs)
Returns aMediaSourceEventListener.EventDispatcher
which dispatches all events to the registered listeners with the specifiedMediaSource.MediaPeriodId
and time offset.void
disable(MediaSource.MediaSourceCaller caller)
Disables the source for the creation ofMediaPeriods
.protected void
disableInternal()
Disables the source, seedisable(MediaSourceCaller)
.void
enable(MediaSource.MediaSourceCaller caller)
Enables the source for the creation ofMediaPeriods
.protected void
enableInternal()
Enables the source, seeenable(MediaSourceCaller)
.protected PlayerId
getPlayerId()
Returns thePlayerId
of the player using this media source.protected boolean
isEnabled()
Returns whether the source is enabled.void
prepareSource(MediaSource.MediaSourceCaller caller, TransferListener mediaTransferListener, PlayerId playerId)
Registers aMediaSource.MediaSourceCaller
.protected abstract void
prepareSourceInternal(TransferListener mediaTransferListener)
Starts source preparation and enables the source, seeprepareSource(MediaSourceCaller, TransferListener, PlayerId)
.protected void
refreshSourceInfo(Timeline timeline)
Updates timeline and manifest and notifies all listeners of the update.void
releaseSource(MediaSource.MediaSourceCaller caller)
Unregisters a caller, and disables and releases the source if no longer required.protected abstract void
releaseSourceInternal()
Releases the source, seereleaseSource(MediaSourceCaller)
.void
removeDrmEventListener(DrmSessionEventListener eventListener)
Removes aDrmSessionEventListener
from the list of listeners which are notified of DRM events for this media source.void
removeEventListener(MediaSourceEventListener eventListener)
Removes aMediaSourceEventListener
from 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, prepareSource, releasePeriod
-
-
-
-
Method Detail
-
prepareSourceInternal
protected abstract void prepareSourceInternal(@Nullable TransferListener mediaTransferListener)
Starts source preparation and enables the source, seeprepareSource(MediaSourceCaller, TransferListener, PlayerId)
. 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.EventDispatcher
which dispatches all events to the registered listeners with the specifiedMediaSource.MediaPeriodId
.- Parameters:
mediaPeriodId
- TheMediaSource.MediaPeriodId
to 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.EventDispatcher
which dispatches all events to the registered listeners with the specifiedMediaSource.MediaPeriodId
and time offset.- Parameters:
mediaPeriodId
- TheMediaSource.MediaPeriodId
to 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.EventDispatcher
which dispatches all events to the registered listeners with the specified window index,MediaSource.MediaPeriodId
and time offset.- Parameters:
windowIndex
- The timeline window index to be reported with the events.mediaPeriodId
- TheMediaSource.MediaPeriodId
to 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.EventDispatcher
which dispatches all events to the registered listeners with the specifiedMediaSource.MediaPeriodId
- Parameters:
mediaPeriodId
- TheMediaSource.MediaPeriodId
to 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.EventDispatcher
which 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.MediaPeriodId
to 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.
-
getPlayerId
protected final PlayerId getPlayerId()
-
addEventListener
public final void addEventListener(Handler handler, MediaSourceEventListener eventListener)
Description copied from interface:MediaSource
Adds aMediaSourceEventListener
to the list of listeners which are notified of media source events.- Specified by:
addEventListener
in 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:MediaSource
Removes aMediaSourceEventListener
from the list of listeners which are notified of media source events.- Specified by:
removeEventListener
in interfaceMediaSource
- Parameters:
eventListener
- The listener to be removed.
-
addDrmEventListener
public final void addDrmEventListener(Handler handler, DrmSessionEventListener eventListener)
Description copied from interface:MediaSource
Adds aDrmSessionEventListener
to the list of listeners which are notified of DRM events for this media source.- Specified by:
addDrmEventListener
in 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:MediaSource
Removes aDrmSessionEventListener
from the list of listeners which are notified of DRM events for this media source.- Specified by:
removeDrmEventListener
in interfaceMediaSource
- Parameters:
eventListener
- The listener to be removed.
-
prepareSource
public final void prepareSource(MediaSource.MediaSourceCaller caller, @Nullable TransferListener mediaTransferListener, PlayerId playerId)
Description copied from interface:MediaSource
Registers 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:
prepareSource
in interfaceMediaSource
- Parameters:
caller
- TheMediaSource.MediaSourceCaller
to 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.playerId
- ThePlayerId
of the player using this media source.
-
enable
public final void enable(MediaSource.MediaSourceCaller caller)
Description copied from interface:MediaSource
Enables the source for the creation ofMediaPeriods
.Should not be called directly from application code.
Must only be called after
MediaSource.prepareSource(MediaSourceCaller, TransferListener, PlayerId)
.- Specified by:
enable
in interfaceMediaSource
- Parameters:
caller
- TheMediaSource.MediaSourceCaller
enabling the source.
-
disable
public final void disable(MediaSource.MediaSourceCaller caller)
Description copied from interface:MediaSource
Disables 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
MediaPeriods
previously created byMediaSource.createPeriod(MediaPeriodId, Allocator, long)
have been released byMediaSource.releasePeriod(MediaPeriod)
.- Specified by:
disable
in interfaceMediaSource
- Parameters:
caller
- TheMediaSource.MediaSourceCaller
disabling the source.
-
releaseSource
public final void releaseSource(MediaSource.MediaSourceCaller caller)
Description copied from interface:MediaSource
Unregisters 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
MediaPeriods
have been released byMediaSource.releasePeriod(MediaPeriod)
.- Specified by:
releaseSource
in interfaceMediaSource
- Parameters:
caller
- TheMediaSource.MediaSourceCaller
to be unregistered.
-
-