MediaSourceCompositeMediaSource, DashMediaSource, FakeMediaSource, HlsMediaSource, ProgressiveMediaSource, SilenceMediaSource, SingleSampleMediaSource, SsMediaSourcepublic abstract class BaseMediaSource extends Object implements MediaSource
MediaSource implementation to handle parallel reuse and to keep a list of MediaSourceEventListeners.
Whenever an implementing subclass needs to provide a new timeline, it must call refreshSourceInfo(Timeline) to notify all listeners.
MediaSource.MediaPeriodId, MediaSource.MediaSourceCaller| Constructor | Description |
|---|---|
BaseMediaSource() |
| Modifier and Type | Method | Description |
|---|---|---|
void |
addDrmEventListener(Handler handler,
DrmSessionEventListener eventListener) |
Adds a
DrmSessionEventListener to the list of listeners which are notified of DRM
events for this media source. |
void |
addEventListener(Handler handler,
MediaSourceEventListener eventListener) |
Adds a
MediaSourceEventListener to the list of listeners which are notified of media
source events. |
protected DrmSessionEventListener.EventDispatcher |
createDrmEventDispatcher(int windowIndex,
MediaSource.MediaPeriodId mediaPeriodId) |
Returns a
DrmSessionEventListener.EventDispatcher which dispatches all events to the
registered listeners with the specified window index and media period id. |
protected DrmSessionEventListener.EventDispatcher |
createDrmEventDispatcher(MediaSource.MediaPeriodId mediaPeriodId) |
Returns a
DrmSessionEventListener.EventDispatcher which dispatches all events to the
registered listeners with the specified media period id. |
protected MediaSourceEventListener.EventDispatcher |
createEventDispatcher(int windowIndex,
MediaSource.MediaPeriodId mediaPeriodId,
long mediaTimeOffsetMs) |
Returns a
MediaSourceEventListener.EventDispatcher which dispatches all events to the
registered listeners with the specified window index, media period id and time offset. |
protected MediaSourceEventListener.EventDispatcher |
createEventDispatcher(MediaSource.MediaPeriodId mediaPeriodId) |
Returns a
MediaSourceEventListener.EventDispatcher which dispatches all events to the
registered listeners with the specified media period id. |
protected MediaSourceEventListener.EventDispatcher |
createEventDispatcher(MediaSource.MediaPeriodId mediaPeriodId,
long mediaTimeOffsetMs) |
Returns a
MediaSourceEventListener.EventDispatcher which dispatches all events to the
registered listeners with the specified media period id and time offset. |
void |
disable(MediaSource.MediaSourceCaller caller) |
Disables the source for the creation of
MediaPeriods. |
protected void |
disableInternal() |
Disables the source, see
disable(MediaSourceCaller). |
void |
enable(MediaSource.MediaSourceCaller caller) |
Enables the source for the creation of
MediaPeriods. |
protected void |
enableInternal() |
Enables the source, see
enable(MediaSourceCaller). |
protected boolean |
isEnabled() |
Returns whether the source is enabled.
|
void |
prepareSource(MediaSource.MediaSourceCaller caller,
TransferListener mediaTransferListener) |
Registers a
MediaSource.MediaSourceCaller. |
protected abstract void |
prepareSourceInternal(TransferListener mediaTransferListener) |
Starts source preparation and enables the source, see
prepareSource(MediaSourceCaller,
TransferListener). |
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, see
releaseSource(MediaSourceCaller). |
void |
removeDrmEventListener(DrmSessionEventListener eventListener) |
Removes a
DrmSessionEventListener from the list of listeners which are notified of DRM
events for this media source. |
void |
removeEventListener(MediaSourceEventListener eventListener) |
Removes a
MediaSourceEventListener from the list of listeners which are notified of
media source events. |
createPeriod, getInitialTimeline, getMediaItem, getTag, isSingleWindow, maybeThrowSourceInfoRefreshError, releasePeriodprotected abstract void prepareSourceInternal(@Nullable
TransferListener mediaTransferListener)
prepareSource(MediaSourceCaller,
TransferListener). This method is called at most once until the next call to releaseSourceInternal().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.protected void enableInternal()
enable(MediaSourceCaller).protected void disableInternal()
disable(MediaSourceCaller).protected abstract void releaseSourceInternal()
releaseSource(MediaSourceCaller). This method is called
exactly once after each call to prepareSourceInternal(TransferListener).protected final void refreshSourceInfo(Timeline timeline)
timeline - The new Timeline.protected final MediaSourceEventListener.EventDispatcher createEventDispatcher(@Nullable MediaSource.MediaPeriodId mediaPeriodId)
MediaSourceEventListener.EventDispatcher which dispatches all events to the
registered listeners with the specified media period id.mediaPeriodId - The MediaSource.MediaPeriodId to be reported with the events. May be null, if
the events do not belong to a specific media period.protected final MediaSourceEventListener.EventDispatcher createEventDispatcher(MediaSource.MediaPeriodId mediaPeriodId, long mediaTimeOffsetMs)
MediaSourceEventListener.EventDispatcher which dispatches all events to the
registered listeners with the specified media period id and time offset.mediaPeriodId - The MediaSource.MediaPeriodId to be reported with the events.mediaTimeOffsetMs - The offset to be added to all media times, in milliseconds.protected final MediaSourceEventListener.EventDispatcher createEventDispatcher(int windowIndex, @Nullable MediaSource.MediaPeriodId mediaPeriodId, long mediaTimeOffsetMs)
MediaSourceEventListener.EventDispatcher which dispatches all events to the
registered listeners with the specified window index, media period id and time offset.windowIndex - The timeline window index to be reported with the events.mediaPeriodId - The MediaSource.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.protected final DrmSessionEventListener.EventDispatcher createDrmEventDispatcher(@Nullable MediaSource.MediaPeriodId mediaPeriodId)
DrmSessionEventListener.EventDispatcher which dispatches all events to the
registered listeners with the specified media period id.mediaPeriodId - The MediaSource.MediaPeriodId to be reported with the events. May be null, if
the events do not belong to a specific media period.protected final DrmSessionEventListener.EventDispatcher createDrmEventDispatcher(int windowIndex, @Nullable MediaSource.MediaPeriodId mediaPeriodId)
DrmSessionEventListener.EventDispatcher which dispatches all events to the
registered listeners with the specified window index and media period id.windowIndex - The timeline window index to be reported with the events.mediaPeriodId - The MediaSource.MediaPeriodId to be reported with the events. May be null, if
the events do not belong to a specific media period.protected final boolean isEnabled()
public final void addEventListener(Handler handler, MediaSourceEventListener eventListener)
MediaSourceMediaSourceEventListener to the list of listeners which are notified of media
source events.addEventListener in interface MediaSourcehandler - A handler on the which listener events will be posted.eventListener - The listener to be added.public final void removeEventListener(MediaSourceEventListener eventListener)
MediaSourceMediaSourceEventListener from the list of listeners which are notified of
media source events.removeEventListener in interface MediaSourceeventListener - The listener to be removed.public final void addDrmEventListener(Handler handler, DrmSessionEventListener eventListener)
MediaSourceDrmSessionEventListener to the list of listeners which are notified of DRM
events for this media source.addDrmEventListener in interface MediaSourcehandler - A handler on the which listener events will be posted.eventListener - The listener to be added.public final void removeDrmEventListener(DrmSessionEventListener eventListener)
MediaSourceDrmSessionEventListener from the list of listeners which are notified of DRM
events for this media source.removeDrmEventListener in interface MediaSourceeventListener - The listener to be removed.public final void prepareSource(MediaSource.MediaSourceCaller caller, @Nullable TransferListener mediaTransferListener)
MediaSourceMediaSource.MediaSourceCaller. Starts source preparation if needed and enables the
source for the creation of MediaPerods.
Should not be called directly from application code.
MediaSource.MediaSourceCaller.onSourceInfoRefreshed(MediaSource, Timeline) will be called once
the source has a Timeline.
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.
prepareSource in interface MediaSourcecaller - The MediaSource.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.public final void enable(MediaSource.MediaSourceCaller caller)
MediaSourceMediaPeriods.
Should not be called directly from application code.
Must only be called after MediaSource.prepareSource(MediaSourceCaller, TransferListener).
enable in interface MediaSourcecaller - The MediaSource.MediaSourceCaller enabling the source.public final void disable(MediaSource.MediaSourceCaller caller)
MediaSourceMediaPeriods. 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 by MediaSource.createPeriod(MediaPeriodId, Allocator, long) have been released by MediaSource.releasePeriod(MediaPeriod).
disable in interface MediaSourcecaller - The MediaSource.MediaSourceCaller disabling the source.public final void releaseSource(MediaSource.MediaSourceCaller caller)
MediaSourceShould not be called directly from application code.
Must only be called if all created MediaPeriods have been released by
MediaSource.releasePeriod(MediaPeriod).
releaseSource in interface MediaSourcecaller - The MediaSource.MediaSourceCaller to be unregistered.