MergingMediaSource


@UnstableApi
class MergingMediaSource : CompositeMediaSource


Merges multiple MediaSources.

The Timelines of the sources being merged must have the same number of periods.

The values of id and id are modified to start with i:, where i is the 0-based index of the MediaSource passed to the constructor that created this or androidx.media3.common.Format.

Summary

Nested types

Thrown when a MergingMediaSource cannot merge its sources.

@Documented
@Retention(value = RetentionPolicy.SOURCE)
@Target(value = TYPE_USE)
@IntDef(value = )
annotation MergingMediaSource.IllegalMergeException.Reason

The reason the merge failed.

Public constructors

Creates a merging media source.

MergingMediaSource(
    adjustPeriodTimeOffsets: Boolean,
    mediaSources: Array<MediaSource!>!
)

Creates a merging media source.

MergingMediaSource(
    adjustPeriodTimeOffsets: Boolean,
    clipDurations: Boolean,
    mediaSources: Array<MediaSource!>!
)

Creates a merging media source.

MergingMediaSource(
    adjustPeriodTimeOffsets: Boolean,
    clipDurations: Boolean,
    compositeSequenceableLoaderFactory: CompositeSequenceableLoaderFactory!,
    mediaSources: Array<MediaSource!>!
)

Creates a merging media source.

Public functions

Boolean

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

MediaPeriod!
createPeriod(
    id: MediaSource.MediaPeriodId!,
    allocator: Allocator!,
    startPositionUs: Long
)

Returns a new MediaPeriod identified by periodId.

MediaItem!

Returns the MediaItem whose media is provided by the source.

Unit

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

Unit
releasePeriod(mediaPeriod: MediaPeriod!)

Releases the period.

Unit

Updates the MediaItem for this source.

Protected functions

MediaSource.MediaPeriodId?
getMediaPeriodIdForChildMediaPeriodId(
    childSourceId: Int!,
    mediaPeriodId: MediaSource.MediaPeriodId!
)

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

Unit
onChildSourceInfoRefreshed(
    childSourceId: Int!,
    mediaSource: MediaSource!,
    newTimeline: Timeline!
)

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

Unit
prepareSourceInternal(mediaTransferListener: TransferListener?)

Starts source preparation and enables the source, see prepareSource.

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.CompositeMediaSource
Unit

Disables a child source.

Unit

Disables the source, see disable.

Unit

Enables a child source.

Unit

Enables the source, see enable.

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.

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

Prepares a child source.

Unit

Releases a child source.

From androidx.media3.exoplayer.source.MediaSource
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.

Boolean

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

Public constructors

MergingMediaSource

MergingMediaSource(mediaSources: Array<MediaSource!>!)

Creates a merging media source.

Neither offsets between the timestamps in the media sources nor the durations of the media sources will be adjusted.

Parameters
mediaSources: Array<MediaSource!>!

The MediaSources to merge.

MergingMediaSource

MergingMediaSource(
    adjustPeriodTimeOffsets: Boolean,
    mediaSources: Array<MediaSource!>!
)

Creates a merging media source.

Durations of the media sources will not be adjusted.

Parameters
adjustPeriodTimeOffsets: Boolean

Whether to adjust timestamps of the merged media sources to all start at the same time.

mediaSources: Array<MediaSource!>!

The MediaSources to merge.

MergingMediaSource

MergingMediaSource(
    adjustPeriodTimeOffsets: Boolean,
    clipDurations: Boolean,
    mediaSources: Array<MediaSource!>!
)

Creates a merging media source.

Parameters
adjustPeriodTimeOffsets: Boolean

Whether to adjust timestamps of the merged media sources to all start at the same time.

clipDurations: Boolean

Whether to clip the durations of the media sources to match the shortest duration.

mediaSources: Array<MediaSource!>!

The MediaSources to merge.

MergingMediaSource

MergingMediaSource(
    adjustPeriodTimeOffsets: Boolean,
    clipDurations: Boolean,
    compositeSequenceableLoaderFactory: CompositeSequenceableLoaderFactory!,
    mediaSources: Array<MediaSource!>!
)

Creates a merging media source.

Parameters
adjustPeriodTimeOffsets: Boolean

Whether to adjust timestamps of the merged media sources to all start at the same time.

clipDurations: Boolean

Whether to clip the durations of the media sources to match the shortest duration.

compositeSequenceableLoaderFactory: CompositeSequenceableLoaderFactory!

A factory to create composite s for when this media source loads data from multiple streams (video, audio etc...).

mediaSources: Array<MediaSource!>!

The MediaSources to merge.

Public functions

canUpdateMediaItem

fun canUpdateMediaItem(mediaItem: MediaItem!): Boolean

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

Should not be called directly from application code.

This method must be called on the application thread.

Parameters
mediaItem: MediaItem!

The new MediaItem.

Returns
Boolean

Whether the source can be updated using this item.

createPeriod

fun createPeriod(
    id: MediaSource.MediaPeriodId!,
    allocator: Allocator!,
    startPositionUs: Long
): MediaPeriod!

Returns a new MediaPeriod identified by periodId.

Should not be called directly from application code.

This method must be called on the playback thread and only if the source is enabled.

Parameters
id: MediaSource.MediaPeriodId!

The identifier of the period.

allocator: Allocator!

An Allocator from which to obtain media buffer allocations.

startPositionUs: Long

The expected start position, in microseconds.

Returns
MediaPeriod!

A new MediaPeriod.

getMediaItem

fun getMediaItem(): MediaItem!

Returns the MediaItem whose media is provided by the source.

Should not be called directly from application code.

This method must be called on the application thread.

maybeThrowSourceInfoRefreshError

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.

releasePeriod

fun releasePeriod(mediaPeriod: MediaPeriod!): Unit

Releases the period.

Should not be called directly from application code.

This method must be called on the playback thread.

Parameters
mediaPeriod: MediaPeriod!

The period to release.

updateMediaItem

fun updateMediaItem(mediaItem: MediaItem!): Unit

Updates the MediaItem for this source.

Should not be called directly from application code.

This method must be called on the playback thread and only if canUpdateMediaItem returns true for the new MediaItem.

Parameters
mediaItem: MediaItem!

The new MediaItem.

Protected functions

getMediaPeriodIdForChildMediaPeriodId

protected fun getMediaPeriodIdForChildMediaPeriodId(
    childSourceId: Int!,
    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
childSourceId: Int!

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.

onChildSourceInfoRefreshed

protected fun onChildSourceInfoRefreshed(
    childSourceId: Int!,
    mediaSource: MediaSource!,
    newTimeline: Timeline!
): Unit

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

Parameters
childSourceId: Int!

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.

prepareSourceInternal

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.

releaseSourceInternal

protected fun releaseSourceInternal(): Unit

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