public class ConcatenatingMediaSource extends CompositeMediaSource<com.google.android.exoplayer2.source.ConcatenatingMediaSource.MediaSourceHolder> implements PlayerMessage.Target
MediaSource
s. The list of MediaSource
s 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.MediaSource.MediaPeriodId, MediaSource.SourceInfoRefreshListener
Constructor and Description |
---|
ConcatenatingMediaSource(boolean isAtomic,
boolean useLazyPreparation,
ShuffleOrder shuffleOrder,
MediaSource... mediaSources) |
ConcatenatingMediaSource(boolean isAtomic,
MediaSource... mediaSources) |
ConcatenatingMediaSource(boolean isAtomic,
ShuffleOrder shuffleOrder,
MediaSource... mediaSources) |
ConcatenatingMediaSource(MediaSource... mediaSources) |
Modifier and Type | Method and Description |
---|---|
void |
addMediaSource(int index,
MediaSource mediaSource)
Adds a
MediaSource to the playlist. |
void |
addMediaSource(int index,
MediaSource mediaSource,
java.lang.Runnable actionOnCompletion)
Adds a
MediaSource to the playlist and executes a custom action on completion. |
void |
addMediaSource(MediaSource mediaSource)
Appends a
MediaSource to the playlist. |
void |
addMediaSource(MediaSource mediaSource,
java.lang.Runnable actionOnCompletion)
Appends a
MediaSource to the playlist and executes a custom action on completion. |
void |
addMediaSources(java.util.Collection<MediaSource> mediaSources)
Appends multiple
MediaSource s to the playlist. |
void |
addMediaSources(java.util.Collection<MediaSource> mediaSources,
java.lang.Runnable actionOnCompletion)
Appends multiple
MediaSource s to the playlist and executes a custom action on
completion. |
void |
addMediaSources(int index,
java.util.Collection<MediaSource> mediaSources)
Adds multiple
MediaSource s to the playlist. |
void |
addMediaSources(int index,
java.util.Collection<MediaSource> mediaSources,
java.lang.Runnable actionOnCompletion)
Adds multiple
MediaSource s to the playlist and executes a custom action on completion. |
void |
clear()
Clears the playlist.
|
void |
clear(java.lang.Runnable actionOnCompletion)
Clears the playlist and executes a custom action on completion.
|
MediaPeriod |
createPeriod(MediaSource.MediaPeriodId id,
Allocator allocator)
Returns a new
MediaPeriod identified by periodId . |
protected MediaSource.MediaPeriodId |
getMediaPeriodIdForChildMediaPeriodId(com.google.android.exoplayer2.source.ConcatenatingMediaSource.MediaSourceHolder mediaSourceHolder,
MediaSource.MediaPeriodId mediaPeriodId)
Returns the
MediaPeriodId in the composite source corresponding to the specified MediaPeriodId in a child source. |
MediaSource |
getMediaSource(int index)
Returns the
MediaSource at a specified index. |
int |
getSize()
Returns the number of media sources in the playlist.
|
protected int |
getWindowIndexForChildWindowIndex(com.google.android.exoplayer2.source.ConcatenatingMediaSource.MediaSourceHolder mediaSourceHolder,
int windowIndex)
Returns the window index in the composite source corresponding to the specified window index in
a child source.
|
void |
handleMessage(int messageType,
java.lang.Object message)
Handles a message delivered to the target.
|
void |
maybeThrowSourceInfoRefreshError()
Throws any pending error encountered while loading or refreshing source information.
|
void |
moveMediaSource(int currentIndex,
int newIndex)
Moves an existing
MediaSource within the playlist. |
void |
moveMediaSource(int currentIndex,
int newIndex,
java.lang.Runnable actionOnCompletion)
Moves an existing
MediaSource within the playlist and executes a custom action on
completion. |
protected void |
onChildSourceInfoRefreshed(com.google.android.exoplayer2.source.ConcatenatingMediaSource.MediaSourceHolder mediaSourceHolder,
MediaSource mediaSource,
Timeline timeline,
java.lang.Object manifest)
Called when the source info of a child source has been refreshed.
|
void |
prepareSourceInternal(ExoPlayer player,
boolean isTopLevelSource,
TransferListener mediaTransferListener)
Starts source preparation.
|
void |
releasePeriod(MediaPeriod mediaPeriod)
Releases the period.
|
void |
releaseSourceInternal()
Releases the source.
|
void |
removeMediaSource(int index)
Removes a
MediaSource from the playlist. |
void |
removeMediaSource(int index,
java.lang.Runnable actionOnCompletion)
Removes a
MediaSource from the playlist and executes a custom action on completion. |
void |
removeMediaSourceRange(int fromIndex,
int toIndex)
Removes a range of
MediaSource s from the playlist, by specifying an initial index
(included) and a final index (excluded). |
void |
removeMediaSourceRange(int fromIndex,
int toIndex,
java.lang.Runnable actionOnCompletion)
Removes a range of
MediaSource s from the playlist, by specifying an initial index
(included) and a final index (excluded), and executes a custom action on completion. |
void |
setShuffleOrder(ShuffleOrder shuffleOrder)
Sets a new shuffle order to use when shuffling the child media sources.
|
void |
setShuffleOrder(ShuffleOrder shuffleOrder,
java.lang.Runnable actionOnCompletion)
Sets a new shuffle order to use when shuffling the child media sources.
|
getMediaTimeForChildMediaTime, prepareChildSource, releaseChildSource
addEventListener, createEventDispatcher, createEventDispatcher, createEventDispatcher, prepareSource, prepareSource, refreshSourceInfo, releaseSource, removeEventListener
public ConcatenatingMediaSource(MediaSource... mediaSources)
mediaSources
- The MediaSource
s to concatenate. It is valid for the same
MediaSource
instance to be present more than once in the array.public ConcatenatingMediaSource(boolean isAtomic, MediaSource... mediaSources)
isAtomic
- Whether the concatenating media source will be treated as atomic, i.e., treated
as a single item for repeating and shuffling.mediaSources
- The MediaSource
s to concatenate. It is valid for the same MediaSource
instance to be present more than once in the array.public ConcatenatingMediaSource(boolean isAtomic, ShuffleOrder shuffleOrder, MediaSource... mediaSources)
isAtomic
- Whether the concatenating media source will be treated as atomic, i.e., treated
as a single item for repeating and shuffling.shuffleOrder
- The ShuffleOrder
to use when shuffling the child media sources.mediaSources
- The MediaSource
s to concatenate. It is valid for the same MediaSource
instance to be present more than once in the array.public ConcatenatingMediaSource(boolean isAtomic, boolean useLazyPreparation, ShuffleOrder shuffleOrder, MediaSource... mediaSources)
isAtomic
- Whether the concatenating media source will be treated as atomic, i.e., treated
as a single item for repeating and shuffling.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
- The ShuffleOrder
to use when shuffling the child media sources.mediaSources
- The MediaSource
s to concatenate. It is valid for the same MediaSource
instance to be present more than once in the array.public final void addMediaSource(MediaSource mediaSource)
MediaSource
to the playlist.mediaSource
- The MediaSource
to be added to the list.public final void addMediaSource(MediaSource mediaSource, @Nullable java.lang.Runnable actionOnCompletion)
MediaSource
to the playlist and executes a custom action on completion.mediaSource
- The MediaSource
to be added to the list.actionOnCompletion
- A Runnable
which is executed immediately after the media
source has been added to the playlist.public final void addMediaSource(int index, MediaSource mediaSource)
MediaSource
to the playlist.index
- The index at which the new MediaSource
will be inserted. This index must
be in the range of 0 <= index <= getSize()
.mediaSource
- The MediaSource
to be added to the list.public final void addMediaSource(int index, MediaSource mediaSource, @Nullable java.lang.Runnable actionOnCompletion)
MediaSource
to the playlist and executes a custom action on completion.index
- The index at which the new MediaSource
will be inserted. This index must
be in the range of 0 <= index <= getSize()
.mediaSource
- The MediaSource
to be added to the list.actionOnCompletion
- A Runnable
which is executed immediately after the media
source has been added to the playlist.public final void addMediaSources(java.util.Collection<MediaSource> mediaSources)
MediaSource
s to the playlist.mediaSources
- A collection of MediaSource
s to be added to the list. The media
sources are added in the order in which they appear in this collection.public final void addMediaSources(java.util.Collection<MediaSource> mediaSources, @Nullable java.lang.Runnable actionOnCompletion)
MediaSource
s to the playlist and executes a custom action on
completion.mediaSources
- A collection of MediaSource
s to be added to the list. The media
sources are added in the order in which they appear in this collection.actionOnCompletion
- A Runnable
which is executed immediately after the media
sources have been added to the playlist.public final void addMediaSources(int index, java.util.Collection<MediaSource> mediaSources)
MediaSource
s to the playlist.index
- The index at which the new MediaSource
s will be inserted. This index must
be in the range of 0 <= index <= getSize()
.mediaSources
- A collection of MediaSource
s to be added to the list. The media
sources are added in the order in which they appear in this collection.public final void addMediaSources(int index, java.util.Collection<MediaSource> mediaSources, @Nullable java.lang.Runnable actionOnCompletion)
MediaSource
s to the playlist and executes a custom action on completion.index
- The index at which the new MediaSource
s will be inserted. This index must
be in the range of 0 <= index <= getSize()
.mediaSources
- A collection of MediaSource
s to be added to the list. The media
sources are added in the order in which they appear in this collection.actionOnCompletion
- A Runnable
which is executed immediately after the media
sources have been added to the playlist.public final void removeMediaSource(int index)
MediaSource
from the playlist.
Note: If you want to move the instance, it's preferable to use moveMediaSource(int,
int)
instead.
Note: If you want to remove a set of contiguous sources, it's preferable to use removeMediaSourceRange(int, int)
instead.
index
- The index at which the media source will be removed. This index must be in the
range of 0 <= index < getSize()
.public final void removeMediaSource(int index, @Nullable java.lang.Runnable actionOnCompletion)
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(int,
int, Runnable)
instead.
Note: If you want to remove a set of contiguous sources, it's preferable to use removeMediaSourceRange(int, int, Runnable)
instead.
index
- The index at which the media source will be removed. This index must be in the
range of 0 <= index < getSize()
.actionOnCompletion
- A Runnable
which is executed immediately after the media
source has been removed from the playlist.public final void removeMediaSourceRange(int fromIndex, int toIndex)
MediaSource
s 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.
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 <= getSize()
.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 <= getSize()
.java.lang.IndexOutOfBoundsException
- When the range is malformed, i.e. fromIndex
< 0,
toIndex
> getSize()
, fromIndex
> toIndex
public final void removeMediaSourceRange(int fromIndex, int toIndex, @Nullable java.lang.Runnable actionOnCompletion)
MediaSource
s 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.
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 <= getSize()
.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 <= getSize()
.actionOnCompletion
- A Runnable
which is executed immediately after the media
source range has been removed from the playlist.java.lang.IllegalArgumentException
- When the range is malformed, i.e. fromIndex
< 0,
toIndex
> getSize()
, fromIndex
> toIndex
public final void moveMediaSource(int currentIndex, int newIndex)
MediaSource
within the playlist.public final void moveMediaSource(int currentIndex, int newIndex, @Nullable java.lang.Runnable actionOnCompletion)
MediaSource
within the playlist and executes a custom action on
completion.currentIndex
- The current index of the media source in the playlist. This index must be
in the range of 0 <= index < getSize()
.newIndex
- The target index of the media source in the playlist. This index must be in the
range of 0 <= index < getSize()
.actionOnCompletion
- A Runnable
which is executed immediately after the media
source has been moved.public final void clear()
public final void clear(@Nullable java.lang.Runnable actionOnCompletion)
actionOnCompletion
- A Runnable
which is executed immediately after the playlist
has been cleared.public final int getSize()
public final MediaSource getMediaSource(int index)
MediaSource
at a specified index.index
- An index in the range of 0 <= index <= getSize()
.MediaSource
at this index.public final void setShuffleOrder(ShuffleOrder shuffleOrder)
shuffleOrder
- A ShuffleOrder
.public final void setShuffleOrder(ShuffleOrder shuffleOrder, @Nullable java.lang.Runnable actionOnCompletion)
shuffleOrder
- A ShuffleOrder
.actionOnCompletion
- A Runnable
which is executed immediately after the shuffle
order has been changed.public final void prepareSourceInternal(ExoPlayer player, boolean isTopLevelSource, @Nullable TransferListener mediaTransferListener)
BaseMediaSource
BaseMediaSource.releaseSourceInternal()
.prepareSourceInternal
in class CompositeMediaSource<com.google.android.exoplayer2.source.ConcatenatingMediaSource.MediaSourceHolder>
player
- The player for which this source is being prepared.isTopLevelSource
- Whether this source has been passed directly to ExoPlayer.prepare(MediaSource)
or ExoPlayer.prepare(MediaSource, boolean,
boolean)
.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.public void maybeThrowSourceInfoRefreshError() throws java.io.IOException
MediaSource
Should not be called directly from application code.
maybeThrowSourceInfoRefreshError
in interface MediaSource
maybeThrowSourceInfoRefreshError
in class CompositeMediaSource<com.google.android.exoplayer2.source.ConcatenatingMediaSource.MediaSourceHolder>
java.io.IOException
public final MediaPeriod createPeriod(MediaSource.MediaPeriodId id, Allocator allocator)
MediaSource
MediaPeriod
identified by periodId
. This method may be called
multiple times without an intervening call to MediaSource.releasePeriod(MediaPeriod)
.
Should not be called directly from application code.
createPeriod
in interface MediaSource
id
- The identifier of the period.allocator
- An Allocator
from which to obtain media buffer allocations.MediaPeriod
.public final void releasePeriod(MediaPeriod mediaPeriod)
MediaSource
Should not be called directly from application code.
releasePeriod
in interface MediaSource
mediaPeriod
- The period to release.public final void releaseSourceInternal()
BaseMediaSource
BaseMediaSource.prepareSourceInternal(ExoPlayer, boolean, TransferListener)
.releaseSourceInternal
in class CompositeMediaSource<com.google.android.exoplayer2.source.ConcatenatingMediaSource.MediaSourceHolder>
protected final void onChildSourceInfoRefreshed(com.google.android.exoplayer2.source.ConcatenatingMediaSource.MediaSourceHolder mediaSourceHolder, MediaSource mediaSource, Timeline timeline, @Nullable java.lang.Object manifest)
CompositeMediaSource
onChildSourceInfoRefreshed
in class CompositeMediaSource<com.google.android.exoplayer2.source.ConcatenatingMediaSource.MediaSourceHolder>
mediaSourceHolder
- The unique id used to prepare the child source.mediaSource
- The child source whose source info has been refreshed.timeline
- The timeline of the child source.manifest
- The manifest of the child source.@Nullable protected MediaSource.MediaPeriodId getMediaPeriodIdForChildMediaPeriodId(com.google.android.exoplayer2.source.ConcatenatingMediaSource.MediaSourceHolder mediaSourceHolder, MediaSource.MediaPeriodId mediaPeriodId)
CompositeMediaSource
MediaPeriodId
in the composite source corresponding to the specified MediaPeriodId
in a child source. The default implementation does not change the media period
id.getMediaPeriodIdForChildMediaPeriodId
in class CompositeMediaSource<com.google.android.exoplayer2.source.ConcatenatingMediaSource.MediaSourceHolder>
mediaSourceHolder
- The unique id used to prepare the child source.mediaPeriodId
- A MediaPeriodId
of the child source.MediaPeriodId
in the composite source. Null if no
corresponding media period id can be determined.protected int getWindowIndexForChildWindowIndex(com.google.android.exoplayer2.source.ConcatenatingMediaSource.MediaSourceHolder mediaSourceHolder, int windowIndex)
CompositeMediaSource
getWindowIndexForChildWindowIndex
in class CompositeMediaSource<com.google.android.exoplayer2.source.ConcatenatingMediaSource.MediaSourceHolder>
mediaSourceHolder
- The unique id used to prepare the child source.windowIndex
- A window index of the child source.public final void handleMessage(int messageType, @Nullable java.lang.Object message) throws ExoPlaybackException
PlayerMessage.Target
handleMessage
in interface PlayerMessage.Target
messageType
- The message type.message
- The message payload.ExoPlaybackException
- If an error occurred whilst handling the message. Should only be
thrown by targets that handle messages on the playback thread.