ConcatenatingMediaSource
@UnstableApi
public final class ConcatenatingMediaSource extends CompositeMediaSource
| java.lang.Object | |||
| ↳ | androidx.media3.exoplayer.source.BaseMediaSource | ||
| ↳ | androidx.media3.exoplayer.source.CompositeMediaSource | ||
| ↳ | androidx.media3.exoplayer.source.ConcatenatingMediaSource |
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 |
|---|
|
|
|
|
Public methods |
|
|---|---|
synchronized void |
Appends a |
synchronized void |
Adds a |
synchronized void |
Appends a |
synchronized void |
Adds a |
synchronized void |
Appends multiple |
synchronized void |
Adds multiple |
synchronized void |
Appends multiple |
synchronized void |
Adds multiple |
synchronized void |
Clears the playlist. |
synchronized void |
Clears the playlist and executes a custom action on completion. |
MediaPeriod |
Returns a new |
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 |
synchronized MediaSource |
Returns the |
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 void |
Moves an existing |
synchronized void |
Moves an existing |
void |
Releases the period. |
synchronized MediaSource |
Removes a |
synchronized MediaSource |
Removes a |
synchronized void |
Removes a range of |
synchronized void |
Removes a range of |
synchronized void |
Sets a new shuffle order to use when shuffling the child media sources. |
synchronized void |
Sets a new shuffle order to use when shuffling the child media sources. |
Protected methods |
|
|---|---|
void |
Disables the source, see |
void |
Enables the source, see |
@Nullable MediaSource.MediaPeriodId |
Returns the |
int |
Returns the window index in the composite source corresponding to the specified window index in a child source. |
void |
Called when the source info of a child source has been refreshed. |
synchronized void |
Starts source preparation and enables the source, see |
synchronized void |
Releases the source, see |
Inherited methods |
||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
|
Public constructors
ConcatenatingMediaSource
public ConcatenatingMediaSource(MediaSource[] mediaSources)| Parameters | |
|---|---|
MediaSource[] mediaSources |
The |
ConcatenatingMediaSource
public ConcatenatingMediaSource(boolean isAtomic, MediaSource[] mediaSources)| Parameters | |
|---|---|
boolean isAtomic |
Whether the concatenating media source will be treated as atomic, i.e., treated as a single item for repeating and shuffling. |
MediaSource[] mediaSources |
The |
ConcatenatingMediaSource
publicConcatenatingMediaSource(
boolean isAtomic,
ShuffleOrder shuffleOrder,
MediaSource[] mediaSources
)
| Parameters | |
|---|---|
boolean isAtomic |
Whether the concatenating media source will be treated as atomic, i.e., treated as a single item for repeating and shuffling. |
ShuffleOrder shuffleOrder |
The |
MediaSource[] mediaSources |
The |
ConcatenatingMediaSource
publicConcatenatingMediaSource(
boolean isAtomic,
boolean useLazyPreparation,
ShuffleOrder shuffleOrder,
MediaSource[] mediaSources
)
| Parameters | |
|---|---|
boolean isAtomic |
Whether the concatenating media source will be treated as atomic, i.e., treated as a single item for repeating and shuffling. |
boolean useLazyPreparation |
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 |
MediaSource[] mediaSources |
The |
Public methods
addMediaSource
synchronized public voidaddMediaSource(MediaSource mediaSource)
Appends a MediaSource to the playlist.
| Parameters | |
|---|---|
MediaSource mediaSource |
The |
addMediaSource
synchronized public voidaddMediaSource(int index, MediaSource mediaSource)
Adds a MediaSource to the playlist.
| Parameters | |
|---|---|
int index |
The index at which the new |
MediaSource mediaSource |
The |
addMediaSource
synchronized public voidaddMediaSource(
MediaSource mediaSource,
Handler handler,
Runnable onCompletionAction
)
Appends a MediaSource to the playlist and executes a custom action on completion.
| Parameters | |
|---|---|
MediaSource mediaSource |
The |
Handler handler |
The |
Runnable onCompletionAction |
A |
addMediaSource
synchronized public voidaddMediaSource(
int index,
MediaSource mediaSource,
Handler handler,
Runnable onCompletionAction
)
Adds a MediaSource to the playlist and executes a custom action on completion.
| Parameters | |
|---|---|
int index |
The index at which the new |
MediaSource mediaSource |
The |
Handler handler |
The |
Runnable onCompletionAction |
A |
addMediaSources
synchronized public voidaddMediaSources(Collection<MediaSource> mediaSources)
Appends multiple MediaSources to the playlist.
| Parameters | |
|---|---|
Collection<MediaSource> mediaSources |
A collection of |
addMediaSources
synchronized public voidaddMediaSources(int index, Collection<MediaSource> mediaSources)
Adds multiple MediaSources to the playlist.
| Parameters | |
|---|---|
int index |
The index at which the new |
Collection<MediaSource> mediaSources |
A collection of |
addMediaSources
synchronized public voidaddMediaSources(
Collection<MediaSource> mediaSources,
Handler handler,
Runnable onCompletionAction
)
Appends multiple MediaSources to the playlist and executes a custom action on completion.
| Parameters | |
|---|---|
Collection<MediaSource> mediaSources |
A collection of |
Handler handler |
The |
Runnable onCompletionAction |
A |
addMediaSources
synchronized public voidaddMediaSources(
int index,
Collection<MediaSource> mediaSources,
Handler handler,
Runnable onCompletionAction
)
Adds multiple MediaSources to the playlist and executes a custom action on completion.
| Parameters | |
|---|---|
int index |
The index at which the new |
Collection<MediaSource> mediaSources |
A collection of |
Handler handler |
The |
Runnable onCompletionAction |
A |
clear
synchronized public voidclear(Handler handler, Runnable onCompletionAction)
Clears the playlist and executes a custom action on completion.
createPeriod
public MediaPeriodcreatePeriod(
MediaSource.MediaPeriodId id,
Allocator allocator,
long startPositionUs
)
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 | |
|---|---|
MediaSource.MediaPeriodId id |
The identifier of the period. |
Allocator allocator |
An |
long startPositionUs |
The expected start position, in microseconds. |
| Returns | |
|---|---|
MediaPeriod |
A new |
getInitialTimeline
synchronized public TimelinegetInitialTimeline()
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
public MediaItemgetMediaItem()
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 public MediaSourcegetMediaSource(int index)
Returns the MediaSource at a specified index.
| Parameters | |
|---|---|
int index |
An index in the range of 0 <= index <= |
| Returns | |
|---|---|
MediaSource |
The |
isSingleWindow
public boolean isSingleWindow()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 public void moveMediaSource(int currentIndex, int newIndex)Moves an existing MediaSource within the playlist.
moveMediaSource
synchronized public voidmoveMediaSource(
int currentIndex,
int newIndex,
Handler handler,
Runnable onCompletionAction
)
Moves an existing MediaSource within the playlist and executes a custom action on completion.
| Parameters | |
|---|---|
int currentIndex |
The current index of the media source in the playlist. This index must be in the range of 0 <= index < |
int newIndex |
The target index of the media source in the playlist. This index must be in the range of 0 <= index < |
Handler handler |
The |
Runnable onCompletionAction |
A |
releasePeriod
public voidreleasePeriod(MediaPeriod mediaPeriod)
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 public MediaSourceremoveMediaSource(int index)
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 | |
|---|---|
int index |
The index at which the media source will be removed. This index must be in the range of 0 <= index < |
| Returns | |
|---|---|
MediaSource |
The removed |
removeMediaSource
synchronized public MediaSourceremoveMediaSource(
int index,
Handler handler,
Runnable onCompletionAction
)
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 | |
|---|---|
int index |
The index at which the media source will be removed. This index must be in the range of 0 <= index < |
Handler handler |
The |
Runnable onCompletionAction |
A |
| Returns | |
|---|---|
MediaSource |
The removed |
removeMediaSourceRange
synchronized public void removeMediaSourceRange(int fromIndex, int toIndex)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 | |
|---|---|
int fromIndex |
The initial range index, pointing to the first media source that will be removed. This index must be in the range of 0 <= index <= |
int toIndex |
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 <= |
| Throws | |
|---|---|
java.lang.IndexOutOfBoundsException |
When the range is malformed, i.e. |
removeMediaSourceRange
synchronized public voidremoveMediaSourceRange(
int fromIndex,
int toIndex,
Handler handler,
Runnable onCompletionAction
)
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 | |
|---|---|
int fromIndex |
The initial range index, pointing to the first media source that will be removed. This index must be in the range of 0 <= index <= |
int toIndex |
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 <= |
Handler handler |
The |
Runnable onCompletionAction |
A |
| Throws | |
|---|---|
java.lang.IllegalArgumentException |
When the range is malformed, i.e. |
setShuffleOrder
synchronized public voidsetShuffleOrder(ShuffleOrder shuffleOrder)
Sets a new shuffle order to use when shuffling the child media sources.
| Parameters | |
|---|---|
ShuffleOrder shuffleOrder |
A |
setShuffleOrder
synchronized public voidsetShuffleOrder(
ShuffleOrder shuffleOrder,
Handler handler,
Runnable onCompletionAction
)
Sets a new shuffle order to use when shuffling the child media sources.
| Parameters | |
|---|---|
ShuffleOrder shuffleOrder |
A |
Handler handler |
The |
Runnable onCompletionAction |
A |
Protected methods
getMediaPeriodIdForChildMediaPeriodId
protected @Nullable MediaSource.MediaPeriodIdgetMediaPeriodIdForChildMediaPeriodId(
ConcatenatingMediaSource.MediaSourceHolder childSourceId,
MediaSource.MediaPeriodId mediaPeriodId
)
Returns the MediaPeriodId in the composite source corresponding to the specified MediaPeriodId in a child source. The default implementation does not change the media period id.
| Parameters | |
|---|---|
ConcatenatingMediaSource.MediaSourceHolder childSourceId |
The unique id used to prepare the child source. |
MediaSource.MediaPeriodId mediaPeriodId |
A |
| Returns | |
|---|---|
@Nullable MediaSource.MediaPeriodId |
The corresponding |
getWindowIndexForChildWindowIndex
protected intgetWindowIndexForChildWindowIndex(
ConcatenatingMediaSource.MediaSourceHolder 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 | |
|---|---|
ConcatenatingMediaSource.MediaSourceHolder 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 voidonChildSourceInfoRefreshed(
ConcatenatingMediaSource.MediaSourceHolder childSourceId,
MediaSource mediaSource,
Timeline newTimeline
)
Called when the source info of a child source has been refreshed.
| Parameters | |
|---|---|
ConcatenatingMediaSource.MediaSourceHolder 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. |
prepareSourceInternal
synchronized protected voidprepareSourceInternal(@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.
This method is called on the playback thread.
| 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. |
releaseSourceInternal
synchronized protected void releaseSourceInternal()Releases the source, see releaseSource. This method is called exactly once after each call to prepareSourceInternal.
This method is called on the playback thread.