MediaSourceFakeAdaptiveMediaSourcepublic class FakeMediaSource extends BaseMediaSource
MediaSource that provides a given timeline. Creating the period will return a FakeMediaPeriod with a TrackGroupArray using the given Formats.| Modifier and Type | Class | Description |
|---|---|---|
static class |
FakeMediaSource.InitialTimeline |
A forwarding timeline to provide an initial timeline for fake multi window sources.
|
MediaSource.MediaPeriodId, MediaSource.MediaSourceCaller| Modifier and Type | Field | Description |
|---|---|---|
static MediaItem |
FAKE_MEDIA_ITEM |
The media item used by the fake media source.
|
| 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. |
| 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. |
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. |
Object |
getTag() |
Deprecated.
Use
getMediaItem() and MediaItem.PlaybackProperties.tag instead. |
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). |
protected void |
releaseMediaPeriod(MediaPeriod mediaPeriod) |
|
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, disable, disableInternal, enable, enableInternal, isEnabled, prepareSource, refreshSourceInfo, releaseSource, removeDrmEventListener, removeEventListenerpublic static final MediaItem FAKE_MEDIA_ITEM
public FakeMediaSource()
FakeMediaSource with a default FakeTimeline.public FakeMediaSource(@Nullable
Timeline timeline,
Format... formats)
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,
DrmSessionManager drmSessionManager,
Format... formats)
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,
DrmSessionManager drmSessionManager,
@Nullable
FakeMediaPeriod.TrackDataFactory trackDataFactory,
Format... formats)
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,
DrmSessionManager drmSessionManager,
@Nullable
FakeMediaPeriod.TrackDataFactory trackDataFactory,
TrackGroupArray trackGroupArray)
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 void setAllowPreparation(boolean allowPreparation)
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.allowPreparation - Whether preparation is allowed to finish.@Nullable protected Timeline getTimeline()
@Deprecated @Nullable public Object getTag()
getMediaItem() and MediaItem.PlaybackProperties.tag instead.public MediaItem getMediaItem()
MediaSourceMediaItem whose media is provided by the source.@Nullable public Timeline getInitialTimeline()
MediaSourceThe 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.
public boolean isSingleWindow()
MediaSourceThe default implementation returns true.
public void prepareSourceInternal(@Nullable
TransferListener mediaTransferListener)
BaseMediaSourceBaseMediaSource.prepareSource(MediaSourceCaller,
TransferListener). This method is called at most once until the next call to BaseMediaSource.releaseSourceInternal().prepareSourceInternal in class BaseMediaSourcemediaTransferListener - 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
MediaSourceShould not be called directly from application code.
Must only be called after MediaSource.prepareSource(MediaSourceCaller, TransferListener).
IOExceptionpublic MediaPeriod createPeriod(MediaSource.MediaPeriodId id, Allocator allocator, long startPositionUs)
MediaSourceMediaPeriod identified by periodId.
Should not be called directly from application code.
Must only be called if the source is enabled.
id - The identifier of the period.allocator - An Allocator from which to obtain media buffer allocations.startPositionUs - The expected start position, in microseconds.MediaPeriod.public void releasePeriod(MediaPeriod mediaPeriod)
MediaSourceShould not be called directly from application code.
mediaPeriod - The period to release.protected void releaseSourceInternal()
BaseMediaSourceBaseMediaSource.releaseSource(MediaSourceCaller). This method is called
exactly once after each call to BaseMediaSource.prepareSourceInternal(TransferListener).releaseSourceInternal in class BaseMediaSourcepublic void setNewSourceInfo(Timeline newTimeline)
newTimeline - The new Timeline.public void setNewSourceInfo(Timeline newTimeline, boolean sendManifestLoadEvents)
Must only be called if preparation is allowed.
newTimeline - The new Timeline.sendManifestLoadEvents - Whether to treat this as a manifest refresh and send manifest
load events to listeners.public boolean isPrepared()
public void assertReleased()
public void assertMediaPeriodCreated(MediaSource.MediaPeriodId mediaPeriodId)
public List<MediaSource.MediaPeriodId> getCreatedMediaPeriods()
MediaSource.MediaPeriodIds, with one element for each created media period.@RequiresNonNull("this.timeline")
protected MediaPeriod createMediaPeriod(MediaSource.MediaPeriodId id,
TrackGroupArray trackGroupArray,
Allocator allocator,
MediaSourceEventListener.EventDispatcher mediaSourceEventDispatcher,
DrmSessionManager drmSessionManager,
DrmSessionEventListener.EventDispatcher drmEventDispatcher,
@Nullable
TransferListener transferListener)
MediaPeriod for this media source.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.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.FakeMediaPeriod.protected void releaseMediaPeriod(MediaPeriod mediaPeriod)