public abstract class BaseMediaSource extends Object implements MediaSource
MediaSource
implementation to handle parallel reuse and to keep a list of MediaSourceEventListener
s.
Whenever an implementing subclass needs to provide a new timeline and/or manifest, it must
call refreshSourceInfo(Timeline, Object)
to notify all listeners.
MediaSource.MediaPeriodId, MediaSource.SourceInfoRefreshListener
Constructor and Description |
---|
BaseMediaSource() |
Modifier and Type | Method and Description |
---|---|
void |
addEventListener(Handler handler,
MediaSourceEventListener eventListener)
Adds a
MediaSourceEventListener to the list of listeners which are notified of media
source events. |
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 |
prepareSource(ExoPlayer player,
boolean isTopLevelSource,
MediaSource.SourceInfoRefreshListener listener) |
void |
prepareSource(ExoPlayer player,
boolean isTopLevelSource,
MediaSource.SourceInfoRefreshListener listener,
TransferListener mediaTransferListener)
Starts source preparation if not yet started, and adds a listener for timeline and/or manifest
updates.
|
protected abstract void |
prepareSourceInternal(ExoPlayer player,
boolean isTopLevelSource,
TransferListener mediaTransferListener)
Starts source preparation.
|
protected void |
refreshSourceInfo(Timeline timeline,
Object manifest)
Updates timeline and manifest and notifies all listeners of the update.
|
void |
releaseSource(MediaSource.SourceInfoRefreshListener listener)
Removes a listener for timeline and/or manifest updates and releases the source if no longer
required.
|
protected abstract void |
releaseSourceInternal()
Releases the source.
|
void |
removeEventListener(MediaSourceEventListener eventListener)
Removes a
MediaSourceEventListener from the list of listeners which are notified of
media source events. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
createPeriod, getTag, maybeThrowSourceInfoRefreshError, releasePeriod
protected abstract void prepareSourceInternal(ExoPlayer player, boolean isTopLevelSource, @Nullable TransferListener mediaTransferListener)
releaseSourceInternal()
.player
- The player for which this source is being prepared.isTopLevelSource
- Whether this source has been passed directly to ExoPlayer.prepare(MediaSource)
or ExoPlayer.prepare(MediaSource, boolean,
boolean)
.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 abstract void releaseSourceInternal()
prepareSourceInternal(ExoPlayer, boolean, TransferListener)
.protected final void refreshSourceInfo(Timeline timeline, @Nullable Object manifest)
timeline
- The new Timeline
.manifest
- The new manifest. May be null.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 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 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 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.public final void addEventListener(Handler handler, MediaSourceEventListener eventListener)
MediaSource
MediaSourceEventListener
to the list of listeners which are notified of media
source events.addEventListener
in interface MediaSource
handler
- A handler on the which listener events will be posted.eventListener
- The listener to be added.public final void removeEventListener(MediaSourceEventListener eventListener)
MediaSource
MediaSourceEventListener
from the list of listeners which are notified of
media source events.removeEventListener
in interface MediaSource
eventListener
- The listener to be removed.public final void prepareSource(ExoPlayer player, boolean isTopLevelSource, MediaSource.SourceInfoRefreshListener listener)
prepareSource
in interface MediaSource
public final void prepareSource(ExoPlayer player, boolean isTopLevelSource, MediaSource.SourceInfoRefreshListener listener, @Nullable TransferListener mediaTransferListener)
MediaSource
Should not be called directly from application code.
The listener will be also be notified if the source already has a timeline and/or manifest.
For each call to this method, a call to MediaSource.releaseSource(SourceInfoRefreshListener)
is
needed to remove the listener and to release the source if no longer required.
prepareSource
in interface MediaSource
player
- The player for which this source is being prepared.isTopLevelSource
- Whether this source has been passed directly to ExoPlayer.prepare(MediaSource)
or ExoPlayer.prepare(MediaSource, boolean,
boolean)
. If false
, this source is being prepared by another source (e.g. ConcatenatingMediaSource
) for composition.listener
- The listener to be added.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 releaseSource(MediaSource.SourceInfoRefreshListener listener)
MediaSource
Should not be called directly from application code.
releaseSource
in interface MediaSource
listener
- The listener to be removed.