WrappingMediaSource


@UnstableApi
public abstract class WrappingMediaSource extends CompositeMediaSource

Known direct subclasses
ClippingMediaSource

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

FilteringMediaSource

A MediaSource that filters the available track types.

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.

PreloadMediaSource

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


An abstract MediaSource wrapping a single child MediaSource.

The implementation may want to override the following methods as needed:

Other methods like prepareSourceInternal, enableInternal, disableInternal or releaseSourceInternal only need to be overwritten if required for resource management.

Summary

Protected fields

final MediaSource

The wrapped child MediaSource.

Protected constructors

Creates the wrapping MediaSource.

Public methods

boolean

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

MediaPeriod
createPeriod(
    MediaSource.MediaPeriodId id,
    Allocator allocator,
    long startPositionUs
)

Creates the requested MediaPeriod.

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

MediaItem

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

void

Releases a MediaPeriod.

void

Updates the for this source.

Protected methods

final void

Disables the child source.

final void

Enables the child source.

@Nullable MediaSource.MediaPeriodId

Returns the MediaPeriodId in the wrapping source corresponding to the specified in a child source.

final @Nullable MediaSource.MediaPeriodId
getMediaPeriodIdForChildMediaPeriodId(
    Void childSourceId,
    MediaSource.MediaPeriodId mediaPeriodId
)

Returns the MediaPeriodId in the composite source corresponding to the specified in a child source.

long
getMediaTimeForChildMediaTime(
    long mediaTimeMs,
    @Nullable MediaSource.MediaPeriodId mediaPeriodId
)

Returns the media time in the MediaPeriod of the wrapping source corresponding to the specified media time in the MediaPeriod of the child source.

final long
getMediaTimeForChildMediaTime(
    Void childSourceId,
    long mediaTimeMs,
    @Nullable MediaSource.MediaPeriodId mediaPeriodId
)

Returns the media time in the MediaPeriod of the composite source corresponding to the specified media time in the MediaPeriod of the child source.

int

Returns the window index in the wrapping source corresponding to the specified window index in a child source.

final int
getWindowIndexForChildWindowIndex(Void childSourceId, int windowIndex)

Returns the window index in the composite source corresponding to the specified window index in a child source.

void

Called when the child source info has been refreshed.

final void
onChildSourceInfoRefreshed(
    Void childSourceId,
    MediaSource mediaSource,
    Timeline newTimeline
)

Called when the source info of a child source has been refreshed.

final void

Prepares the wrapped child source.

void

Starts source preparation and enables the source, see prepareSource.

final void

Starts source preparation and enables the source, see prepareSource.

final void

Releases the child source.

Inherited methods

From androidx.media3.exoplayer.source.BaseMediaSource
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.

final void
addEventListener(
    Handler handler,
    MediaSourceEventListener eventListener
)

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

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.

final void

Disables the source for the creation of MediaPeriods.

final void

Enables the source for the creation of MediaPeriods.

final PlayerId

Returns the PlayerId of the player using this media source.

final boolean

Returns whether the source is enabled.

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

This method is deprecated.

Implement prepareSource instead.

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

Registers a MediaSourceCaller.

final boolean

Returns whether the source has prepareSource called.

final void

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

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.

final void

Sets the PlayerId of the player using this media source.

From androidx.media3.exoplayer.source.CompositeMediaSource
final void

Disables a child source.

void

Disables the source, see disable.

final void

Enables a child source.

void

Enables the source, see enable.

void

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

final void

Prepares a child source.

final void

Releases a child source.

void

Releases the source, see releaseSource.

Protected fields

mediaSource

protected final MediaSource mediaSource

The wrapped child MediaSource.

Protected constructors

WrappingMediaSource

protected WrappingMediaSource(MediaSource mediaSource)

Creates the wrapping MediaSource.

Parameters
MediaSource mediaSource

The wrapped child MediaSource.

Public methods

canUpdateMediaItem

public boolean canUpdateMediaItem(MediaItem mediaItem)

Returns whether the 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.

This method can be overridden to change whether the MediaItem of the child source can be updated.

createPeriod

public MediaPeriod createPeriod(
    MediaSource.MediaPeriodId id,
    Allocator allocator,
    long startPositionUs
)

Creates the requested MediaPeriod.

This method typically forwards to the wrapped media source and optionally wraps the returned MediaPeriod.

See also
createPeriod

getInitialTimeline

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

public MediaItem getMediaItem()

Returns the whose media is provided by the source.

Should not be called directly from application code.

This method must be called on the application thread.

This method can be overridden to amend the MediaItem of the child source. It is only used before the child source is prepared.

isSingleWindow

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

releasePeriod

public void releasePeriod(MediaPeriod mediaPeriod)

Releases a MediaPeriod.

This method typically forwards to the wrapped media source and optionally unwraps the provided MediaPeriod.

See also
releasePeriod

updateMediaItem

public void updateMediaItem(MediaItem mediaItem)

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

This method can be overridden to change how the MediaItem of the child source is updated.

Protected methods

disableChildSource

protected final void disableChildSource()

Disables the child source.

enableChildSource

protected final void enableChildSource()

Enables the child source.

getMediaPeriodIdForChildMediaPeriodId

protected @Nullable MediaSource.MediaPeriodId getMediaPeriodIdForChildMediaPeriodId(
    MediaSource.MediaPeriodId mediaPeriodId
)

Returns the MediaPeriodId in the wrapping source corresponding to the specified in a child source. The default implementation does not change the media period id.

Parameters
MediaSource.MediaPeriodId mediaPeriodId

A MediaPeriodId of the child source.

Returns
@Nullable MediaSource.MediaPeriodId

The corresponding MediaPeriodId in the wrapping source. Null if no corresponding media period id can be determined.

getMediaPeriodIdForChildMediaPeriodId

protected final @Nullable MediaSource.MediaPeriodId getMediaPeriodIdForChildMediaPeriodId(
    Void childSourceId,
    MediaSource.MediaPeriodId mediaPeriodId
)

Returns the MediaPeriodId in the composite source corresponding to the specified in a child source. The default implementation does not change the media period id.

Parameters
Void childSourceId

The unique id used to prepare the child source.

MediaSource.MediaPeriodId mediaPeriodId

A MediaPeriodId of the child source.

Returns
@Nullable MediaSource.MediaPeriodId

The corresponding MediaPeriodId in the composite source. Null if no corresponding media period id can be determined.

getMediaTimeForChildMediaTime

protected long getMediaTimeForChildMediaTime(
    long mediaTimeMs,
    @Nullable MediaSource.MediaPeriodId mediaPeriodId
)

Returns the media time in the MediaPeriod of the wrapping source corresponding to the specified media time in the MediaPeriod of the child source. The default implementation does not change the media time.

Parameters
long mediaTimeMs

A media time in the MediaPeriod of the child source, in milliseconds.

@Nullable MediaSource.MediaPeriodId mediaPeriodId

The MediaPeriodId of the MediaPeriod of the child source, or null if the time does not relate to a specific MediaPeriod.

Returns
long

The corresponding media time in the MediaPeriod of the wrapping source, in milliseconds.

getMediaTimeForChildMediaTime

protected final long getMediaTimeForChildMediaTime(
    Void childSourceId,
    long mediaTimeMs,
    @Nullable MediaSource.MediaPeriodId mediaPeriodId
)

Returns the media time in the MediaPeriod of the composite source corresponding to the specified media time in the MediaPeriod of the child source. The default implementation does not change the media time.

Parameters
Void childSourceId

The unique id used to prepare the child source.

long mediaTimeMs

A media time in the MediaPeriod of the child source, in milliseconds.

@Nullable MediaSource.MediaPeriodId mediaPeriodId

The MediaPeriodId of the MediaPeriod of the child source, or null if the time does not relate to a specific MediaPeriod.

Returns
long

The corresponding media time in the MediaPeriod of the composite source, in milliseconds.

getWindowIndexForChildWindowIndex

protected int getWindowIndexForChildWindowIndex(int windowIndex)

Returns the window index in the wrapping source corresponding to the specified window index in a child source. The default implementation does not change the window index.

Parameters
int windowIndex

A window index of the child source.

Returns
int

The corresponding window index in the wrapping source.

getWindowIndexForChildWindowIndex

protected final int getWindowIndexForChildWindowIndex(Void childSourceId, int windowIndex)

Returns the window index in the composite source corresponding to the specified window index in a child source. The default implementation does not change the window index.

Parameters
Void childSourceId

The unique id used to prepare the child source.

int windowIndex

A window index of the child source.

Returns
int

The corresponding window index in the composite source.

onChildSourceInfoRefreshed

protected void onChildSourceInfoRefreshed(Timeline newTimeline)

Called when the child source info has been refreshed.

This Timeline can be amended if needed, for example using . The Timeline for the wrapping source needs to be published with refreshSourceInfo.

Parameters
Timeline newTimeline

The timeline of the child source.

onChildSourceInfoRefreshed

protected final void onChildSourceInfoRefreshed(
    Void childSourceId,
    MediaSource mediaSource,
    Timeline newTimeline
)

Called when the source info of a child source has been refreshed.

Parameters
Void childSourceId

The unique id used to prepare the child source.

MediaSource mediaSource

The child source whose source info has been refreshed.

Timeline newTimeline

The timeline of the child source.

prepareChildSource

protected final void prepareChildSource()

Prepares the wrapped child source.

onChildSourceInfoRefreshed will be called when the child source updates its timeline.

If sources aren't explicitly released with releaseChildSource they will be released in releaseSourceInternal.

prepareSourceInternal

protected void prepareSourceInternal()

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

prepareSourceInternal

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

releaseChildSource

protected final void releaseChildSource()

Releases the child source.