interface MediaSource

Known direct subclasses
BaseMediaSource

Base MediaSource implementation to handle parallel reuse and to keep a list of s.

Known indirect subclasses
AdsMediaSource

A MediaSource that inserts ads linearly into a provided content media source.

ClippingMediaSource

MediaSource that wraps a source and clips its timeline based on specified start/end positions.

CompositeMediaSource

Composite MediaSource consisting of multiple child sources.

ConcatenatingMediaSource2

Concatenates multiple MediaSources, combining everything in one single .

ConcatenatingMediaSource

This class is deprecated.

Use playlist modification methods like addMediaItem instead.

DashMediaSource

A DASH MediaSource.

ExternallyLoadedMediaSource

A MediaSource for media loaded outside of the usual ExoPlayer loading mechanism.

FakeAdaptiveMediaSource

Fake MediaSource that provides a given timeline.

FakeMediaSource

Fake MediaSource that provides a given timeline.

FilteringMediaSource

A MediaSource that filters the available track types.

HlsMediaSource

An HLS MediaSource.

ImaServerSideAdInsertionMediaSource

MediaSource for IMA server side inserted ad streams.

LoopingMediaSource

This class is deprecated.

To loop a MediaSource indefinitely, use setRepeatMode instead of this class.

MaskingMediaSource

A MediaSource that masks the Timeline with a placeholder until the actual media structure is known.

MergingMediaSource

Merges multiple MediaSources.

PreloadMediaSource

Preloads a MediaSource and provides a MediaPeriod that has data loaded before playback.

ProgressiveMediaSource

Provides one period that loads data from a Uri and extracted using an Extractor.

RtspMediaSource

An Rtsp MediaSource

ServerSideAdInsertionMediaSource

A MediaSource for server-side inserted ad breaks.

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 MediaSource.

WrappingMediaSource

An abstract MediaSource wrapping a single child MediaSource.


Defines and provides media to be played by an ExoPlayer. A MediaSource has two main responsibilities:

  • To provide the player with a 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 onSourceInfoRefreshed on the MediaSourceCallers passed to prepareSource.
  • To provide MediaPeriod instances for the periods in its timeline. MediaPeriods are obtained by calling createPeriod, 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

Factory for creating MediaSources from MediaItems.

Identifier for a MediaPeriod.

A caller of media sources, which will be notified of source events.

Public functions

Unit
@UnstableApi
addDrmEventListener(
    handler: Handler!,
    eventListener: DrmSessionEventListener!
)

Adds a DrmSessionEventListener to the list of listeners which are notified of DRM events for this media source.

Unit
@UnstableApi
addEventListener(
    handler: Handler!,
    eventListener: MediaSourceEventListener!
)

Adds a MediaSourceEventListener to the list of listeners which are notified of media source events.

Boolean

Returns whether the MediaItem for this source can be updated with the provided item.

MediaPeriod!
@UnstableApi
createPeriod(
    id: MediaSource.MediaPeriodId!,
    allocator: Allocator!,
    startPositionUs: Long
)

Returns a new MediaPeriod identified by periodId.

Unit

Disables the source for the creation of MediaPeriods.

Unit

Enables the source for the creation of MediaPeriods.

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 MediaItem whose media is provided by the source.

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
@UnstableApi
prepareSource(
    caller: MediaSource.MediaSourceCaller!,
    mediaTransferListener: TransferListener?
)

This function is deprecated.

Implement prepareSource instead.

Unit
@UnstableApi
prepareSource(
    caller: MediaSource.MediaSourceCaller!,
    mediaTransferListener: TransferListener?,
    playerId: PlayerId!
)

Registers a MediaSourceCaller.

Unit

Releases the period.

Unit

Unregisters a caller, and disables and releases the source if no longer required.

Unit

Removes a DrmSessionEventListener from the list of listeners which are notified of DRM events for this media source.

Unit

Removes a MediaSourceEventListener from the list of listeners which are notified of media source events.

Unit

Updates the MediaItem for this source.

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.

Parameters
mediaItem: MediaItem!

The new MediaItem.

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 Allocator from which to obtain media buffer allocations.

startPositionUs: Long

The expected start position, in microseconds.

Returns
MediaPeriod!

A new MediaPeriod.

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 MediaSourceCaller disabling the source.

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 MediaSourceCaller enabling the source.

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.

prepareSource

@UnstableApi
fun prepareSource(
    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 MediaSourceCaller to be registered.

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 PlayerId of the player using this media source.

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 MediaSourceCaller to be unregistered.

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.

Parameters
mediaItem: MediaItem!

The new MediaItem.