MediaSource
public interface MediaSource
BaseMediaSource |
Base |
AdsMediaSource |
A |
ClippingMediaSource |
|
CompositeMediaSource |
Composite |
ConcatenatingMediaSource2 |
Concatenates multiple |
ConcatenatingMediaSource |
This class is deprecated. Use playlist modification methods like addMediaItem instead. |
DashMediaSource |
A DASH |
EmptyMediaSource |
MediaSource producing an empty |
ExternallyLoadedMediaSource |
A |
FakeAdaptiveMediaSource |
Fake |
FakeMediaSource |
Fake |
FilteringMediaSource |
A |
HlsMediaSource |
An HLS |
ImaServerSideAdInsertionMediaSource |
MediaSource for IMA server side inserted ad streams. |
LoopingMediaSource |
This class is deprecated. To loop a |
MaskingMediaSource |
A |
MergingMediaSource |
Merges multiple |
PreloadMediaSource |
Preloads a |
ProgressiveMediaSource |
Provides one period that loads data from a |
RtspMediaSource |
An Rtsp |
ServerSideAdInsertionMediaSource |
A |
SilenceMediaSource |
Media source with a single period consisting of silent raw audio of a given duration. |
SingleSampleMediaSource |
This class is deprecated. The only use for this class is subtitle playback, but it is only compatible with legacy subtitle decoding, which is not supported by default. |
SsMediaSource |
A SmoothStreaming |
WrappingMediaSource |
An abstract |
Defines and provides media to be played by an ExoPlayer. A MediaSource has two main responsibilities:
- To provide the player with a
Timelinedefining the structure of its media, and to provide a new timeline whenever the structure of the media changes. The MediaSource provides these timelines by callingonSourceInfoRefreshedon theMediaSourceCallers passed toprepareSource. - To provide
MediaPeriodinstances for the periods in its timeline. MediaPeriods are obtained by callingcreatePeriod, and provide a way for the player to load and read the media.
MediaSource methods should not be called from application code. Instead, the playback logic in ExoPlayer will trigger methods at the right time.
Instances can be re-used, but only for one ExoPlayer instance simultaneously.
MediaSource methods will be called on one of two threads, an application thread or a playback thread. Each method is documented with the thread it is called on.
Summary
Nested types |
|---|
public interface MediaSource.FactoryFactory for creating |
@UnstableApiIdentifier for a |
@UnstableApiA caller of media sources, which will be notified of source events. |
Public methods |
|
|---|---|
abstract void |
@UnstableApiAdds a |
abstract void |
@UnstableApiAdds a |
default boolean |
@UnstableApiReturns whether the |
abstract MediaPeriod |
@UnstableApiReturns a new |
abstract void |
Disables the source for the creation of |
abstract void |
Enables the source for the creation of |
default @Nullable 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. |
abstract MediaItem |
Returns the |
default boolean |
Returns true if the media source is guaranteed to never have zero or more than one window. |
abstract void |
Throws any pending error encountered while loading or refreshing source information. |
default void |
@UnstableApiThis method is deprecated. Use |
default void |
@UnstableApiRegisters a |
abstract void |
@UnstableApiReleases the period. |
abstract void |
Unregisters a caller, and disables and releases the source if no longer required. |
abstract void |
@UnstableApiRemoves a |
abstract void |
@UnstableApiRemoves a |
default void |
@UnstableApiUpdates the |
Public methods
addDrmEventListener
@UnstableApi
abstract void addDrmEventListener(
Handler handler,
DrmSessionEventListener eventListener
)
Adds a DrmSessionEventListener to the list of listeners which are notified of DRM events for this media source.
Should not be called directly from application code.
This method must be called on the playback thread.
| Parameters | |
|---|---|
Handler handler |
A handler on the which listener events will be posted. |
DrmSessionEventListener eventListener |
The listener to be added. |
addEventListener
@UnstableApi
abstract void addEventListener(
Handler handler,
MediaSourceEventListener eventListener
)
Adds a MediaSourceEventListener to the list of listeners which are notified of media source events.
Should not be called directly from application code.
This method must be called on the playback thread.
| Parameters | |
|---|---|
Handler handler |
A handler on the which listener events will be posted. |
MediaSourceEventListener eventListener |
The listener to be added. |
canUpdateMediaItem
@UnstableApi
default boolean canUpdateMediaItem(MediaItem mediaItem)
Returns whether the MediaItem for this source can be updated with the provided item.
Should not be called directly from application code.
This method must be called on the application thread.
| Returns | |
|---|---|
boolean |
Whether the source can be updated using this item. |
createPeriod
@UnstableApi
abstract MediaPeriod createPeriod(
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 |
disable
@UnstableApi
abstract void disable(MediaSource.MediaSourceCaller caller)
Disables the source for the creation of MediaPeriods. The implementation should not hold onto limited resources used for the creation of media periods.
Should not be called directly from application code.
This method must be called on the playback thread and only after all MediaPeriods previously created by createPeriod have been released by releasePeriod.
| Parameters | |
|---|---|
MediaSource.MediaSourceCaller caller |
The |
enable
@UnstableApi
abstract void enable(MediaSource.MediaSourceCaller caller)
Enables the source for the creation of MediaPeriods.
Should not be called directly from application code.
This method must be called on the playback thread and only after prepareSource.
| Parameters | |
|---|---|
MediaSource.MediaSourceCaller caller |
The |
getInitialTimeline
@UnstableApi
default @Nullable 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.
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
@UnstableApi
abstract MediaItem getMediaItem()
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.
isSingleWindow
@UnstableApi
default 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. |
maybeThrowSourceInfoRefreshError
@UnstableApi
abstract void maybeThrowSourceInfoRefreshError()
Throws any pending error encountered while loading or refreshing source information.
Should not be called directly from application code.
This method must be called on the playback thread and only after prepareSource.
| Throws | |
|---|---|
java.io.IOException |
prepareSource
@UnstableApi
default voidprepareSource(
MediaSource.MediaSourceCaller caller,
@Nullable TransferListener mediaTransferListener,
PlayerId playerId
)
prepareSource
@UnstableApi
default void prepareSource(
MediaSource.MediaSourceCaller caller,
PlayerId playerId,
BandwidthMeter bandwidthMeter
)
Registers a MediaSourceCaller. Starts source preparation if needed and enables the source for the creation of MediaPerods.
Should not be called directly from application code.
onSourceInfoRefreshed will be called once the source has a Timeline.
For each call to this method, a call to releaseSource is needed to remove the caller and to release the source if no longer required.
This method must be called on the playback thread.
| Parameters | |
|---|---|
MediaSource.MediaSourceCaller caller |
The |
PlayerId playerId |
The |
BandwidthMeter bandwidthMeter |
The |
releasePeriod
@UnstableApi
abstract void releasePeriod(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. |
releaseSource
@UnstableApi
abstract void releaseSource(MediaSource.MediaSourceCaller caller)
Unregisters a caller, and disables and releases the source if no longer required.
Should not be called directly from application code.
This method must be called on the playback thread and only if all created MediaPeriods have been released by releasePeriod.
| Parameters | |
|---|---|
MediaSource.MediaSourceCaller caller |
The |
removeDrmEventListener
@UnstableApi
abstract void removeDrmEventListener(DrmSessionEventListener eventListener)
Removes a DrmSessionEventListener from the list of listeners which are notified of DRM events for this media source.
Should not be called directly from application code.
This method must be called on the playback thread.
| Parameters | |
|---|---|
DrmSessionEventListener eventListener |
The listener to be removed. |
removeEventListener
@UnstableApi
abstract void removeEventListener(MediaSourceEventListener eventListener)
Removes a MediaSourceEventListener from the list of listeners which are notified of media source events.
Should not be called directly from application code.
This method must be called on the playback thread.
| Parameters | |
|---|---|
MediaSourceEventListener eventListener |
The listener to be removed. |
updateMediaItem
@UnstableApi
default void updateMediaItem(MediaItem mediaItem)
Updates the MediaItem for this source.
Should not be called directly from application code.
This method must be called on the playback thread and only if canUpdateMediaItem returns true for the new MediaItem.