docs/doc/reference/com/google/android/exoplayer2/testutil/FakeMediaSource.html
Package com.google.android.exoplayer2.testutil
All Implemented Interfaces:MediaSourceDirect Known Subclasses:FakeAdaptiveMediaSource
public classFakeMediaSourceextends[BaseMediaSource](../source/BaseMediaSource.html "class in com.google.android.exoplayer2.source")
Fake MediaSource that provides a given timeline. Creating the period will return a FakeMediaPeriod with a TrackGroupArray using the given Formats.
Nested Classes | Modifier and Type | Class | Description |
| --- | --- | --- |
| static class | FakeMediaSource.InitialTimeline |
A forwarding timeline to provide an initial timeline for fake multi window sources.
|
-
MediaSource.Factory, MediaSource.MediaPeriodId, MediaSource.MediaSourceCaller
Fields | Modifier and Type | Field | Description |
| --- | --- | --- |
| static MediaItem | FAKE_MEDIA_ITEM |
The media item used by the fake media source.
|
Constructors | Constructor | Description |
| --- | --- |
| FakeMediaSource() |
Creates a FakeMediaSource with a default FakeTimeline.
|
| FakeMediaSource(Timeline timeline, DrmSessionManager drmSessionManager, Format... formats) |
Creates a FakeMediaSource.
|
| FakeMediaSource(Timeline timeline, DrmSessionManager drmSessionManager, FakeMediaPeriod.TrackDataFactory trackDataFactory, Format... formats) |
Creates a FakeMediaSource.
|
| FakeMediaSource(Timeline timeline, DrmSessionManager drmSessionManager, FakeMediaPeriod.TrackDataFactory trackDataFactory, TrackGroupArray trackGroupArray) |
Creates a FakeMediaSource.
|
| FakeMediaSource(Timeline timeline, Format... formats) |
Creates a FakeMediaSource.
|
All Methods Static Methods Instance Methods Concrete Methods | Modifier and Type | Method | Description |
| --- | --- | --- |
| void | assertMediaPeriodCreated(MediaSource.MediaPeriodId mediaPeriodId) |
Assert that a media period for the given id has been created.
|
| void | assertReleased() |
Assert that the source and all periods have been released.
|
| protected MediaPeriod | createMediaPeriod(MediaSource.MediaPeriodId id, TrackGroupArray trackGroupArray, Allocator allocator, MediaSourceEventListener.EventDispatcher mediaSourceEventDispatcher, DrmSessionManager drmSessionManager, DrmSessionEventListener.EventDispatcher drmEventDispatcher, TransferListener transferListener) |
Creates a MediaPeriod for this media source.
|
| MediaPeriod | createPeriod(MediaSource.MediaPeriodId id, Allocator allocator, long startPositionUs) |
Returns a new MediaPeriod identified by periodId.
|
| static FakeMediaSource | createWithWindowId(Object windowId) |
Convenience method to create a FakeMediaSource with the given window id.
|
| List<MediaSource.MediaPeriodId> | getCreatedMediaPeriods() |
Returns a list of MediaSource.MediaPeriodIds, with one element for each created media period.
|
| 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.
|
| MediaItem | getMediaItem() |
Returns the MediaItem whose media is provided by the source.
|
| protected Timeline | getTimeline() | |
| boolean | isPrepared() |
Returns whether the source is currently prepared.
|
| boolean | isSingleWindow() |
Returns true if the media source is guaranteed to never have zero or more than one window.
|
| void | maybeThrowSourceInfoRefreshError() |
Throws any pending error encountered while loading or refreshing source information.
|
| void | prepareSourceInternal(TransferListener mediaTransferListener) |
Starts source preparation and enables the source, see BaseMediaSource.prepareSource(MediaSourceCaller, TransferListener, PlayerId).
|
| protected void | releaseMediaPeriod(MediaPeriod mediaPeriod) |
Releases a media period created by createMediaPeriod(MediaPeriodId, TrackGroupArray, Allocator, MediaSourceEventListener.EventDispatcher, DrmSessionManager, DrmSessionEventListener.EventDispatcher, TransferListener).
|
| void | releasePeriod(MediaPeriod mediaPeriod) |
Releases the period.
|
| protected void | releaseSourceInternal() |
Releases the source, see BaseMediaSource.releaseSource(MediaSourceCaller).
|
| void | setAllowPreparation(boolean allowPreparation) |
Sets whether the next call to BaseMediaSource.prepareSource(com.google.android.exoplayer2.source.MediaSource.MediaSourceCaller, com.google.android.exoplayer2.upstream.TransferListener) is allowed to finish.
|
| void | setNewSourceInfo(Timeline newTimeline) |
Sets a new timeline.
|
| void | setNewSourceInfo(Timeline newTimeline, boolean sendManifestLoadEvents) |
Sets a new timeline.
|
-
addDrmEventListener, addEventListener, createDrmEventDispatcher, createDrmEventDispatcher, createEventDispatcher, createEventDispatcher, createEventDispatcher, createEventDispatcher, disable, disableInternal, enable, enableInternal, getPlayerId, isEnabled, prepareSource, prepareSource, refreshSourceInfo, releaseSource, removeDrmEventListener, removeEventListener
-
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
public static final[MediaItem](../MediaItem.html "class in com.google.android.exoplayer2")FAKE_MEDIA_ITEM
The media item used by the fake media source.
-
public FakeMediaSource()
Creates a FakeMediaSource with a default FakeTimeline.
-
public FakeMediaSource(@Nullable[Timeline](../Timeline.html "class in com.google.android.exoplayer2")timeline,[Format](../Format.html "class in com.google.android.exoplayer2")... 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(Timeline).
-
public FakeMediaSource(@Nullable[Timeline](../Timeline.html "class in com.google.android.exoplayer2")timeline,[DrmSessionManager](../drm/DrmSessionManager.html "interface in com.google.android.exoplayer2.drm")drmSessionManager,[Format](../Format.html "class in com.google.android.exoplayer2")... formats)
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(Timeline).
-
public FakeMediaSource(@Nullable[Timeline](../Timeline.html "class in com.google.android.exoplayer2")timeline,[DrmSessionManager](../drm/DrmSessionManager.html "interface in com.google.android.exoplayer2.drm")drmSessionManager,
@Nullable[FakeMediaPeriod.TrackDataFactory](FakeMediaPeriod.TrackDataFactory.html "interface in com.google.android.exoplayer2.testutil")trackDataFactory,[Format](../Format.html "class in com.google.android.exoplayer2")... formats)
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(Timeline).
-
public FakeMediaSource(@Nullable[Timeline](../Timeline.html "class in com.google.android.exoplayer2")timeline,[DrmSessionManager](../drm/DrmSessionManager.html "interface in com.google.android.exoplayer2.drm")drmSessionManager,
@Nullable[FakeMediaPeriod.TrackDataFactory](FakeMediaPeriod.TrackDataFactory.html "interface in com.google.android.exoplayer2.testutil")trackDataFactory,[TrackGroupArray](../source/TrackGroupArray.html "class in com.google.android.exoplayer2.source")trackGroupArray)
Creates a FakeMediaSource. This media source creates FakeMediaPeriods with the provided TrackGroupArray, DrmSessionManager and FakeMediaPeriod.TrackDataFactory. 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(Timeline).
-
public static[FakeMediaSource](FakeMediaSource.html "class in com.google.android.exoplayer2.testutil")createWithWindowId([Object](https://developer.android.com/reference/java/lang/Object.html "class or interface in java.lang")windowId)
Convenience method to create a FakeMediaSource with the given window id.
-
public void setAllowPreparation(boolean allowPreparation)
Sets whether the next call to BaseMediaSource.prepareSource(com.google.android.exoplayer2.source.MediaSource.MediaSourceCaller, com.google.android.exoplayer2.upstream.TransferListener) is allowed to finish. If not allowed, a later call to this method with allowPreparation set to true will finish the preparation.
Parameters:allowPreparation - Whether preparation is allowed to finish.
-
@Nullable
protected[Timeline](../Timeline.html "class in com.google.android.exoplayer2")getTimeline()
-
public[MediaItem](../MediaItem.html "class in com.google.android.exoplayer2")getMediaItem()
Description copied from interface: MediaSource
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.
-
@Nullable
public[Timeline](../Timeline.html "class in com.google.android.exoplayer2")getInitialTimeline()
Description copied from interface: MediaSource
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.
-
public boolean isSingleWindow()
Description copied from interface: MediaSource
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:true if the source has exactly one window.
-
public void prepareSourceInternal(@Nullable[TransferListener](../upstream/TransferListener.html "interface in com.google.android.exoplayer2.upstream")mediaTransferListener)
Description copied from class: BaseMediaSource
Starts source preparation and enables the source, see BaseMediaSource.prepareSource(MediaSourceCaller, TransferListener, PlayerId). This method is called at most once until the next call to BaseMediaSource.releaseSourceInternal().
Specified by:prepareSourceInternal in class BaseMediaSourceParameters: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.
-
public void maybeThrowSourceInfoRefreshError()
throws[IOException](https://developer.android.com/reference/java/io/IOException.html "class or interface in java.io")
Description copied from interface: MediaSource
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 MediaSource.prepareSource(MediaSourceCaller, TransferListener, PlayerId).
Throws:IOException
-
public[MediaPeriod](../source/MediaPeriod.html "interface in com.google.android.exoplayer2.source")createPeriod([MediaSource.MediaPeriodId](../source/MediaSource.MediaPeriodId.html "class in com.google.android.exoplayer2.source")id,[Allocator](../upstream/Allocator.html "interface in com.google.android.exoplayer2.upstream")allocator,
long startPositionUs)
Description copied from interface: MediaSource
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 - The identifier of the period.allocator - An Allocator from which to obtain media buffer allocations.startPositionUs - The expected start position, in microseconds.Returns:A new MediaPeriod.
-
public void releasePeriod([MediaPeriod](../source/MediaPeriod.html "interface in com.google.android.exoplayer2.source")mediaPeriod)
Description copied from interface: MediaSource
Releases the period.
Should not be called directly from application code.
This method must be called on the playback thread.
Parameters:mediaPeriod - The period to release.
-
protected void releaseSourceInternal()
Description copied from class: BaseMediaSource
Releases the source, see BaseMediaSource.releaseSource(MediaSourceCaller). This method is called exactly once after each call to BaseMediaSource.prepareSourceInternal(TransferListener).
Specified by:releaseSourceInternal in class BaseMediaSource
-
public void setNewSourceInfo([Timeline](../Timeline.html "class in com.google.android.exoplayer2")newTimeline)
Sets a new timeline. If the source is already prepared, this triggers a source info refresh message being sent to the listener.
Parameters:newTimeline - The new Timeline.
-
public void setNewSourceInfo([Timeline](../Timeline.html "class in com.google.android.exoplayer2")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.
Parameters:newTimeline - The new Timeline.sendManifestLoadEvents - Whether to treat this as a manifest refresh and send manifest load events to listeners.
-
public boolean isPrepared()
Returns whether the source is currently prepared.
-
public void assertReleased()
Assert that the source and all periods have been released.
-
public void assertMediaPeriodCreated([MediaSource.MediaPeriodId](../source/MediaSource.MediaPeriodId.html "class in com.google.android.exoplayer2.source")mediaPeriodId)
Assert that a media period for the given id has been created.
-
public[List](https://developer.android.com/reference/java/util/List.html "class or interface in java.util")<[MediaSource.MediaPeriodId](../source/MediaSource.MediaPeriodId.html "class in com.google.android.exoplayer2.source")> getCreatedMediaPeriods()
Returns a list of MediaSource.MediaPeriodIds, with one element for each created media period.
-
@RequiresNonNull("this.timeline")
protected[MediaPeriod](../source/MediaPeriod.html "interface in com.google.android.exoplayer2.source")createMediaPeriod([MediaSource.MediaPeriodId](../source/MediaSource.MediaPeriodId.html "class in com.google.android.exoplayer2.source")id,[TrackGroupArray](../source/TrackGroupArray.html "class in com.google.android.exoplayer2.source")trackGroupArray,[Allocator](../upstream/Allocator.html "interface in com.google.android.exoplayer2.upstream")allocator,[MediaSourceEventListener.EventDispatcher](../source/MediaSourceEventListener.EventDispatcher.html "class in com.google.android.exoplayer2.source")mediaSourceEventDispatcher,[DrmSessionManager](../drm/DrmSessionManager.html "interface in com.google.android.exoplayer2.drm")drmSessionManager,[DrmSessionEventListener.EventDispatcher](../drm/DrmSessionEventListener.EventDispatcher.html "class in com.google.android.exoplayer2.drm")drmEventDispatcher,
@Nullable[TransferListener](../upstream/TransferListener.html "interface in com.google.android.exoplayer2.upstream")transferListener)
Creates a MediaPeriod for this media source.
Parameters:id - The identifier of the period.trackGroupArray - The TrackGroupArray supported by the media period.allocator - An Allocator from which to obtain media buffer allocations.mediaSourceEventDispatcher - An MediaSourceEventListener.EventDispatcher to dispatch media source events.drmSessionManager - A DrmSessionManager to allow DRM interactions.drmEventDispatcher - An MediaSourceEventListener.EventDispatcher to dispatch DRM events.transferListener - The transfer listener which should be informed of any data transfers. May be null if no listener is available.Returns:A new FakeMediaPeriod.
-
protected void releaseMediaPeriod([MediaPeriod](../source/MediaPeriod.html "interface in com.google.android.exoplayer2.source")mediaPeriod)
Releases a media period created by createMediaPeriod(MediaPeriodId, TrackGroupArray, Allocator, MediaSourceEventListener.EventDispatcher, DrmSessionManager, DrmSessionEventListener.EventDispatcher, TransferListener).