MaskingMediaSource


@UnstableApi
public final class MaskingMediaSource extends WrappingMediaSource


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

Summary

Nested types

A timeline with one dynamic window with a period of indeterminate duration.

Public constructors

MaskingMediaSource(MediaSource mediaSource, boolean useLazyPreparation)

Creates the masking media source.

Public methods

boolean

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

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

Creates the requested MediaPeriod.

Timeline

Returns the Timeline.

void

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

void

Starts source preparation and enables the source, see prepareSource.

void

Releases a MediaPeriod.

void

Releases the source, see releaseSource.

void

Updates the for this source.

Protected methods

@Nullable MediaSource.MediaPeriodId

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

void

Called when the child source info has been refreshed.

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.

@Nullable MediaSource.MediaPeriodId
getMediaPeriodIdForChildMediaPeriodId(
    @UnknownNull T childSourceId,
    MediaSource.MediaPeriodId mediaPeriodId
)

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

long
getMediaTimeForChildMediaTime(
    @UnknownNull T 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
getWindowIndexForChildWindowIndex(
    @UnknownNull T childSourceId,
    int windowIndex
)

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

abstract void
onChildSourceInfoRefreshed(
    @UnknownNull T childSourceId,
    MediaSource mediaSource,
    Timeline newTimeline
)

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

final void

Prepares a child source.

final void

Releases a child source.

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

Disables the child source.

final void

Enables the child source.

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

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.

boolean

Returns true if the media source is guaranteed to never have zero or more than one window.

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.

final void

Starts source preparation and enables the source, see prepareSource.

final void

Releases the child source.

Public constructors

MaskingMediaSource

public MaskingMediaSource(MediaSource mediaSource, boolean useLazyPreparation)

Creates the masking media source.

Parameters
MediaSource mediaSource

A MediaSource.

boolean useLazyPreparation

Whether the mediaSource is prepared lazily. If false, all manifest loads and other initial preparation steps happen immediately. If true, these initial preparations are triggered only when the player starts buffering the media.

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

getTimeline

public Timeline getTimeline()

Returns the Timeline.

maybeThrowSourceInfoRefreshError

public void maybeThrowSourceInfoRefreshError()

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.

prepareSourceInternal

public void prepareSourceInternal()

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

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

releaseSourceInternal

public void releaseSourceInternal()

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

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

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.

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.