CompositeMediaSource


@UnstableApi
public abstract class CompositeMediaSource<T> extends BaseMediaSource

Known direct subclasses
AdsMediaSource

A MediaSource that inserts ads linearly into a provided content media source.

ConcatenatingMediaSource2

Concatenates multiple MediaSources, combining everything in one single .

ConcatenatingMediaSource

This class is deprecated.

Use playlist modification methods like addMediaItem instead.

ImaServerSideAdInsertionMediaSource

MediaSource for IMA server side inserted ad streams.

MergingMediaSource

Merges multiple MediaSources.

WrappingMediaSource

An abstract MediaSource wrapping a single child MediaSource.

Known indirect subclasses
ClippingMediaSource

MediaSource that wraps a source and clips its timeline based on specified start/end positions.

FilteringMediaSource

A MediaSource that filters the available track types.

LoopingMediaSource

This class is deprecated.

To loop a MediaSource indefinitely, use setRepeatMode instead of this class.

MaskingMediaSource

A MediaSource that masks the Timeline with a placeholder until the actual media structure is known.

PreloadMediaSource

Preloads a MediaSource and provides a MediaPeriod that has data loaded before playback.


Composite MediaSource consisting of multiple child sources.

Parameters
<T>

The type of the id used to identify prepared child sources.

Summary

Protected constructors

Creates composite media source without child sources.

Public methods

void

Throws any pending error encountered while loading or refreshing source information.

Protected methods

final void

Disables a child source.

void

Disables the source, see disable.

final void

Enables a child source.

void

Enables the source, see enable.

@Nullable MediaSource.MediaPeriodId
getMediaPeriodIdForChildMediaPeriodId(
    @UnknownNull T childSourceId,
    MediaSource.MediaPeriodId mediaPeriodId
)

Returns the MediaPeriodId in the composite source corresponding to the specified in a child source.

long
getMediaTimeForChildMediaTime(
    @UnknownNull T childSourceId,
    long mediaTimeMs,
    @Nullable MediaSource.MediaPeriodId mediaPeriodId
)

Returns the media time in the MediaPeriod of the composite source corresponding to the specified media time in the MediaPeriod of the child source.

int
getWindowIndexForChildWindowIndex(
    @UnknownNull T childSourceId,
    int windowIndex
)

Returns the window index in the composite source corresponding to the specified window index in a child source.

abstract void
onChildSourceInfoRefreshed(
    @UnknownNull T childSourceId,
    MediaSource mediaSource,
    Timeline newTimeline
)

Called when the source info of a child source has been refreshed.

final void

Prepares a child source.

void

Starts source preparation and enables the source, see prepareSource.

final void

Releases a child source.

void

Releases the source, see releaseSource.

Inherited methods

From androidx.media3.exoplayer.source.BaseMediaSource
final void
@UnstableApi
addDrmEventListener(
    Handler handler,
    DrmSessionEventListener eventListener
)

Adds a DrmSessionEventListener to the list of listeners which are notified of DRM events for this media source.

final void
@UnstableApi
addEventListener(
    Handler handler,
    MediaSourceEventListener eventListener
)

Adds a MediaSourceEventListener to the list of listeners which are notified of media source events.

final DrmSessionEventListener.EventDispatcher

Returns a DrmSessionEventListener.EventDispatcher which dispatches all events to the registered listeners with the specified MediaPeriodId

final DrmSessionEventListener.EventDispatcher
createDrmEventDispatcher(
    int windowIndex,
    @Nullable MediaSource.MediaPeriodId mediaPeriodId
)

Returns a DrmSessionEventListener.EventDispatcher which dispatches all events to the registered listeners with the specified window index and MediaPeriodId.

final MediaSourceEventListener.EventDispatcher

Returns a MediaSourceEventListener.EventDispatcher which dispatches all events to the registered listeners with the specified MediaPeriodId.

final MediaSourceEventListener.EventDispatcher
createEventDispatcher(
    MediaSource.MediaPeriodId mediaPeriodId,
    long mediaTimeOffsetMs
)

This method is deprecated.

Use createEventDispatcher instead.

final MediaSourceEventListener.EventDispatcher
createEventDispatcher(
    int windowIndex,
    @Nullable MediaSource.MediaPeriodId mediaPeriodId
)

Returns a MediaSourceEventListener.EventDispatcher which dispatches all events to the registered listeners with the specified window index and MediaPeriodId.

final MediaSourceEventListener.EventDispatcher
createEventDispatcher(
    int windowIndex,
    @Nullable MediaSource.MediaPeriodId mediaPeriodId,
    long mediaTimeOffsetMs
)

This method is deprecated.

Use createEventDispatcher instead.

final void

Disables the source for the creation of MediaPeriods.

final void

Enables the source for the creation of MediaPeriods.

final PlayerId

Returns the PlayerId of the player using this media source.

final boolean

Returns whether the source is enabled.

final void
@UnstableApi
prepareSource(
    MediaSource.MediaSourceCaller caller,
    @Nullable TransferListener mediaTransferListener
)

This method is deprecated.

Implement prepareSource instead.

final void
@UnstableApi
prepareSource(
    MediaSource.MediaSourceCaller caller,
    @Nullable TransferListener mediaTransferListener,
    PlayerId playerId
)

Registers a MediaSourceCaller.

final boolean

Returns whether the source has prepareSource called.

final void

Updates timeline and manifest and notifies all listeners of the update.

final void

Unregisters a caller, and disables and releases the source if no longer required.

final void

Removes a DrmSessionEventListener from the list of listeners which are notified of DRM events for this media source.

final void

Removes a MediaSourceEventListener from the list of listeners which are notified of media source events.

final void

Sets the PlayerId of the player using this media source.

From androidx.media3.exoplayer.source.MediaSource
boolean

Returns whether the MediaItem for this source can be updated with the provided item.

abstract MediaPeriod
@UnstableApi
createPeriod(
    MediaSource.MediaPeriodId id,
    Allocator allocator,
    long startPositionUs
)

Returns a new MediaPeriod identified by periodId.

@Nullable Timeline

Returns the initial placeholder timeline that is returned immediately when the real timeline is not yet known, or null to let the player create an initial timeline.

abstract MediaItem

Returns the MediaItem whose media is provided by the source.

boolean

Returns true if the media source is guaranteed to never have zero or more than one window.

abstract void

Releases the period.

void

Updates the MediaItem for this source.

Protected constructors

CompositeMediaSource

protected CompositeMediaSource()

Creates composite media source without child sources.

Public methods

maybeThrowSourceInfoRefreshError

@CallSuper
public void maybeThrowSourceInfoRefreshError()

Throws any pending error encountered while loading or refreshing source information.

Should not be called directly from application code.

This method must be called on the playback thread and only after prepareSource.

Protected methods

disableChildSource

protected final void disableChildSource(@UnknownNull T id)

Disables a child source.

Parameters
@UnknownNull T id

The unique id used to prepare the child source.

disableInternal

@CallSuper
protected void disableInternal()

Disables the source, see disable.

enableChildSource

protected final void enableChildSource(@UnknownNull T id)

Enables a child source.

Parameters
@UnknownNull T id

The unique id used to prepare the child source.

enableInternal

@CallSuper
protected void enableInternal()

Enables the source, see enable.

getMediaPeriodIdForChildMediaPeriodId

protected @Nullable MediaSource.MediaPeriodId getMediaPeriodIdForChildMediaPeriodId(
    @UnknownNull T childSourceId,
    MediaSource.MediaPeriodId mediaPeriodId
)

Returns the MediaPeriodId in the composite source corresponding to the specified in a child source. The default implementation does not change the media period id.

Parameters
@UnknownNull T childSourceId

The unique id used to prepare the child source.

MediaSource.MediaPeriodId mediaPeriodId

A MediaPeriodId of the child source.

Returns
@Nullable MediaSource.MediaPeriodId

The corresponding MediaPeriodId in the composite source. Null if no corresponding media period id can be determined.

getMediaTimeForChildMediaTime

protected long getMediaTimeForChildMediaTime(
    @UnknownNull T childSourceId,
    long mediaTimeMs,
    @Nullable MediaSource.MediaPeriodId mediaPeriodId
)

Returns the media time in the MediaPeriod of the composite source corresponding to the specified media time in the MediaPeriod of the child source. The default implementation does not change the media time.

Parameters
@UnknownNull T childSourceId

The unique id used to prepare the child source.

long mediaTimeMs

A media time in the MediaPeriod of the child source, in milliseconds.

@Nullable MediaSource.MediaPeriodId mediaPeriodId

The MediaPeriodId of the MediaPeriod of the child source, or null if the time does not relate to a specific MediaPeriod.

Returns
long

The corresponding media time in the MediaPeriod of the composite source, in milliseconds.

getWindowIndexForChildWindowIndex

protected int getWindowIndexForChildWindowIndex(
    @UnknownNull T childSourceId,
    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
@UnknownNull T childSourceId

The unique id used to prepare the child source.

int windowIndex

A window index of the child source.

Returns
int

The corresponding window index in the composite source.

onChildSourceInfoRefreshed

protected abstract void onChildSourceInfoRefreshed(
    @UnknownNull T childSourceId,
    MediaSource mediaSource,
    Timeline newTimeline
)

Called when the source info of a child source has been refreshed.

Parameters
@UnknownNull T childSourceId

The unique id used to prepare the child source.

MediaSource mediaSource

The child source whose source info has been refreshed.

Timeline newTimeline

The timeline of the child source.

prepareChildSource

protected final void prepareChildSource(@UnknownNull T id, MediaSource mediaSource)

Prepares a child source.

onChildSourceInfoRefreshed will be called when the child source updates its timeline with the same id passed to this method.

Any child sources that aren't explicitly released with releaseChildSource will be released in releaseSourceInternal.

Parameters
@UnknownNull T id

A unique id to identify the child source preparation. Null is allowed as an id.

MediaSource mediaSource

The child MediaSource.

prepareSourceInternal

@CallSuper
protected void prepareSourceInternal(@Nullable TransferListener mediaTransferListener)

Starts source preparation and enables the source, see prepareSource. This method is called at most once until the next call to releaseSourceInternal.

Parameters
@Nullable TransferListener 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.

releaseChildSource

protected final void releaseChildSource(@UnknownNull T id)

Releases a child source.

Parameters
@UnknownNull T id

The unique id used to prepare the child source.

releaseSourceInternal

@CallSuper
protected void releaseSourceInternal()

Releases the source, see releaseSource. This method is called exactly once after each call to prepareSourceInternal.