SilenceMediaSource


@UnstableApi
public final class SilenceMediaSource extends BaseMediaSource


Media source with a single period consisting of silent raw audio of a given duration.

Summary

Nested types

public final class SilenceMediaSource.Factory

Factory for SilenceMediaSources.

Constants

static final String
MEDIA_ID = "SilenceMediaSource"

The media id used by any media item of silence media sources.

Public fields

MediaItem
@GuardedBy(value = "this")
mediaItem

Public constructors

SilenceMediaSource(long durationUs)

Creates a new media source providing silent audio of the given duration.

Public methods

boolean

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

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

Returns a new MediaPeriod identified by periodId.

synchronized MediaItem

Returns the MediaItem whose media is provided by the source.

void

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

void

Releases the period.

synchronized void

Updates the MediaItem for this source.

Protected methods

void

Starts source preparation and enables the source, see prepareSource.

void

Releases the source, see releaseSource.

Inherited methods

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

void

Disables the source, see disable.

final void

Enables the source for the creation of MediaPeriods.

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

boolean

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

Constants

MEDIA_ID

public static final String MEDIA_ID = "SilenceMediaSource"

The media id used by any media item of silence media sources.

Public fields

mediaItem

@GuardedBy(value = "this")
public MediaItem mediaItem

Public constructors

SilenceMediaSource

public SilenceMediaSource(long durationUs)

Creates a new media source providing silent audio of the given duration.

Parameters
long durationUs

The duration of silent audio to output, in microseconds.

Public methods

canUpdateMediaItem

public boolean canUpdateMediaItem(MediaItem mediaItem)

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

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

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

The identifier of the period.

Allocator allocator

An Allocator from which to obtain media buffer allocations.

long startPositionUs

The expected start position, in microseconds.

Returns
MediaPeriod

A new MediaPeriod.

getMediaItem

synchronized public MediaItem getMediaItem()

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.

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.

releasePeriod

public void releasePeriod(MediaPeriod mediaPeriod)

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.

updateMediaItem

synchronized public void updateMediaItem(MediaItem mediaItem)

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.

Protected methods

prepareSourceInternal

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

releaseSourceInternal

protected void releaseSourceInternal()

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