Class CompositeMediaSource<T>
- java.lang.Object
-
- com.google.android.exoplayer2.source.BaseMediaSource
-
- com.google.android.exoplayer2.source.CompositeMediaSource<T>
-
- Type Parameters:
T
- The type of the id used to identify prepared child sources.
- All Implemented Interfaces:
MediaSource
- Direct Known Subclasses:
AdsMediaSource
,ClippingMediaSource
,ConcatenatingMediaSource
,ImaServerSideAdInsertionMediaSource
,LoopingMediaSource
,MaskingMediaSource
,MergingMediaSource
public abstract class CompositeMediaSource<T> extends BaseMediaSource
CompositeMediaSource
consisting of multiple child sources.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.google.android.exoplayer2.source.MediaSource
MediaSource.Factory, MediaSource.MediaPeriodId, MediaSource.MediaSourceCaller
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
CompositeMediaSource()
Creates composite media source without child sources.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
disableChildSource(T id)
Disables a child source.protected void
disableInternal()
Disables the source, seeBaseMediaSource.disable(MediaSourceCaller)
.protected void
enableChildSource(T id)
Enables a child source.protected void
enableInternal()
Enables the source, seeBaseMediaSource.enable(MediaSourceCaller)
.protected MediaSource.MediaPeriodId
getMediaPeriodIdForChildMediaPeriodId(T id, MediaSource.MediaPeriodId mediaPeriodId)
Returns theMediaSource.MediaPeriodId
in the composite source corresponding to the specifiedMediaSource.MediaPeriodId
in a child source.protected long
getMediaTimeForChildMediaTime(T id, long mediaTimeMs)
Returns the media time in theMediaPeriod
of the composite source corresponding to the specified media time in theMediaPeriod
of the child source.protected int
getWindowIndexForChildWindowIndex(T id, int windowIndex)
Returns the window index in the composite source corresponding to the specified window index in a child source.void
maybeThrowSourceInfoRefreshError()
Throws any pending error encountered while loading or refreshing source information.protected abstract void
onChildSourceInfoRefreshed(T id, MediaSource mediaSource, Timeline timeline)
Called when the source info of a child source has been refreshed.protected void
prepareChildSource(T id, MediaSource mediaSource)
Prepares a child source.protected void
prepareSourceInternal(TransferListener mediaTransferListener)
Starts source preparation and enables the source, seeBaseMediaSource.prepareSource(MediaSourceCaller, TransferListener, PlayerId)
.protected void
releaseChildSource(T id)
Releases a child source.protected void
releaseSourceInternal()
Releases the source, seeBaseMediaSource.releaseSource(MediaSourceCaller)
.-
Methods inherited from class com.google.android.exoplayer2.source.BaseMediaSource
addDrmEventListener, addEventListener, createDrmEventDispatcher, createDrmEventDispatcher, createEventDispatcher, createEventDispatcher, createEventDispatcher, disable, enable, getPlayerId, isEnabled, 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.source.MediaSource
createPeriod, getInitialTimeline, getMediaItem, isSingleWindow, prepareSource, releasePeriod
-
-
-
-
Method Detail
-
prepareSourceInternal
@CallSuper protected void prepareSourceInternal(@Nullable TransferListener mediaTransferListener)
Description copied from class:BaseMediaSource
Starts 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:
prepareSourceInternal
in 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
@CallSuper public void maybeThrowSourceInfoRefreshError() throws IOException
Description copied from interface:MediaSource
Throws any pending error encountered while loading or refreshing source information.Should not be called directly from application code.
Must only be called after
MediaSource.prepareSource(MediaSourceCaller, TransferListener, PlayerId)
.- Throws:
IOException
-
enableInternal
@CallSuper protected void enableInternal()
Description copied from class:BaseMediaSource
Enables the source, seeBaseMediaSource.enable(MediaSourceCaller)
.- Overrides:
enableInternal
in classBaseMediaSource
-
disableInternal
@CallSuper protected void disableInternal()
Description copied from class:BaseMediaSource
Disables the source, seeBaseMediaSource.disable(MediaSourceCaller)
.- Overrides:
disableInternal
in classBaseMediaSource
-
releaseSourceInternal
@CallSuper protected void releaseSourceInternal()
Description copied from class:BaseMediaSource
Releases the source, seeBaseMediaSource.releaseSource(MediaSourceCaller)
. This method is called exactly once after each call toBaseMediaSource.prepareSourceInternal(TransferListener)
.- Specified by:
releaseSourceInternal
in classBaseMediaSource
-
onChildSourceInfoRefreshed
protected abstract void onChildSourceInfoRefreshed(T id, MediaSource mediaSource, Timeline timeline)
Called when the source info of a child source has been refreshed.- Parameters:
id
- The unique id used to prepare the child source.mediaSource
- The child source whose source info has been refreshed.timeline
- The timeline of the child source.
-
prepareChildSource
protected final void prepareChildSource(T id, MediaSource mediaSource)
Prepares a child source.onChildSourceInfoRefreshed(Object, MediaSource, Timeline)
will be called when the child source updates its timeline with the sameid
passed to this method.Any child sources that aren't explicitly released with
releaseChildSource(Object)
will be released inreleaseSourceInternal()
.- Parameters:
id
- A unique id to identify the child source preparation. Null is allowed as an id.mediaSource
- The childMediaSource
.
-
enableChildSource
protected final void enableChildSource(T id)
Enables a child source.- Parameters:
id
- The unique id used to prepare the child source.
-
disableChildSource
protected final void disableChildSource(T id)
Disables a child source.- Parameters:
id
- The unique id used to prepare the child source.
-
releaseChildSource
protected final void releaseChildSource(T id)
Releases a child source.- Parameters:
id
- The unique id used to prepare the child source.
-
getWindowIndexForChildWindowIndex
protected int getWindowIndexForChildWindowIndex(T id, int windowIndex)
Returns the window index in the composite source corresponding to the specified window index in a child source. The default implementation does not change the window index.- Parameters:
id
- The unique id used to prepare the child source.windowIndex
- A window index of the child source.- Returns:
- The corresponding window index in the composite source.
-
getMediaPeriodIdForChildMediaPeriodId
@Nullable protected MediaSource.MediaPeriodId getMediaPeriodIdForChildMediaPeriodId(T id, MediaSource.MediaPeriodId mediaPeriodId)
Returns theMediaSource.MediaPeriodId
in the composite source corresponding to the specifiedMediaSource.MediaPeriodId
in a child source. The default implementation does not change the media period id.- Parameters:
id
- The unique id used to prepare the child source.mediaPeriodId
- AMediaSource.MediaPeriodId
of the child source.- Returns:
- The corresponding
MediaSource.MediaPeriodId
in the composite source. Null if no corresponding media period id can be determined.
-
getMediaTimeForChildMediaTime
protected long getMediaTimeForChildMediaTime(T id, long mediaTimeMs)
Returns the media time in theMediaPeriod
of the composite source corresponding to the specified media time in theMediaPeriod
of the child source. The default implementation does not change the media time.- Parameters:
id
- The unique id used to prepare the child source.mediaTimeMs
- A media time in theMediaPeriod
of the child source, in milliseconds.- Returns:
- The corresponding media time in the
MediaPeriod
of the composite source, in milliseconds.
-
-