CompositeMediaSource


@UnstableApi
abstract class CompositeMediaSource<T> : 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 functions

Unit

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

Protected functions

Unit

Disables a child source.

Unit

Disables the source, see disable.

Unit

Enables a child source.

Unit

Enables the source, see enable.

MediaSource.MediaPeriodId?
getMediaPeriodIdForChildMediaPeriodId(
    @UnknownNull childSourceId: T!,
    mediaPeriodId: MediaSource.MediaPeriodId!
)

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

Long
getMediaTimeForChildMediaTime(
    @UnknownNull childSourceId: T!,
    mediaTimeMs: Long,
    mediaPeriodId: MediaSource.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 childSourceId: T!,
    windowIndex: Int
)

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

abstract Unit
onChildSourceInfoRefreshed(
    @UnknownNull childSourceId: T!,
    mediaSource: MediaSource!,
    newTimeline: Timeline!
)

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

Unit
prepareChildSource(@UnknownNull id: T!, mediaSource: MediaSource!)

Prepares a child source.

Unit

Starts source preparation and enables the source, see prepareSource.

Unit

Releases a child source.

Unit

Releases the source, see releaseSource.

Inherited functions

From androidx.media3.exoplayer.source.BaseMediaSource
Unit
@UnstableApi
addDrmEventListener(
    handler: Handler!,
    eventListener: DrmSessionEventListener!
)

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

Unit
@UnstableApi
addEventListener(
    handler: Handler!,
    eventListener: MediaSourceEventListener!
)

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

DrmSessionEventListener.EventDispatcher!

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

DrmSessionEventListener.EventDispatcher!
createDrmEventDispatcher(
    windowIndex: Int,
    mediaPeriodId: MediaSource.MediaPeriodId?
)

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

MediaSourceEventListener.EventDispatcher!

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

MediaSourceEventListener.EventDispatcher!
createEventDispatcher(
    mediaPeriodId: MediaSource.MediaPeriodId!,
    mediaTimeOffsetMs: Long
)

This function is deprecated.

Use createEventDispatcher instead.

MediaSourceEventListener.EventDispatcher!
createEventDispatcher(
    windowIndex: Int,
    mediaPeriodId: MediaSource.MediaPeriodId?
)

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

MediaSourceEventListener.EventDispatcher!
createEventDispatcher(
    windowIndex: Int,
    mediaPeriodId: MediaSource.MediaPeriodId?,
    mediaTimeOffsetMs: Long
)

This function is deprecated.

Use createEventDispatcher instead.

Unit

Disables the source for the creation of MediaPeriods.

Unit

Enables the source for the creation of MediaPeriods.

Boolean

Returns whether the source is enabled.

Unit
@UnstableApi
prepareSource(
    caller: MediaSource.MediaSourceCaller!,
    mediaTransferListener: TransferListener?
)

This function is deprecated.

Implement prepareSource instead.

Unit
@UnstableApi
prepareSource(
    caller: MediaSource.MediaSourceCaller!,
    mediaTransferListener: TransferListener?,
    playerId: PlayerId!
)

Registers a MediaSourceCaller.

Boolean

Returns whether the source has prepareSource called.

Unit

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

Unit

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

Unit

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

Unit

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

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(
    id: MediaSource.MediaPeriodId!,
    allocator: Allocator!,
    startPositionUs: Long
)

Returns a new MediaPeriod identified by periodId.

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 Unit

Releases the period.

Unit

Updates the MediaItem for this source.

Protected constructors

CompositeMediaSource

protected CompositeMediaSource()

Creates composite media source without child sources.

Public functions

maybeThrowSourceInfoRefreshError

@CallSuper
fun maybeThrowSourceInfoRefreshError(): Unit

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 functions

disableChildSource

protected fun disableChildSource(@UnknownNull id: T!): Unit

Disables a child source.

Parameters
@UnknownNull id: T!

The unique id used to prepare the child source.

disableInternal

@CallSuper
protected fun disableInternal(): Unit

Disables the source, see disable.

enableChildSource

protected fun enableChildSource(@UnknownNull id: T!): Unit

Enables a child source.

Parameters
@UnknownNull id: T!

The unique id used to prepare the child source.

enableInternal

@CallSuper
protected fun enableInternal(): Unit

Enables the source, see enable.

getMediaPeriodIdForChildMediaPeriodId

protected fun getMediaPeriodIdForChildMediaPeriodId(
    @UnknownNull childSourceId: T!,
    mediaPeriodId: MediaSource.MediaPeriodId!
): MediaSource.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 childSourceId: T!

The unique id used to prepare the child source.

mediaPeriodId: MediaSource.MediaPeriodId!

A MediaPeriodId of the child source.

Returns
MediaSource.MediaPeriodId?

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

getMediaTimeForChildMediaTime

protected fun getMediaTimeForChildMediaTime(
    @UnknownNull childSourceId: T!,
    mediaTimeMs: Long,
    mediaPeriodId: MediaSource.MediaPeriodId?
): Long

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 childSourceId: T!

The unique id used to prepare the child source.

mediaTimeMs: Long

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

mediaPeriodId: MediaSource.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 fun getWindowIndexForChildWindowIndex(
    @UnknownNull childSourceId: T!,
    windowIndex: Int
): Int

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 childSourceId: T!

The unique id used to prepare the child source.

windowIndex: Int

A window index of the child source.

Returns
Int

The corresponding window index in the composite source.

onChildSourceInfoRefreshed

protected abstract fun onChildSourceInfoRefreshed(
    @UnknownNull childSourceId: T!,
    mediaSource: MediaSource!,
    newTimeline: Timeline!
): Unit

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

Parameters
@UnknownNull childSourceId: T!

The unique id used to prepare the child source.

mediaSource: MediaSource!

The child source whose source info has been refreshed.

newTimeline: Timeline!

The timeline of the child source.

prepareChildSource

protected fun prepareChildSource(@UnknownNull id: T!, mediaSource: MediaSource!): Unit

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 id: T!

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

mediaSource: MediaSource!

The child MediaSource.

prepareSourceInternal

@CallSuper
protected fun prepareSourceInternal(mediaTransferListener: TransferListener?): Unit

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

Parameters
mediaTransferListener: TransferListener?

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 fun releaseChildSource(@UnknownNull id: T!): Unit

Releases a child source.

Parameters
@UnknownNull id: T!

The unique id used to prepare the child source.

releaseSourceInternal

@CallSuper
protected fun releaseSourceInternal(): Unit

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