MediaSource
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 |
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 |
|---|
interface MediaSource.FactoryFactory for creating |
|
Identifier for a |
@UnstableApiA caller of media sources, which will be notified of source events. |
Public functions |
|
|---|---|
Unit |
@UnstableApiAdds a |
Unit |
@UnstableApiAdds a |
Boolean |
@UnstableApiReturns whether the |
MediaPeriod! |
@UnstableApiReturns a new |
Unit |
@UnstableApiDisables the source for the creation of |
Unit |
@UnstableApiEnables the source for the creation of |
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. |
MediaItem! |
Returns the |
Boolean |
Returns true if the media source is guaranteed to never have zero or more than one window. |
Unit |
Throws any pending error encountered while loading or refreshing source information. |
Unit |
@UnstableApiThis function is deprecated. Implement |
Unit |
@UnstableApiRegisters a |
Unit |
@UnstableApiReleases the period. |
Unit |
Unregisters a caller, and disables and releases the source if no longer required. |
Unit |
@UnstableApiRemoves a |
Unit |
@UnstableApiRemoves a |
Unit |
@UnstableApiUpdates the |
Public functions
addDrmEventListener
@UnstableApi
fun addDrmEventListener(
handler: Handler!,
eventListener: DrmSessionEventListener!
): Unit
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. |
eventListener: DrmSessionEventListener! |
The listener to be added. |
addEventListener
@UnstableApi
fun addEventListener(
handler: Handler!,
eventListener: MediaSourceEventListener!
): Unit
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. |
eventListener: MediaSourceEventListener! |
The listener to be added. |
canUpdateMediaItem
@UnstableApi
fun canUpdateMediaItem(mediaItem: MediaItem!): Boolean
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
fun createPeriod(
id: MediaSource.MediaPeriodId!,
allocator: Allocator!,
startPositionUs: Long
): MediaPeriod!
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 | |
|---|---|
id: MediaSource.MediaPeriodId! |
The identifier of the period. |
allocator: Allocator! |
An |
startPositionUs: Long |
The expected start position, in microseconds. |
| Returns | |
|---|---|
MediaPeriod! |
A new |
disable
@UnstableApi
fun disable(caller: MediaSource.MediaSourceCaller!): Unit
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 | |
|---|---|
caller: MediaSource.MediaSourceCaller! |
The |
enable
@UnstableApi
fun enable(caller: MediaSource.MediaSourceCaller!): Unit
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 | |
|---|---|
caller: MediaSource.MediaSourceCaller! |
The |
getInitialTimeline
@UnstableApi
fun getInitialTimeline(): 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.
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
fun getMediaItem(): MediaItem!
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
fun isSingleWindow(): Boolean
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
fun maybeThrowSourceInfoRefreshError(): Unit
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
funprepareSource(
caller: MediaSource.MediaSourceCaller!,
mediaTransferListener: TransferListener?
): Unit
prepareSource
@UnstableApi
fun prepareSource(
caller: MediaSource.MediaSourceCaller!,
mediaTransferListener: TransferListener?,
playerId: PlayerId!
): Unit
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 | |
|---|---|
caller: MediaSource.MediaSourceCaller! |
The |
mediaTransferListener: TransferListener? |
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. |
playerId: PlayerId! |
The |
releasePeriod
@UnstableApi
fun releasePeriod(mediaPeriod: MediaPeriod!): Unit
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
fun releaseSource(caller: MediaSource.MediaSourceCaller!): Unit
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 | |
|---|---|
caller: MediaSource.MediaSourceCaller! |
The |
removeDrmEventListener
@UnstableApi
fun removeDrmEventListener(eventListener: DrmSessionEventListener!): Unit
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 | |
|---|---|
eventListener: DrmSessionEventListener! |
The listener to be removed. |
removeEventListener
@UnstableApi
fun removeEventListener(eventListener: MediaSourceEventListener!): Unit
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 | |
|---|---|
eventListener: MediaSourceEventListener! |
The listener to be removed. |
updateMediaItem
@UnstableApi
fun updateMediaItem(mediaItem: MediaItem!): Unit
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.