ClippingMediaSource


@UnstableApi
class ClippingMediaSource : WrappingMediaSource


MediaSource that wraps a source and clips its timeline based on specified start/end positions. The wrapped source must consist of a single period.

Summary

Nested types

Thrown when a ClippingMediaSource cannot clip its wrapped source.

@Documented
@Retention(value = RetentionPolicy.SOURCE)
@Target(value = TYPE_USE)
@IntDef(value = )
annotation ClippingMediaSource.IllegalClippingException.Reason

The reason clipping failed.

Public constructors

ClippingMediaSource(mediaSource: MediaSource!, durationUs: Long)

Creates a new clipping source that wraps the specified source and provides samples from the default position for the specified duration.

ClippingMediaSource(
    mediaSource: MediaSource!,
    startPositionUs: Long,
    endPositionUs: Long
)

Creates a new clipping source that wraps the specified source and provides samples between the specified start and end position.

ClippingMediaSource(
    mediaSource: MediaSource!,
    startPositionUs: Long,
    endPositionUs: Long,
    enableInitialDiscontinuity: Boolean,
    allowDynamicClippingUpdates: Boolean,
    relativeToDefaultPosition: Boolean
)

Creates a new clipping source that wraps the specified source.

Public functions

Boolean

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

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

Creates the requested MediaPeriod.

Unit

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

Unit
releasePeriod(mediaPeriod: MediaPeriod!)

Releases a MediaPeriod.

Protected functions

Unit

Called when the child source info has been refreshed.

Unit

Releases the source, see releaseSource.

Inherited functions

From androidx.media3.exoplayer.source.BaseMediaSource
Unit
@UnstableApi
addDrmEventListener(
    handler: Handler!,
    eventListener: DrmSessionEventListener!
)

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

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

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

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 for the creation of MediaPeriods.

Unit

Enables the source for the creation of MediaPeriods.

Boolean

Returns whether the source is enabled.

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

This function is deprecated.

Implement prepareSource instead.

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

Registers a MediaSourceCaller.

Boolean

Returns whether the source has prepareSource called.

Unit

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

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.

From androidx.media3.exoplayer.source.CompositeMediaSource
Unit

Disables a child source.

Unit

Disables the source, see disable.

Unit

Enables a child source.

Unit

Enables the source, see enable.

MediaSource.MediaPeriodId?
getMediaPeriodIdForChildMediaPeriodId(
    @UnknownNull childSourceId: T!,
    mediaPeriodId: MediaSource.MediaPeriodId!
)

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

Long
getMediaTimeForChildMediaTime(
    @UnknownNull childSourceId: T!,
    mediaTimeMs: Long,
    mediaPeriodId: MediaSource.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 childSourceId: T!,
    windowIndex: Int
)

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

abstract Unit
onChildSourceInfoRefreshed(
    @UnknownNull childSourceId: T!,
    mediaSource: MediaSource!,
    newTimeline: Timeline!
)

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

Unit
prepareChildSource(@UnknownNull id: T!, mediaSource: MediaSource!)

Prepares a child source.

Unit

Releases a child source.

From androidx.media3.exoplayer.source.WrappingMediaSource
Unit

Disables the child source.

Unit

Enables the child source.

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.

MediaSource.MediaPeriodId?

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

MediaSource.MediaPeriodId?
getMediaPeriodIdForChildMediaPeriodId(
    childSourceId: Void!,
    mediaPeriodId: MediaSource.MediaPeriodId!
)

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

Long
getMediaTimeForChildMediaTime(
    mediaTimeMs: Long,
    mediaPeriodId: MediaSource.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.

Long
getMediaTimeForChildMediaTime(
    childSourceId: Void!,
    mediaTimeMs: Long,
    mediaPeriodId: MediaSource.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.

Int
getWindowIndexForChildWindowIndex(childSourceId: Void!, windowIndex: Int)

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.

Unit
onChildSourceInfoRefreshed(
    childSourceId: Void!,
    mediaSource: MediaSource!,
    newTimeline: Timeline!
)

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

Unit

Prepares the wrapped child source.

Unit

Starts source preparation and enables the source, see prepareSource.

Unit
prepareSourceInternal(mediaTransferListener: TransferListener?)

Starts source preparation and enables the source, see prepareSource.

Unit

Releases the child source.

Unit

Updates the for this source.

Public constructors

ClippingMediaSource

ClippingMediaSource(mediaSource: MediaSource!, durationUs: Long)

Creates a new clipping source that wraps the specified source and provides samples from the default position for the specified duration.

Parameters
mediaSource: MediaSource!

The single-period source to wrap.

durationUs: Long

The duration from the default position in the window in mediaSource's timeline at which to stop providing samples. Specifying a duration that exceeds the mediaSource's duration will result in the end of the source not being clipped.

ClippingMediaSource

ClippingMediaSource(
    mediaSource: MediaSource!,
    startPositionUs: Long,
    endPositionUs: Long
)

Creates a new clipping source that wraps the specified source and provides samples between the specified start and end position.

Parameters
mediaSource: MediaSource!

The single-period source to wrap.

startPositionUs: Long

The start position within mediaSource's window at which to start providing samples, in microseconds.

endPositionUs: Long

The end position within mediaSource's window at which to stop providing samples, in microseconds. Specify TIME_END_OF_SOURCE to provide samples from the specified start point up to the end of the source. Specifying a position that exceeds the mediaSource's duration will also result in the end of the source not being clipped.

ClippingMediaSource

ClippingMediaSource(
    mediaSource: MediaSource!,
    startPositionUs: Long,
    endPositionUs: Long,
    enableInitialDiscontinuity: Boolean,
    allowDynamicClippingUpdates: Boolean,
    relativeToDefaultPosition: Boolean
)

Creates a new clipping source that wraps the specified source.

If the start point is guaranteed to be a key frame, pass false to enableInitialPositionDiscontinuity to suppress an initial discontinuity when a period is first read from.

For live streams, if the clipping positions should move with the live window, pass true to allowDynamicClippingUpdates. Otherwise, the live stream ends when the playback reaches endPositionUs in the last reported live window at the time a media period was created.

Parameters
mediaSource: MediaSource!

The single-period source to wrap.

startPositionUs: Long

The start position at which to start providing samples, in microseconds. If relativeToDefaultPosition is false, this position is relative to the start of the window in mediaSource's timeline. If relativeToDefaultPosition is true, this position is relative to the default position in the window in mediaSource's timeline.

endPositionUs: Long

The end position at which to stop providing samples, in microseconds. Specify TIME_END_OF_SOURCE to provide samples from the specified start point up to the end of the source. Specifying a position that exceeds the mediaSource's duration will also result in the end of the source not being clipped. If relativeToDefaultPosition is false, the specified position is relative to the start of the window in mediaSource's timeline. If relativeToDefaultPosition is true, this position is relative to the default position in the window in mediaSource's timeline.

enableInitialDiscontinuity: Boolean

Whether the initial discontinuity should be enabled.

allowDynamicClippingUpdates: Boolean

Whether the clipping of active media periods moves with a live window. If false, playback ends when it reaches endPositionUs in the last reported live window at the time a media period was created.

relativeToDefaultPosition: Boolean

Whether startPositionUs and endPositionUs are relative to the default position in the window in mediaSource's timeline.

Public functions

canUpdateMediaItem

fun canUpdateMediaItem(mediaItem: MediaItem!): Boolean

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

fun createPeriod(
    id: MediaSource.MediaPeriodId!,
    allocator: Allocator!,
    startPositionUs: Long
): MediaPeriod!

Creates the requested MediaPeriod.

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

See also
createPeriod

maybeThrowSourceInfoRefreshError

fun maybeThrowSourceInfoRefreshError(): Unit

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

fun releasePeriod(mediaPeriod: MediaPeriod!): Unit

Releases a MediaPeriod.

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

See also
releasePeriod

Protected functions

onChildSourceInfoRefreshed

protected fun onChildSourceInfoRefreshed(newTimeline: Timeline!): Unit

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
newTimeline: Timeline!

The timeline of the child source.

releaseSourceInternal

protected fun releaseSourceInternal(): Unit

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