FakeMediaSource
@UnstableApi
class FakeMediaSource : BaseMediaSource
| kotlin.Any | ||
| ↳ | androidx.media3.exoplayer.source.BaseMediaSource | |
| ↳ | androidx.media3.test.utils.FakeMediaSource |
FakeAdaptiveMediaSource |
Fake |
Fake MediaSource that provides a given timeline. Creating the period will return a FakeMediaPeriod with a TrackGroupArray using the given Formats.
Summary
Nested types |
|---|
class FakeMediaSource.BuilderA builder for |
|
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(timeline: Timeline?, formats: Array<Format!>!)Creates a |
This function is deprecated. Use |
This function is deprecated. Use |
This function is deprecated. Use |
Protected constructors |
|---|
FakeMediaSource(Creates a |
Public functions |
|
|---|---|
Unit |
assertMediaPeriodCreated(mediaPeriodId: MediaSource.MediaPeriodId!)Assert that a media period for the given id has been created. |
Unit |
Assert that the source and all periods have been released. |
Boolean |
canUpdateMediaItem(mediaItem: MediaItem!)Returns whether the |
MediaPeriod! |
createPeriod(Returns a new |
java-static FakeMediaSource! |
createWithWindowId(windowId: Any!)Convenience method to create a |
(Mutable)List<MediaSource.MediaPeriodId!>! |
Returns a list of |
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 |
MediaItem! |
Returns the |
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 |
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 |
Unit |
setNewSourceInfo(newTimeline: Timeline!)Sets a new timeline. |
synchronized Unit |
setNewSourceInfo(newTimeline: Timeline!, sendManifestLoadEvents: Boolean)Sets a new timeline. |
Unit |
setPeriodDefersOnPreparedCallback(Sets whether the created |
Unit |
updateMediaItem(mediaItem: MediaItem!)Updates the |
Protected functions |
|
|---|---|
MediaPeriod! |
@RequiresNonNull(value = "this.timeline")Creates a |
Unit |
releaseMediaPeriod(mediaPeriod: MediaPeriod!)Releases a media period created by |
Unit |
Releases the source, see |
Protected properties |
|
|---|---|
@MonotonicNonNull Timeline! |
Inherited functions |
||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Constants
Public constructors
FakeMediaSource
FakeMediaSource()
Creates a FakeMediaSource with a default FakeTimeline.
Use Builder to create a more configured instance.
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.
Use Builder to create a more configured instance.
FakeMediaSource
FakeMediaSource(
timeline: Timeline?,
drmSessionManager: DrmSessionManager!,
formats: Array<Format!>!
)
FakeMediaSource
FakeMediaSource(
timeline: Timeline?,
drmSessionManager: DrmSessionManager!,
trackDataFactory: FakeMediaPeriod.TrackDataFactory?,
formats: Array<Format!>!
)
FakeMediaSource
FakeMediaSource(
timeline: Timeline?,
drmSessionManager: DrmSessionManager!,
trackDataFactory: FakeMediaPeriod.TrackDataFactory?,
trackGroupArray: TrackGroupArray!
)
Protected constructors
FakeMediaSource
protected FakeMediaSource(
timeline: Timeline?,
drmSessionManager: DrmSessionManager!,
trackDataFactory: FakeMediaPeriod.TrackDataFactory?,
syncSampleTimesUs: LongArray?,
trackGroupArray: TrackGroupArray!
)
Creates a FakeMediaSource. This media source creates FakeMediaPeriods with the provided TrackGroupArray, DrmSessionManager, FakeMediaPeriod.TrackDataFactory, and syncSampleTimesUs. 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.
| 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 |
startPositionUs: Long |
The expected start position, in microseconds. |
| Returns | |
|---|---|
MediaPeriod! |
A new |
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.
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.
| Throws | |
|---|---|
java.io.IOException |
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.
This method is called on the playback thread.
| 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.
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.
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.
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.
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 |
allocator: Allocator! |
An |
mediaSourceEventDispatcher: MediaSourceEventListener.EventDispatcher! |
An |
drmSessionManager: DrmSessionManager! |
A |
drmEventDispatcher: DrmSessionEventListener.EventDispatcher! |
An |
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 |
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.
This method is called on the playback thread.