@UnstableApi
class FakeMediaSource : BaseMediaSource

Known direct subclasses
FakeAdaptiveMediaSource

Fake MediaSource that provides a given timeline.


Fake MediaSource that provides a given timeline. Creating the period will return a with a TrackGroupArray using the given Formats.

Summary

Nested types

A forwarding timeline to provide an initial timeline for fake multi window sources.

Constants

const MediaItem!

The media item used by the fake media source.

Public constructors

Creates a FakeMediaSource with a default FakeTimeline.

FakeMediaSource(timeline: Timeline?, formats: Array<Format!>!)

Creates a FakeMediaSource.

FakeMediaSource(
    timeline: Timeline?,
    drmSessionManager: DrmSessionManager!,
    formats: Array<Format!>!
)

Creates a FakeMediaSource.

FakeMediaSource(
    timeline: Timeline?,
    drmSessionManager: DrmSessionManager!,
    trackDataFactory: FakeMediaPeriod.TrackDataFactory?,
    formats: Array<Format!>!
)

Creates a FakeMediaSource.

FakeMediaSource(
    timeline: Timeline?,
    drmSessionManager: DrmSessionManager!,
    trackDataFactory: FakeMediaPeriod.TrackDataFactory?,
    trackGroupArray: TrackGroupArray!
)

Creates a FakeMediaSource.

Public functions

Unit

Assert that a media period for the given id has been created.

Unit

Assert that the source and all periods have been released.

Boolean

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

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

Returns a new MediaPeriod identified by periodId.

java-static FakeMediaSource!
createWithWindowId(windowId: Any!)

Convenience method to create a FakeMediaSource with the given window id.

(Mutable)List<MediaSource.MediaPeriodId!>!

Returns a list of MediaPeriodIds, with one element for each created media period.

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.

MediaPeriod!

Returns the last created active MediaPeriod.

MediaItem!

Returns the MediaItem whose media is provided by the source.

Boolean

Returns whether the source is currently prepared.

Boolean

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

Unit

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

synchronized Unit
prepareSourceInternal(mediaTransferListener: TransferListener?)

Starts source preparation and enables the source, see prepareSource.

Unit
releasePeriod(mediaPeriod: MediaPeriod!)

Releases the period.

synchronized Unit
setAllowPreparation(allowPreparation: Boolean)

Sets whether the next call to prepareSource is allowed to finish.

Unit
setCanUpdateMediaItems(canUpdateMediaItems: Boolean)

Sets whether the source allows to update its MediaItem via updateMediaItem.

Unit
setNewSourceInfo(newTimeline: Timeline!)

Sets a new timeline.

synchronized Unit
setNewSourceInfo(newTimeline: Timeline!, sendManifestLoadEvents: Boolean)

Sets a new timeline.

Unit
setPeriodDefersOnPreparedCallback(
    periodDefersOnPreparedCallback: Boolean
)

Sets whether the created period should defer to call onPrepared.

Unit

Updates the MediaItem for this source.

Protected functions

MediaPeriod!
@RequiresNonNull(value = "this.timeline")
createMediaPeriod(
    id: MediaSource.MediaPeriodId!,
    trackGroupArray: TrackGroupArray!,
    allocator: Allocator!,
    mediaSourceEventDispatcher: MediaSourceEventListener.EventDispatcher!,
    drmSessionManager: DrmSessionManager!,
    drmEventDispatcher: DrmSessionEventListener.EventDispatcher!,
    transferListener: TransferListener?
)

Creates a MediaPeriod for this media source.

Unit

Releases a media period created by createMediaPeriod.

Unit

Releases the source, see releaseSource.

Inherited functions

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

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

Unit
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

Disables the source, see disable.

Unit

Enables the source for the creation of MediaPeriods.

Unit

Enables the source, see enable.

Boolean

Returns whether the source is enabled.

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

This function is deprecated.

Implement prepareSource instead.

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

Constants

FAKE_MEDIA_ITEM

const val FAKE_MEDIA_ITEMMediaItem!

The media item used by the fake media source.

Public constructors

FakeMediaSource

FakeMediaSource()

Creates a FakeMediaSource with a default FakeTimeline.

FakeMediaSource

FakeMediaSource(timeline: Timeline?, formats: Array<Format!>!)

Creates a FakeMediaSource. This media source creates FakeMediaPeriods with a TrackGroupArray using the given Formats. The provided Timeline may be null to prevent an immediate source info refresh message when preparing the media source. It can be manually set later using setNewSourceInfo.

FakeMediaSource

FakeMediaSource(
    timeline: Timeline?,
    drmSessionManager: DrmSessionManager!,
    formats: Array<Format!>!
)

Creates a FakeMediaSource. This media source creates FakeMediaPeriods with a TrackGroupArray using the given Formats. It passes drmSessionManager into the created periods. The provided Timeline may be null to prevent an immediate source info refresh message when preparing the media source. It can be manually set later using setNewSourceInfo.

FakeMediaSource

FakeMediaSource(
    timeline: Timeline?,
    drmSessionManager: DrmSessionManager!,
    trackDataFactory: FakeMediaPeriod.TrackDataFactory?,
    formats: Array<Format!>!
)

Creates a FakeMediaSource. This media source creates FakeMediaPeriods with a TrackGroupArray using the given Formats. It passes drmSessionManager and trackDataFactory into the created periods. The provided Timeline may be null to prevent an immediate source info refresh message when preparing the media source. It can be manually set later using setNewSourceInfo.

FakeMediaSource

FakeMediaSource(
    timeline: Timeline?,
    drmSessionManager: DrmSessionManager!,
    trackDataFactory: FakeMediaPeriod.TrackDataFactory?,
    trackGroupArray: TrackGroupArray!
)

Creates a FakeMediaSource. This media source creates FakeMediaPeriods with the provided TrackGroupArray, DrmSessionManager and . The provided Timeline may be null to prevent an immediate source info refresh message when preparing the media source. It can be manually set later using setNewSourceInfo.

Public functions

assertMediaPeriodCreated

fun assertMediaPeriodCreated(mediaPeriodId: MediaSource.MediaPeriodId!): Unit

Assert that a media period for the given id has been created.

assertReleased

fun assertReleased(): Unit

Assert that the source and all periods have been released.

canUpdateMediaItem

fun canUpdateMediaItem(mediaItem: MediaItem!): Boolean

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

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

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

The identifier of the period.

allocator: Allocator!

An Allocator from which to obtain media buffer allocations.

startPositionUs: Long

The expected start position, in microseconds.

Returns
MediaPeriod!

A new MediaPeriod.

createWithWindowId

java-static fun createWithWindowId(windowId: Any!): FakeMediaSource!

Convenience method to create a FakeMediaSource with the given window id.

getCreatedMediaPeriods

fun getCreatedMediaPeriods(): (Mutable)List<MediaSource.MediaPeriodId!>!

Returns a list of MediaPeriodIds, with one element for each created media period.

getInitialTimeline

fun getInitialTimeline(): 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.

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.

getLastCreatedActiveMediaPeriod

fun getLastCreatedActiveMediaPeriod(): MediaPeriod!

Returns the last created active MediaPeriod.

Must only be called if the source has created at least one period and it hasn't been released.

getMediaItem

fun getMediaItem(): MediaItem!

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.

isPrepared

fun isPrepared(): Boolean

Returns whether the source is currently prepared.

isSingleWindow

fun isSingleWindow(): Boolean

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.

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.

prepareSourceInternal

synchronized fun prepareSourceInternal(mediaTransferListener: TransferListener?): Unit

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

Parameters
mediaTransferListener: TransferListener?

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.

releasePeriod

fun releasePeriod(mediaPeriod: MediaPeriod!): Unit

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.

setAllowPreparation

synchronized fun setAllowPreparation(allowPreparation: Boolean): Unit

Sets whether the next call to prepareSource is allowed to finish. If not allowed, a later call to this method with allowPreparation set to true will finish the preparation.

Parameters
allowPreparation: Boolean

Whether preparation is allowed to finish.

setCanUpdateMediaItems

fun setCanUpdateMediaItems(canUpdateMediaItems: Boolean): Unit

Sets whether the source allows to update its MediaItem via updateMediaItem.

Parameters
canUpdateMediaItems: Boolean

Whether a MediaItem update is possible.

setNewSourceInfo

fun setNewSourceInfo(newTimeline: Timeline!): Unit

Sets a new timeline. If the source is already prepared, this triggers a source info refresh message being sent to the listener.

Parameters
newTimeline: Timeline!

The new Timeline.

setNewSourceInfo

synchronized fun setNewSourceInfo(newTimeline: Timeline!, sendManifestLoadEvents: Boolean): Unit

Sets a new timeline. If the source is already prepared, this triggers a source info refresh message being sent to the listener.

Must only be called if preparation is allowed.

Parameters
newTimeline: Timeline!

The new Timeline.

sendManifestLoadEvents: Boolean

Whether to treat this as a manifest refresh and send manifest load events to listeners.

setPeriodDefersOnPreparedCallback

fun setPeriodDefersOnPreparedCallback(
    periodDefersOnPreparedCallback: Boolean
): Unit

Sets whether the created period should defer to call onPrepared. If set to true, onPrepared should be called only after setPreparationComplete has been called, otherwise the preparation completes immediately.

updateMediaItem

fun updateMediaItem(mediaItem: MediaItem!): Unit

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 functions

createMediaPeriod

@RequiresNonNull(value = "this.timeline")
protected fun createMediaPeriod(
    id: MediaSource.MediaPeriodId!,
    trackGroupArray: TrackGroupArray!,
    allocator: Allocator!,
    mediaSourceEventDispatcher: MediaSourceEventListener.EventDispatcher!,
    drmSessionManager: DrmSessionManager!,
    drmEventDispatcher: DrmSessionEventListener.EventDispatcher!,
    transferListener: TransferListener?
): MediaPeriod!

Creates a MediaPeriod for this media source.

Parameters
id: MediaSource.MediaPeriodId!

The identifier of the period.

trackGroupArray: TrackGroupArray!

The TrackGroupArray supported by the media period.

allocator: Allocator!

An Allocator from which to obtain media buffer allocations.

mediaSourceEventDispatcher: MediaSourceEventListener.EventDispatcher!

An MediaSourceEventListener.EventDispatcher to dispatch media source events.

drmSessionManager: DrmSessionManager!

A DrmSessionManager to allow DRM interactions.

drmEventDispatcher: DrmSessionEventListener.EventDispatcher!

An MediaSourceEventListener.EventDispatcher to dispatch DRM events.

transferListener: TransferListener?

The transfer listener which should be informed of any data transfers. May be null if no listener is available.

Returns
MediaPeriod!

A new MediaPeriod.

releaseMediaPeriod

protected fun releaseMediaPeriod(mediaPeriod: MediaPeriod!): Unit

Releases a media period created by createMediaPeriod.

releaseSourceInternal

protected fun releaseSourceInternal(): Unit

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

Protected properties

timeline

@MonotonicNonNull
protected val timeline: @MonotonicNonNull Timeline!