BaseMediaSource


@UnstableApi
abstract class BaseMediaSource : MediaSource

Known direct subclasses
CompositeMediaSource

Composite MediaSource consisting of multiple child sources.

DashMediaSource

A DASH MediaSource.

ExternallyLoadedMediaSource

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

FakeMediaSource

Fake MediaSource that provides a given timeline.

HlsMediaSource

An HLS MediaSource.

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

Loads data at a given Uri as a single sample belonging to a single MediaPeriod.

SsMediaSource

A SmoothStreaming MediaSource.

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.

ConcatenatingMediaSource2

Concatenates multiple MediaSources, combining everything in one single .

ConcatenatingMediaSource

This class is deprecated.

Use playlist modification methods like addMediaItem instead.

FakeAdaptiveMediaSource

Fake MediaSource that provides a given timeline.

FilteringMediaSource

A MediaSource that filters the available track types.

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.

WrappingMediaSource

An abstract MediaSource wrapping a single child MediaSource.


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

Whenever an implementing subclass needs to provide a new timeline, it must call refreshSourceInfo to notify all listeners.

Summary

Public constructors

Public functions

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

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

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

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

Unit

Disables the source for the creation of MediaPeriods.

Unit

Enables the source for the creation of MediaPeriods.

Unit
prepareSource(
    caller: MediaSource.MediaSourceCaller!,
    mediaTransferListener: TransferListener?
)

This function is deprecated.

Implement prepareSource instead.

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

Registers a MediaSourceCaller.

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.

Protected functions

DrmSessionEventListener.EventDispatcher!

Returns a DrmSessionEventListener.EventDispatcher which dispatches all events to the registered listeners with the specified MediaPeriodId

DrmSessionEventListener.EventDispatcher!
createDrmEventDispatcher(
    windowIndex: Int,
    mediaPeriodId: MediaSource.MediaPeriodId?
)

Returns a DrmSessionEventListener.EventDispatcher which dispatches all events to the registered listeners with the specified window index and MediaPeriodId.

MediaSourceEventListener.EventDispatcher!

Returns a MediaSourceEventListener.EventDispatcher which dispatches all events to the registered listeners with the specified MediaPeriodId.

MediaSourceEventListener.EventDispatcher!
createEventDispatcher(
    mediaPeriodId: MediaSource.MediaPeriodId!,
    mediaTimeOffsetMs: Long
)

This function is deprecated.

Use createEventDispatcher instead.

MediaSourceEventListener.EventDispatcher!
createEventDispatcher(
    windowIndex: Int,
    mediaPeriodId: MediaSource.MediaPeriodId?
)

Returns a MediaSourceEventListener.EventDispatcher which dispatches all events to the registered listeners with the specified window index and MediaPeriodId.

MediaSourceEventListener.EventDispatcher!
createEventDispatcher(
    windowIndex: Int,
    mediaPeriodId: MediaSource.MediaPeriodId?,
    mediaTimeOffsetMs: Long
)

This function is deprecated.

Use createEventDispatcher instead.

Unit

Disables the source, see disable.

Unit

Enables the source, see enable.

Boolean

Returns whether the source is enabled.

Boolean

Returns whether the source has prepareSource called.

abstract Unit
prepareSourceInternal(mediaTransferListener: TransferListener?)

Starts source preparation and enables the source, see prepareSource.

Unit

Updates timeline and manifest and notifies all listeners of the update.

abstract Unit

Releases the source, see releaseSource.

Protected properties

PlayerId?

Inherited functions

From androidx.media3.exoplayer.source.MediaSource
Boolean

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

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

Returns a new MediaPeriod identified by periodId.

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

abstract Unit

Throws any pending error encountered while loading or refreshing source information.

abstract Unit

Releases the period.

Unit

Updates the MediaItem for this source.

Public constructors

BaseMediaSource

BaseMediaSource()

Public functions

addDrmEventListener

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

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.

disable

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

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.

prepareSource

fun prepareSource(
    caller: MediaSource.MediaSourceCaller!,
    mediaTransferListener: TransferListener?
): Unit

prepareSource

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.

releaseSource

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

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

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.

Protected functions

createDrmEventDispatcher

protected fun createDrmEventDispatcher(mediaPeriodId: MediaSource.MediaPeriodId?): DrmSessionEventListener.EventDispatcher!

Returns a DrmSessionEventListener.EventDispatcher which dispatches all events to the registered listeners with the specified MediaPeriodId

Parameters
mediaPeriodId: MediaSource.MediaPeriodId?

The MediaPeriodId to be reported with the events. May be null, if the events do not belong to a specific media period.

Returns
DrmSessionEventListener.EventDispatcher!

An event dispatcher with pre-configured media period id.

createDrmEventDispatcher

protected fun createDrmEventDispatcher(
    windowIndex: Int,
    mediaPeriodId: MediaSource.MediaPeriodId?
): DrmSessionEventListener.EventDispatcher!

Returns a DrmSessionEventListener.EventDispatcher which dispatches all events to the registered listeners with the specified window index and MediaPeriodId.

Parameters
windowIndex: Int

The timeline window index to be reported with the events.

mediaPeriodId: MediaSource.MediaPeriodId?

The MediaPeriodId to be reported with the events. May be null, if the events do not belong to a specific media period.

Returns
DrmSessionEventListener.EventDispatcher!

An event dispatcher with pre-configured media period id and time offset.

createEventDispatcher

protected fun createEventDispatcher(mediaPeriodId: MediaSource.MediaPeriodId?): MediaSourceEventListener.EventDispatcher!

Returns a MediaSourceEventListener.EventDispatcher which dispatches all events to the registered listeners with the specified MediaPeriodId.

Parameters
mediaPeriodId: MediaSource.MediaPeriodId?

The MediaPeriodId to be reported with the events. May be null, if the events do not belong to a specific media period.

Returns
MediaSourceEventListener.EventDispatcher!

An event dispatcher with pre-configured media period id.

createEventDispatcher

protected fun createEventDispatcher(
    mediaPeriodId: MediaSource.MediaPeriodId!,
    mediaTimeOffsetMs: Long
): MediaSourceEventListener.EventDispatcher!

Note: The mediaTimeOffsetMs passed to this method is ignored and not added to media times in any way.

createEventDispatcher

protected fun createEventDispatcher(
    windowIndex: Int,
    mediaPeriodId: MediaSource.MediaPeriodId?
): MediaSourceEventListener.EventDispatcher!

Returns a MediaSourceEventListener.EventDispatcher which dispatches all events to the registered listeners with the specified window index and MediaPeriodId.

Parameters
windowIndex: Int

The timeline window index to be reported with the events.

mediaPeriodId: MediaSource.MediaPeriodId?

The MediaPeriodId to be reported with the events. May be null, if the events do not belong to a specific media period.

Returns
MediaSourceEventListener.EventDispatcher!

An event dispatcher with pre-configured media period id.

createEventDispatcher

protected fun createEventDispatcher(
    windowIndex: Int,
    mediaPeriodId: MediaSource.MediaPeriodId?,
    mediaTimeOffsetMs: Long
): MediaSourceEventListener.EventDispatcher!

Note: The mediaTimeOffsetMs passed to this method is ignored and not added to media times in any way.

disableInternal

protected fun disableInternal(): Unit

Disables the source, see disable.

enableInternal

protected fun enableInternal(): Unit

Enables the source, see enable.

isEnabled

protected fun isEnabled(): Boolean

Returns whether the source is enabled.

prepareSourceCalled

protected fun prepareSourceCalled(): Boolean

Returns whether the source has prepareSource called.

prepareSourceInternal

protected abstract fun prepareSourceInternal(mediaTransferListener: TransferListener?): Unit

Starts source preparation and enables the source, see prepareSource. This method is called at most once until the next call to releaseSourceInternal.

Parameters
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 usually be only informed of transfers related to the media loads and not of auxiliary loads for manifests and other data.

refreshSourceInfo

protected fun refreshSourceInfo(timeline: Timeline!): Unit

Updates timeline and manifest and notifies all listeners of the update.

Parameters
timeline: Timeline!

The new Timeline.

releaseSourceInternal

protected abstract fun releaseSourceInternal(): Unit

Releases the source, see releaseSource. This method is called exactly once after each call to prepareSourceInternal.

Protected properties

playerId

protected var playerIdPlayerId?