ConcatenatingMediaSource


@UnstableApi
class ConcatenatingMediaSource : CompositeMediaSource


Concatenates multiple MediaSource instances. The list of MediaSource instances can be modified during playback. It is valid for the same MediaSource instance to be present more than once in the concatenation. Access to this class is thread-safe.

Summary

Public constructors

ConcatenatingMediaSource(
    isAtomic: Boolean,
    mediaSources: Array<MediaSource!>!
)
ConcatenatingMediaSource(
    isAtomic: Boolean,
    shuffleOrder: ShuffleOrder!,
    mediaSources: Array<MediaSource!>!
)
ConcatenatingMediaSource(
    isAtomic: Boolean,
    useLazyPreparation: Boolean,
    shuffleOrder: ShuffleOrder!,
    mediaSources: Array<MediaSource!>!
)

Public functions

synchronized Unit
addMediaSource(mediaSource: MediaSource!)

Appends a MediaSource to the playlist.

synchronized Unit
addMediaSource(index: Int, mediaSource: MediaSource!)

Adds a MediaSource to the playlist.

synchronized Unit
addMediaSource(
    mediaSource: MediaSource!,
    handler: Handler!,
    onCompletionAction: Runnable!
)

Appends a MediaSource to the playlist and executes a custom action on completion.

synchronized Unit
addMediaSource(
    index: Int,
    mediaSource: MediaSource!,
    handler: Handler!,
    onCompletionAction: Runnable!
)

Adds a MediaSource to the playlist and executes a custom action on completion.

synchronized Unit

Appends multiple MediaSources to the playlist.

synchronized Unit
addMediaSources(
    index: Int,
    mediaSources: (Mutable)Collection<MediaSource!>!
)

Adds multiple MediaSources to the playlist.

synchronized Unit
addMediaSources(
    mediaSources: (Mutable)Collection<MediaSource!>!,
    handler: Handler!,
    onCompletionAction: Runnable!
)

Appends multiple MediaSources to the playlist and executes a custom action on completion.

synchronized Unit
addMediaSources(
    index: Int,
    mediaSources: (Mutable)Collection<MediaSource!>!,
    handler: Handler!,
    onCompletionAction: Runnable!
)

Adds multiple MediaSources to the playlist and executes a custom action on completion.

synchronized Unit

Clears the playlist.

synchronized Unit
clear(handler: Handler!, onCompletionAction: Runnable!)

Clears the playlist and executes a custom action on completion.

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

Returns a new MediaPeriod identified by periodId.

synchronized 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.

MediaItem!

Returns the MediaItem whose media is provided by the source.

synchronized MediaSource!

Returns the MediaSource at a specified index.

synchronized Int

Returns the number of media sources in the playlist.

Boolean

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

synchronized Unit
moveMediaSource(currentIndex: Int, newIndex: Int)

Moves an existing MediaSource within the playlist.

synchronized Unit
moveMediaSource(
    currentIndex: Int,
    newIndex: Int,
    handler: Handler!,
    onCompletionAction: Runnable!
)

Moves an existing MediaSource within the playlist and executes a custom action on completion.

Unit
releasePeriod(mediaPeriod: MediaPeriod!)

Releases the period.

synchronized MediaSource!

Removes a MediaSource from the playlist.

synchronized MediaSource!
removeMediaSource(
    index: Int,
    handler: Handler!,
    onCompletionAction: Runnable!
)

Removes a MediaSource from the playlist and executes a custom action on completion.

synchronized Unit
removeMediaSourceRange(fromIndex: Int, toIndex: Int)

Removes a range of MediaSources from the playlist, by specifying an initial index (included) and a final index (excluded).

synchronized Unit
removeMediaSourceRange(
    fromIndex: Int,
    toIndex: Int,
    handler: Handler!,
    onCompletionAction: Runnable!
)

Removes a range of MediaSources from the playlist, by specifying an initial index (included) and a final index (excluded), and executes a custom action on completion.

synchronized Unit
setShuffleOrder(shuffleOrder: ShuffleOrder!)

Sets a new shuffle order to use when shuffling the child media sources.

synchronized Unit
setShuffleOrder(
    shuffleOrder: ShuffleOrder!,
    handler: Handler!,
    onCompletionAction: Runnable!
)

Sets a new shuffle order to use when shuffling the child media sources.

Protected functions

Unit

Disables the source, see disable.

Unit

Enables the source, see enable.

synchronized Unit
prepareSourceInternal(mediaTransferListener: TransferListener?)

Starts source preparation and enables the source, see prepareSource.

synchronized 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

Enables 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.

Unit

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

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

Prepares a child source.

Unit

Releases a child source.

From androidx.media3.exoplayer.source.MediaSource
Boolean

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

Unit

Updates the MediaItem for this source.

Public constructors

ConcatenatingMediaSource

ConcatenatingMediaSource(mediaSources: Array<MediaSource!>!)
Parameters
mediaSources: Array<MediaSource!>!

The MediaSources to concatenate. It is valid for the same instance to be present more than once in the array.

ConcatenatingMediaSource

ConcatenatingMediaSource(
    isAtomic: Boolean,
    mediaSources: Array<MediaSource!>!
)
Parameters
isAtomic: Boolean

Whether the concatenating media source will be treated as atomic, i.e., treated as a single item for repeating and shuffling.

mediaSources: Array<MediaSource!>!

The MediaSources to concatenate. It is valid for the same instance to be present more than once in the array.

ConcatenatingMediaSource

ConcatenatingMediaSource(
    isAtomic: Boolean,
    shuffleOrder: ShuffleOrder!,
    mediaSources: Array<MediaSource!>!
)
Parameters
isAtomic: Boolean

Whether the concatenating media source will be treated as atomic, i.e., treated as a single item for repeating and shuffling.

shuffleOrder: ShuffleOrder!

The ShuffleOrder to use when shuffling the child media sources.

mediaSources: Array<MediaSource!>!

The MediaSources to concatenate. It is valid for the same instance to be present more than once in the array.

ConcatenatingMediaSource

ConcatenatingMediaSource(
    isAtomic: Boolean,
    useLazyPreparation: Boolean,
    shuffleOrder: ShuffleOrder!,
    mediaSources: Array<MediaSource!>!
)
Parameters
isAtomic: Boolean

Whether the concatenating media source will be treated as atomic, i.e., treated as a single item for repeating and shuffling.

useLazyPreparation: Boolean

Whether playlist items are prepared lazily. If false, all manifest loads and other initial preparation steps happen immediately. If true, these initial preparations are triggered only when the player starts buffering the media.

shuffleOrder: ShuffleOrder!

The ShuffleOrder to use when shuffling the child media sources.

mediaSources: Array<MediaSource!>!

The MediaSources to concatenate. It is valid for the same instance to be present more than once in the array.

Public functions

addMediaSource

synchronized fun addMediaSource(mediaSource: MediaSource!): Unit

Appends a MediaSource to the playlist.

Parameters
mediaSource: MediaSource!

The MediaSource to be added to the list.

addMediaSource

synchronized fun addMediaSource(index: Int, mediaSource: MediaSource!): Unit

Adds a MediaSource to the playlist.

Parameters
index: Int

The index at which the new MediaSource will be inserted. This index must be in the range of 0 <= index <= getSize.

mediaSource: MediaSource!

The MediaSource to be added to the list.

addMediaSource

synchronized fun addMediaSource(
    mediaSource: MediaSource!,
    handler: Handler!,
    onCompletionAction: Runnable!
): Unit

Appends a MediaSource to the playlist and executes a custom action on completion.

Parameters
mediaSource: MediaSource!

The MediaSource to be added to the list.

handler: Handler!

The Handler to run onCompletionAction.

onCompletionAction: Runnable!

A Runnable which is executed immediately after the media source has been added to the playlist.

addMediaSource

synchronized fun addMediaSource(
    index: Int,
    mediaSource: MediaSource!,
    handler: Handler!,
    onCompletionAction: Runnable!
): Unit

Adds a MediaSource to the playlist and executes a custom action on completion.

Parameters
index: Int

The index at which the new MediaSource will be inserted. This index must be in the range of 0 <= index <= getSize.

mediaSource: MediaSource!

The MediaSource to be added to the list.

handler: Handler!

The Handler to run onCompletionAction.

onCompletionAction: Runnable!

A Runnable which is executed immediately after the media source has been added to the playlist.

addMediaSources

synchronized fun addMediaSources(mediaSources: (Mutable)Collection<MediaSource!>!): Unit

Appends multiple MediaSources to the playlist.

Parameters
mediaSources: (Mutable)Collection<MediaSource!>!

A collection of MediaSources to be added to the list. The media sources are added in the order in which they appear in this collection.

addMediaSources

synchronized fun addMediaSources(
    index: Int,
    mediaSources: (Mutable)Collection<MediaSource!>!
): Unit

Adds multiple MediaSources to the playlist.

Parameters
index: Int

The index at which the new MediaSources will be inserted. This index must be in the range of 0 <= index <= getSize.

mediaSources: (Mutable)Collection<MediaSource!>!

A collection of MediaSources to be added to the list. The media sources are added in the order in which they appear in this collection.

addMediaSources

synchronized fun addMediaSources(
    mediaSources: (Mutable)Collection<MediaSource!>!,
    handler: Handler!,
    onCompletionAction: Runnable!
): Unit

Appends multiple MediaSources to the playlist and executes a custom action on completion.

Parameters
mediaSources: (Mutable)Collection<MediaSource!>!

A collection of MediaSources to be added to the list. The media sources are added in the order in which they appear in this collection.

handler: Handler!

The Handler to run onCompletionAction.

onCompletionAction: Runnable!

A Runnable which is executed immediately after the media sources have been added to the playlist.

addMediaSources

synchronized fun addMediaSources(
    index: Int,
    mediaSources: (Mutable)Collection<MediaSource!>!,
    handler: Handler!,
    onCompletionAction: Runnable!
): Unit

Adds multiple MediaSources to the playlist and executes a custom action on completion.

Parameters
index: Int

The index at which the new MediaSources will be inserted. This index must be in the range of 0 <= index <= getSize.

mediaSources: (Mutable)Collection<MediaSource!>!

A collection of MediaSources to be added to the list. The media sources are added in the order in which they appear in this collection.

handler: Handler!

The Handler to run onCompletionAction.

onCompletionAction: Runnable!

A Runnable which is executed immediately after the media sources have been added to the playlist.

clear

synchronized fun clear(): Unit

Clears the playlist.

clear

synchronized fun clear(handler: Handler!, onCompletionAction: Runnable!): Unit

Clears the playlist and executes a custom action on completion.

Parameters
handler: Handler!

The Handler to run onCompletionAction.

onCompletionAction: Runnable!

A Runnable which is executed immediately after the playlist has been cleared.

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.

getInitialTimeline

synchronized fun getInitialTimeline(): 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.

Should not be called directly from application code.

The initial timeline must use the same uids for windows and periods that the real timeline will use. It also must provide windows which are marked as dynamic to indicate that the window is expected to change when the real timeline arrives.

Any media source which has multiple windows should typically provide such an initial timeline to make sure the player reports the correct number of windows immediately.

This method must be called on the application thread.

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.

getMediaSource

synchronized fun getMediaSource(index: Int): MediaSource!

Returns the MediaSource at a specified index.

Parameters
index: Int

An index in the range of 0 <= index <= getSize.

Returns
MediaSource!

The MediaSource at this index.

getSize

synchronized fun getSize(): Int

Returns the number of media sources in the playlist.

isSingleWindow

fun isSingleWindow(): Boolean

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

Should not be called directly from application code.

The default implementation returns true.

This method must be called on the application thread.

Returns
Boolean

true if the source has exactly one window.

moveMediaSource

synchronized fun moveMediaSource(currentIndex: Int, newIndex: Int): Unit

Moves an existing MediaSource within the playlist.

Parameters
currentIndex: Int

The current index of the media source in the playlist. This index must be in the range of 0 <= index <getSize.

newIndex: Int

The target index of the media source in the playlist. This index must be in the range of 0 <= index <getSize.

moveMediaSource

synchronized fun moveMediaSource(
    currentIndex: Int,
    newIndex: Int,
    handler: Handler!,
    onCompletionAction: Runnable!
): Unit

Moves an existing MediaSource within the playlist and executes a custom action on completion.

Parameters
currentIndex: Int

The current index of the media source in the playlist. This index must be in the range of 0 <= index <getSize.

newIndex: Int

The target index of the media source in the playlist. This index must be in the range of 0 <= index <getSize.

handler: Handler!

The Handler to run onCompletionAction.

onCompletionAction: Runnable!

A Runnable which is executed immediately after the media source has been moved.

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.

removeMediaSource

synchronized fun removeMediaSource(index: Int): MediaSource!

Removes a MediaSource from the playlist.

Note: If you want to move the instance, it's preferable to use moveMediaSource instead.

Note: If you want to remove a set of contiguous sources, it's preferable to use removeMediaSourceRange instead.

Parameters
index: Int

The index at which the media source will be removed. This index must be in the range of 0 <= index <getSize.

Returns
MediaSource!

The removed MediaSource.

removeMediaSource

synchronized fun removeMediaSource(
    index: Int,
    handler: Handler!,
    onCompletionAction: Runnable!
): MediaSource!

Removes a MediaSource from the playlist and executes a custom action on completion.

Note: If you want to move the instance, it's preferable to use moveMediaSource instead.

Note: If you want to remove a set of contiguous sources, it's preferable to use removeMediaSourceRange instead.

Parameters
index: Int

The index at which the media source will be removed. This index must be in the range of 0 <= index <getSize.

handler: Handler!

The Handler to run onCompletionAction.

onCompletionAction: Runnable!

A Runnable which is executed immediately after the media source has been removed from the playlist.

Returns
MediaSource!

The removed MediaSource.

removeMediaSourceRange

synchronized fun removeMediaSourceRange(fromIndex: Int, toIndex: Int): Unit

Removes a range of MediaSources from the playlist, by specifying an initial index (included) and a final index (excluded).

Note: when specified range is empty, no actual media source is removed and no exception is thrown.

Parameters
fromIndex: Int

The initial range index, pointing to the first media source that will be removed. This index must be in the range of 0 <= index <= getSize.

toIndex: Int

The final range index, pointing to the first media source that will be left untouched. This index must be in the range of 0 <= index <= getSize.

Throws
java.lang.IndexOutOfBoundsException

When the range is malformed, i.e. fromIndex<0, toIndex>getSize, fromIndex>toIndex

removeMediaSourceRange

synchronized fun removeMediaSourceRange(
    fromIndex: Int,
    toIndex: Int,
    handler: Handler!,
    onCompletionAction: Runnable!
): Unit

Removes a range of MediaSources from the playlist, by specifying an initial index (included) and a final index (excluded), and executes a custom action on completion.

Note: when specified range is empty, no actual media source is removed and no exception is thrown.

Parameters
fromIndex: Int

The initial range index, pointing to the first media source that will be removed. This index must be in the range of 0 <= index <= getSize.

toIndex: Int

The final range index, pointing to the first media source that will be left untouched. This index must be in the range of 0 <= index <= getSize.

handler: Handler!

The Handler to run onCompletionAction.

onCompletionAction: Runnable!

A Runnable which is executed immediately after the media source range has been removed from the playlist.

Throws
java.lang.IllegalArgumentException

When the range is malformed, i.e. fromIndex<0, toIndex>getSize, fromIndex>toIndex

setShuffleOrder

synchronized fun setShuffleOrder(shuffleOrder: ShuffleOrder!): Unit

Sets a new shuffle order to use when shuffling the child media sources.

Parameters
shuffleOrder: ShuffleOrder!

A ShuffleOrder.

setShuffleOrder

synchronized fun setShuffleOrder(
    shuffleOrder: ShuffleOrder!,
    handler: Handler!,
    onCompletionAction: Runnable!
): Unit

Sets a new shuffle order to use when shuffling the child media sources.

Parameters
shuffleOrder: ShuffleOrder!

A ShuffleOrder.

handler: Handler!

The Handler to run onCompletionAction.

onCompletionAction: Runnable!

A Runnable which is executed immediately after the shuffle order has been changed.

Protected functions

disableInternal

protected fun disableInternal(): Unit

Disables the source, see disable.

enableInternal

protected fun enableInternal(): Unit

Enables the source, see enable.

prepareSourceInternal

synchronized 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

synchronized protected fun releaseSourceInternal(): Unit

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