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.SourceInfoRefreshListener.onSourceInfoRefreshed(com.google.android.exoplayer2.source.MediaSource, com.google.android.exoplayer2.Timeline, java.lang.Object)
on the MediaSource.SourceInfoRefreshListeners passed to prepareSource(ExoPlayer,
boolean, SourceInfoRefreshListener).
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 can be
re-used, but only for one ExoPlayer instance simultaneously.| Modifier and Type | Interface and Description |
|---|---|
static class |
MediaSource.MediaPeriodId
Identifier for a
MediaPeriod. |
static interface |
MediaSource.SourceInfoRefreshListener
Listener for source events.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addEventListener(android.os.Handler handler,
MediaSourceEventListener eventListener)
Adds a
MediaSourceEventListener to the list of listeners which are notified of media
source events. |
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.SourceInfoRefreshListener listener)
Starts source preparation if not yet started, and adds a listener for timeline and/or manifest
updates.
|
void |
releasePeriod(MediaPeriod mediaPeriod)
Releases the period.
|
void |
releaseSource(MediaSource.SourceInfoRefreshListener listener)
Removes a listener for timeline and/or manifest updates and releases the source if no longer
required.
|
void |
removeEventListener(MediaSourceEventListener eventListener)
Removes a
MediaSourceEventListener from the list of listeners which are notified of
media source events. |
void addEventListener(android.os.Handler handler,
MediaSourceEventListener eventListener)
MediaSourceEventListener to the list of listeners which are notified of media
source events.handler - A handler on the which listener events will be posted.eventListener - The listener to be added.void removeEventListener(MediaSourceEventListener eventListener)
MediaSourceEventListener from the list of listeners which are notified of
media source events.eventListener - The listener to be removed.void prepareSource(ExoPlayer player, boolean isTopLevelSource, MediaSource.SourceInfoRefreshListener listener)
Should not be called directly from application code.
The listener will be also be notified if the source already has a timeline and/or manifest.
For each call to this method, a call to releaseSource(SourceInfoRefreshListener) is
needed to remove the listener and to release the source if no longer required.
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 to be added.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(MediaSource.SourceInfoRefreshListener listener)
Should not be called directly from application code.
listener - The listener to be removed.