public interface MediaSource
ExoPlayer. A MediaSource has two main
responsibilities:
Timeline defining the structure of its media, and to
provide a new timeline whenever the structure of the media changes. The MediaSource provides
these timelines by calling MediaSource.Listener.onSourceInfoRefreshed(com.google.android.exoplayer2.source.MediaSource, com.google.android.exoplayer2.Timeline, java.lang.Object) on the MediaSource.Listener
passed to prepareSource(ExoPlayer, boolean, Listener).MediaPeriod instances for the periods in its timeline. MediaPeriods are
obtained by calling createPeriod(MediaPeriodId, Allocator), and provide a way for the
player to load and read the media.ExoPlayer Javadoc. They should not be called directly from application code. Instances
should not be re-used, meaning they should be passed to ExoPlayer.prepare(com.google.android.exoplayer2.source.MediaSource) at most once.| Modifier and Type | Interface and Description |
|---|---|
static interface |
MediaSource.Listener
Listener for source events.
|
static class |
MediaSource.MediaPeriodId
Identifier for a
MediaPeriod. |
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
MEDIA_SOURCE_REUSED_ERROR_MESSAGE |
| Modifier and Type | Method and Description |
|---|---|
MediaPeriod |
createPeriod(MediaSource.MediaPeriodId id,
Allocator allocator)
Returns a new
MediaPeriod identified by periodId. |
void |
maybeThrowSourceInfoRefreshError()
Throws any pending error encountered while loading or refreshing source information.
|
void |
prepareSource(ExoPlayer player,
boolean isTopLevelSource,
MediaSource.Listener listener)
Starts preparation of the source.
|
void |
releasePeriod(MediaPeriod mediaPeriod)
Releases the period.
|
void |
releaseSource()
Releases the source.
|
static final java.lang.String MEDIA_SOURCE_REUSED_ERROR_MESSAGE
void prepareSource(ExoPlayer player, boolean isTopLevelSource, MediaSource.Listener listener)
Should not be called directly from application code.
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). If false, this source is
being prepared by another source (e.g. ConcatenatingMediaSource) for composition.listener - The listener for source events.void maybeThrowSourceInfoRefreshError()
throws java.io.IOException
Should not be called directly from application code.
java.io.IOExceptionMediaPeriod createPeriod(MediaSource.MediaPeriodId id, Allocator allocator)
MediaPeriod identified by periodId. This method may be called
multiple times with the same period identifier without an intervening call to
releasePeriod(MediaPeriod).
Should not be called directly from application code.
id - The identifier of the period.allocator - An Allocator from which to obtain media buffer allocations.MediaPeriod.void releasePeriod(MediaPeriod mediaPeriod)
Should not be called directly from application code.
mediaPeriod - The period to release.void releaseSource()
Should not be called directly from application code.