AdsMediaSource
, BaseMediaSource
, ClippingMediaSource
, CompositeMediaSource
, ConcatenatingMediaSource
, DashMediaSource
, ExtractorMediaSource
, FakeAdaptiveMediaSource
, FakeMediaSource
, HlsMediaSource
, LoopingMediaSource
, MaskingMediaSource
, MergingMediaSource
, ProgressiveMediaSource
, SilenceMediaSource
, SingleSampleMediaSource
, SsMediaSource
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.MediaSourceCaller.onSourceInfoRefreshed(com.google.android.exoplayer2.source.MediaSource, com.google.android.exoplayer2.Timeline)
on the
MediaSource.MediaSourceCaller
s passed to prepareSource(MediaSourceCaller,
TransferListener)
.
MediaPeriod
instances for the periods in its timeline. MediaPeriods are
obtained by calling createPeriod(MediaPeriodId, Allocator, long)
, 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 | Description |
---|---|---|
static class |
MediaSource.MediaPeriodId |
Identifier for a
MediaPeriod . |
static interface |
MediaSource.MediaSourceCaller |
A caller of media sources, which will be notified of source events.
|
Modifier and Type | Method | Description |
---|---|---|
void |
addDrmEventListener(Handler handler,
DrmSessionEventListener eventListener) |
Adds a
DrmSessionEventListener to the list of listeners which are notified of DRM
events for this media source. |
void |
addEventListener(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,
long startPositionUs) |
Returns a new
MediaPeriod identified by periodId . |
void |
disable(MediaSource.MediaSourceCaller caller) |
Disables the source for the creation of
MediaPeriods . |
void |
enable(MediaSource.MediaSourceCaller caller) |
Enables the source for the creation of
MediaPeriods . |
default Timeline |
getInitialTimeline() |
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 |
getMediaItem() |
Returns the
MediaItem whose media is provided by the source. |
default Object |
getTag() |
Deprecated.
Use
getMediaItem() and MediaItem.PlaybackProperties.tag instead. |
default boolean |
isSingleWindow() |
Returns true if the media source is guaranteed to never have zero or more than one window.
|
void |
maybeThrowSourceInfoRefreshError() |
Throws any pending error encountered while loading or refreshing source information.
|
void |
prepareSource(MediaSource.MediaSourceCaller caller,
TransferListener mediaTransferListener) |
Registers a
MediaSource.MediaSourceCaller . |
void |
releasePeriod(MediaPeriod mediaPeriod) |
Releases the period.
|
void |
releaseSource(MediaSource.MediaSourceCaller caller) |
Unregisters a caller, and disables and releases the source if no longer required.
|
void |
removeDrmEventListener(DrmSessionEventListener eventListener) |
Removes a
DrmSessionEventListener from the list of listeners which are notified of DRM
events for this media source. |
void |
removeEventListener(MediaSourceEventListener eventListener) |
Removes a
MediaSourceEventListener from the list of listeners which are notified of
media source events. |
void addEventListener(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 addDrmEventListener(Handler handler, DrmSessionEventListener eventListener)
DrmSessionEventListener
to the list of listeners which are notified of DRM
events for this media source.handler
- A handler on the which listener events will be posted.eventListener
- The listener to be added.void removeDrmEventListener(DrmSessionEventListener eventListener)
DrmSessionEventListener
from the list of listeners which are notified of DRM
events for this media source.eventListener
- The listener to be removed.@Nullable default Timeline getInitialTimeline()
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.
default boolean isSingleWindow()
The default implementation returns true
.
@Deprecated @Nullable default Object getTag()
getMediaItem()
and MediaItem.PlaybackProperties.tag
instead.void prepareSource(MediaSource.MediaSourceCaller caller, @Nullable TransferListener mediaTransferListener)
MediaSource.MediaSourceCaller
. Starts source preparation if needed and enables the
source for the creation of MediaPerods
.
Should not be called directly from application code.
MediaSource.MediaSourceCaller.onSourceInfoRefreshed(MediaSource, Timeline)
will be called once
the source has a Timeline
.
For each call to this method, a call to releaseSource(MediaSourceCaller)
is needed
to remove the caller and to release the source if no longer required.
caller
- The MediaSource.MediaSourceCaller
to be registered.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 be only
informed of transfers related to the media loads and not of auxiliary loads for manifests
and other data.void maybeThrowSourceInfoRefreshError() throws IOException
Should not be called directly from application code.
Must only be called after prepareSource(MediaSourceCaller, TransferListener)
.
IOException
void enable(MediaSource.MediaSourceCaller caller)
MediaPeriods
.
Should not be called directly from application code.
Must only be called after prepareSource(MediaSourceCaller, TransferListener)
.
caller
- The MediaSource.MediaSourceCaller
enabling the source.MediaPeriod createPeriod(MediaSource.MediaPeriodId id, Allocator allocator, long startPositionUs)
MediaPeriod
identified by periodId
.
Should not be called directly from application code.
Must only be called if the source is enabled.
id
- The identifier of the period.allocator
- An Allocator
from which to obtain media buffer allocations.startPositionUs
- The expected start position, in microseconds.MediaPeriod
.void releasePeriod(MediaPeriod mediaPeriod)
Should not be called directly from application code.
mediaPeriod
- The period to release.void disable(MediaSource.MediaSourceCaller caller)
MediaPeriods
. The implementation
should not hold onto limited resources used for the creation of media periods.
Should not be called directly from application code.
Must only be called after all MediaPeriods
previously created by createPeriod(MediaPeriodId, Allocator, long)
have been released by releasePeriod(MediaPeriod)
.
caller
- The MediaSource.MediaSourceCaller
disabling the source.void releaseSource(MediaSource.MediaSourceCaller caller)
Should not be called directly from application code.
Must only be called if all created MediaPeriods
have been released by
releasePeriod(MediaPeriod)
.
caller
- The MediaSource.MediaSourceCaller
to be unregistered.