FakeMediaSource
@UnstableApi
public class FakeMediaSource extends BaseMediaSource
| java.lang.Object | ||
| ↳ | 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 |
|---|
public class FakeMediaSource.BuilderA builder for |
public class FakeMediaSource.InitialTimeline extends ForwardingTimelineA forwarding timeline to provide an initial timeline for fake multi window sources. |
Constants |
|
|---|---|
static final MediaItem |
The media item used by the fake media source. |
Protected fields |
|
|---|---|
@MonotonicNonNull Timeline |
Public constructors |
|---|
|
Creates a |
FakeMediaSource(@Nullable Timeline timeline, Format[] formats)Creates a |
This method is deprecated. Use |
This method is deprecated. Use |
This method is deprecated. Use |
Protected constructors |
|---|
FakeMediaSource(Creates a |
Public methods |
|
|---|---|
void |
assertMediaPeriodCreated(MediaSource.MediaPeriodId mediaPeriodId)Assert that a media period for the given id has been created. |
void |
Assert that the source and all periods have been released. |
boolean |
canUpdateMediaItem(MediaItem mediaItem)Returns whether the |
MediaPeriod |
createPeriod(Returns a new |
static FakeMediaSource |
createWithWindowId(Object windowId)Convenience method to create a |
List<MediaSource.MediaPeriodId> |
Returns a list of |
@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. |
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. |
void |
Throws any pending error encountered while loading or refreshing source information. |
synchronized void |
prepareSourceInternal(@Nullable TransferListener mediaTransferListener)Starts source preparation and enables the source, see |
void |
releasePeriod(MediaPeriod mediaPeriod)Releases the period. |
synchronized void |
setAllowPreparation(boolean allowPreparation)Sets whether the next call to prepareSource is allowed to finish. |
void |
setCanUpdateMediaItems(boolean canUpdateMediaItems)Sets whether the source allows to update its |
void |
setNewSourceInfo(Timeline newTimeline)Sets a new timeline. |
synchronized void |
setNewSourceInfo(Timeline newTimeline, boolean sendManifestLoadEvents)Sets a new timeline. |
void |
setPeriodDefersOnPreparedCallback(Sets whether the created |
void |
updateMediaItem(MediaItem mediaItem)Updates the |
Protected methods |
|
|---|---|
MediaPeriod |
@RequiresNonNull(value = "this.timeline")Creates a |
@Nullable Timeline |
|
void |
releaseMediaPeriod(MediaPeriod mediaPeriod)Releases a media period created by |
void |
Releases the source, see |
Inherited methods |
||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Constants
FAKE_MEDIA_ITEM
public static final MediaItem FAKE_MEDIA_ITEM
The media item used by the fake media source.
Protected fields
Public constructors
FakeMediaSource
public FakeMediaSource()
Creates a FakeMediaSource with a default FakeTimeline.
Use Builder to create a more configured instance.
FakeMediaSource
public FakeMediaSource(@Nullable Timeline timeline, Format[] formats)
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
publicFakeMediaSource(
@Nullable Timeline timeline,
DrmSessionManager drmSessionManager,
Format[] formats
)
FakeMediaSource
publicFakeMediaSource(
@Nullable Timeline timeline,
DrmSessionManager drmSessionManager,
@Nullable FakeMediaPeriod.TrackDataFactory trackDataFactory,
Format[] formats
)
FakeMediaSource
publicFakeMediaSource(
@Nullable Timeline timeline,
DrmSessionManager drmSessionManager,
@Nullable FakeMediaPeriod.TrackDataFactory trackDataFactory,
TrackGroupArray trackGroupArray
)
Protected constructors
FakeMediaSource
protected FakeMediaSource(
@Nullable Timeline timeline,
DrmSessionManager drmSessionManager,
@Nullable FakeMediaPeriod.TrackDataFactory trackDataFactory,
@Nullable long[] syncSampleTimesUs,
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 methods
assertMediaPeriodCreated
public void assertMediaPeriodCreated(MediaSource.MediaPeriodId mediaPeriodId)
Assert that a media period for the given id has been created.
assertReleased
public void assertReleased()
Assert that the source and all periods have been released.
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.
| 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 |
long startPositionUs |
The expected start position, in microseconds. |
| Returns | |
|---|---|
MediaPeriod |
A new |
createWithWindowId
public static FakeMediaSource createWithWindowId(Object windowId)
Convenience method to create a FakeMediaSource with the given window id.
getCreatedMediaPeriods
public List<MediaSource.MediaPeriodId> getCreatedMediaPeriods()
Returns a list of MediaPeriodIds, with one element for each created media period.
getInitialTimeline
public @Nullable Timeline getInitialTimeline()
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
public MediaPeriod getLastCreatedActiveMediaPeriod()
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
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.
isSingleWindow
public boolean isSingleWindow()
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
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.
| Throws | |
|---|---|
java.io.IOException |
prepareSourceInternal
synchronized public 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.
This method is called on the playback thread.
| 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. |
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. |
setAllowPreparation
synchronized public void setAllowPreparation(boolean allowPreparation)
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 | |
|---|---|
boolean allowPreparation |
Whether preparation is allowed to finish. |
setCanUpdateMediaItems
public void setCanUpdateMediaItems(boolean canUpdateMediaItems)
Sets whether the source allows to update its MediaItem via updateMediaItem.
| Parameters | |
|---|---|
boolean canUpdateMediaItems |
Whether a |
setNewSourceInfo
public void setNewSourceInfo(Timeline newTimeline)
Sets a new timeline. If the source is already prepared, this triggers a source info refresh message being sent to the listener.
setNewSourceInfo
synchronized public void setNewSourceInfo(Timeline newTimeline, boolean sendManifestLoadEvents)
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
public void setPeriodDefersOnPreparedCallback(
boolean periodDefersOnPreparedCallback
)
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
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.
Protected methods
createMediaPeriod
@RequiresNonNull(value = "this.timeline")
protected MediaPeriod createMediaPeriod(
MediaSource.MediaPeriodId id,
TrackGroupArray trackGroupArray,
Allocator allocator,
MediaSourceEventListener.EventDispatcher mediaSourceEventDispatcher,
DrmSessionManager drmSessionManager,
DrmSessionEventListener.EventDispatcher drmEventDispatcher,
@Nullable TransferListener transferListener
)
Creates a MediaPeriod for this media source.
| Parameters | |
|---|---|
MediaSource.MediaPeriodId id |
The identifier of the period. |
TrackGroupArray trackGroupArray |
The |
Allocator allocator |
An |
MediaSourceEventListener.EventDispatcher mediaSourceEventDispatcher |
An |
DrmSessionManager drmSessionManager |
A |
DrmSessionEventListener.EventDispatcher drmEventDispatcher |
An |
@Nullable 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 void releaseMediaPeriod(MediaPeriod mediaPeriod)
Releases a media period created by createMediaPeriod.
releaseSourceInternal
protected void releaseSourceInternal()
Releases the source, see releaseSource. This method is called exactly once after each call to prepareSourceInternal.
This method is called on the playback thread.