BaseMediaSource


@UnstableApi
public abstract class BaseMediaSource implements 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

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.

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

Protected fields

@Nullable PlayerId

Public constructors

Public methods

final void
@UnstableApi
addDrmEventListener(
    Handler handler,
    DrmSessionEventListener eventListener
)

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

final void
@UnstableApi
addEventListener(
    Handler handler,
    MediaSourceEventListener eventListener
)

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

final void

Disables the source for the creation of MediaPeriods.

final void

Enables the source for the creation of MediaPeriods.

final void
@UnstableApi
prepareSource(
    MediaSource.MediaSourceCaller caller,
    @Nullable TransferListener mediaTransferListener
)

This method is deprecated.

Implement prepareSource instead.

final void
@UnstableApi
prepareSource(
    MediaSource.MediaSourceCaller caller,
    @Nullable TransferListener mediaTransferListener,
    PlayerId playerId
)

Registers a MediaSourceCaller.

final void

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

final void

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

final void

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

Protected methods

final DrmSessionEventListener.EventDispatcher

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

final DrmSessionEventListener.EventDispatcher
createDrmEventDispatcher(
    int windowIndex,
    @Nullable MediaSource.MediaPeriodId mediaPeriodId
)

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

final MediaSourceEventListener.EventDispatcher

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

final MediaSourceEventListener.EventDispatcher
createEventDispatcher(
    MediaSource.MediaPeriodId mediaPeriodId,
    long mediaTimeOffsetMs
)

This method is deprecated.

Use createEventDispatcher instead.

final MediaSourceEventListener.EventDispatcher
createEventDispatcher(
    int windowIndex,
    @Nullable MediaSource.MediaPeriodId mediaPeriodId
)

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

final MediaSourceEventListener.EventDispatcher
createEventDispatcher(
    int windowIndex,
    @Nullable MediaSource.MediaPeriodId mediaPeriodId,
    long mediaTimeOffsetMs
)

This method is deprecated.

Use createEventDispatcher instead.

void

Disables the source, see disable.

void

Enables the source, see enable.

final PlayerId

Returns the PlayerId of the player using this media source.

final boolean

Returns whether the source is enabled.

final boolean

Returns whether the source has prepareSource called.

abstract void

Starts source preparation and enables the source, see prepareSource.

final void

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

abstract void

Releases the source, see releaseSource.

final void

Sets the PlayerId of the player using this media source.

Inherited methods

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(
    MediaSource.MediaPeriodId id,
    Allocator allocator,
    long startPositionUs
)

Returns a new MediaPeriod identified by periodId.

@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 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 void

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

abstract void

Releases the period.

void

Updates the MediaItem for this source.

Protected fields

playerId

protected @Nullable PlayerId playerId

Public constructors

BaseMediaSource

public BaseMediaSource()

Public methods

addDrmEventListener

@UnstableApi
public final 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
public final 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.

disable

@UnstableApi
public final 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 MediaSourceCaller disabling the source.

enable

@UnstableApi
public final 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 MediaSourceCaller enabling the source.

prepareSource

@UnstableApi
public final void prepareSource(
    MediaSource.MediaSourceCaller caller,
    @Nullable TransferListener mediaTransferListener
)

prepareSource

@UnstableApi
public final void prepareSource(
    MediaSource.MediaSourceCaller caller,
    @Nullable TransferListener mediaTransferListener,
    PlayerId playerId
)

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

@Nullable TransferListener 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.

PlayerId playerId

The PlayerId of the player using this media source.

releaseSource

@UnstableApi
public final 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 MediaSourceCaller to be unregistered.

removeDrmEventListener

@UnstableApi
public final 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
public final 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.

Protected methods

createDrmEventDispatcher

protected final DrmSessionEventListener.EventDispatcher createDrmEventDispatcher(
    @Nullable MediaSource.MediaPeriodId mediaPeriodId
)

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

Parameters
@Nullable MediaSource.MediaPeriodId 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 final DrmSessionEventListener.EventDispatcher createDrmEventDispatcher(
    int windowIndex,
    @Nullable MediaSource.MediaPeriodId mediaPeriodId
)

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

Parameters
int windowIndex

The timeline window index to be reported with the events.

@Nullable MediaSource.MediaPeriodId 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 final MediaSourceEventListener.EventDispatcher createEventDispatcher(@Nullable MediaSource.MediaPeriodId mediaPeriodId)

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

Parameters
@Nullable MediaSource.MediaPeriodId 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 final MediaSourceEventListener.EventDispatcher createEventDispatcher(
    MediaSource.MediaPeriodId mediaPeriodId,
    long mediaTimeOffsetMs
)

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

createEventDispatcher

protected final MediaSourceEventListener.EventDispatcher createEventDispatcher(
    int windowIndex,
    @Nullable MediaSource.MediaPeriodId mediaPeriodId
)

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

Parameters
int windowIndex

The timeline window index to be reported with the events.

@Nullable MediaSource.MediaPeriodId 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 final MediaSourceEventListener.EventDispatcher createEventDispatcher(
    int windowIndex,
    @Nullable MediaSource.MediaPeriodId mediaPeriodId,
    long mediaTimeOffsetMs
)

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

disableInternal

protected void disableInternal()

Disables the source, see disable.

enableInternal

protected void enableInternal()

Enables the source, see enable.

getPlayerId

protected final PlayerId getPlayerId()

Returns the PlayerId of the player using this media source.

Must only be used when the media source is prepared or has a player ID set.

isEnabled

protected final boolean isEnabled()

Returns whether the source is enabled.

prepareSourceCalled

protected final boolean prepareSourceCalled()

Returns whether the source has prepareSource called.

prepareSourceInternal

protected abstract void prepareSourceInternal(@Nullable TransferListener mediaTransferListener)

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

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

refreshSourceInfo

protected final void refreshSourceInfo(Timeline timeline)

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

Parameters
Timeline timeline

The new Timeline.

releaseSourceInternal

protected abstract void releaseSourceInternal()

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

setPlayerId

protected final void setPlayerId(PlayerId playerId)

Sets the PlayerId of the player using this media source.

Parameters
PlayerId playerId

The player ID to be set.