Class FakeMediaSource
- java.lang.Object
-
- com.google.android.exoplayer2.source.BaseMediaSource
-
- com.google.android.exoplayer2.testutil.FakeMediaSource
-
- All Implemented Interfaces:
MediaSource
- Direct Known Subclasses:
FakeAdaptiveMediaSource
public class FakeMediaSource extends BaseMediaSource
FakeMediaSource
that provides a given timeline. Creating the period will return aFakeMediaPeriod
with aTrackGroupArray
using the givenFormat
s.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
FakeMediaSource.InitialTimeline
A forwarding timeline to provide an initial timeline for fake multi window sources.-
Nested classes/interfaces inherited from interface com.google.android.exoplayer2.source.MediaSource
MediaSource.MediaPeriodId, MediaSource.MediaSourceCaller
-
-
Field Summary
Fields Modifier and Type Field Description static MediaItem
FAKE_MEDIA_ITEM
The media item used by the fake media source.
-
Constructor Summary
Constructors Constructor Description FakeMediaSource()
Creates aFakeMediaSource
with a defaultFakeTimeline
.FakeMediaSource(Timeline timeline, DrmSessionManager drmSessionManager, Format... formats)
Creates aFakeMediaSource
.FakeMediaSource(Timeline timeline, DrmSessionManager drmSessionManager, FakeMediaPeriod.TrackDataFactory trackDataFactory, Format... formats)
Creates aFakeMediaSource
.FakeMediaSource(Timeline timeline, DrmSessionManager drmSessionManager, FakeMediaPeriod.TrackDataFactory trackDataFactory, TrackGroupArray trackGroupArray)
Creates aFakeMediaSource
.FakeMediaSource(Timeline timeline, Format... formats)
Creates aFakeMediaSource
.
-
Method Summary
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 aMediaPeriod
for this media source.MediaPeriod
createPeriod(MediaSource.MediaPeriodId id, Allocator allocator, long startPositionUs)
Returns a newMediaPeriod
identified byperiodId
.static FakeMediaSource
createWithWindowId(Object windowId)
Convenience method to create aFakeMediaSource
with the given window id.List<MediaSource.MediaPeriodId>
getCreatedMediaPeriods()
Returns a list ofMediaSource.MediaPeriodId
s, 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 theMediaItem
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, seeBaseMediaSource.prepareSource(MediaSourceCaller, TransferListener)
.protected void
releaseMediaPeriod(MediaPeriod mediaPeriod)
void
releasePeriod(MediaPeriod mediaPeriod)
Releases the period.protected void
releaseSourceInternal()
Releases the source, seeBaseMediaSource.releaseSource(MediaSourceCaller)
.void
setAllowPreparation(boolean allowPreparation)
Sets whether the next call toBaseMediaSource.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.-
Methods inherited from class com.google.android.exoplayer2.source.BaseMediaSource
addDrmEventListener, addEventListener, createDrmEventDispatcher, createDrmEventDispatcher, createEventDispatcher, createEventDispatcher, createEventDispatcher, disable, disableInternal, enable, enableInternal, isEnabled, prepareSource, refreshSourceInfo, releaseSource, removeDrmEventListener, removeEventListener
-
-
-
-
Field Detail
-
FAKE_MEDIA_ITEM
public static final MediaItem FAKE_MEDIA_ITEM
The media item used by the fake media source.
-
-
Constructor Detail
-
FakeMediaSource
public FakeMediaSource()
Creates aFakeMediaSource
with a defaultFakeTimeline
.
-
FakeMediaSource
public FakeMediaSource(@Nullable Timeline timeline, Format... formats)
Creates aFakeMediaSource
. This media source createsFakeMediaPeriod
s with aTrackGroupArray
using the givenFormat
s. The providedTimeline
may be null to prevent an immediate source info refresh message when preparing the media source. It can be manually set later usingsetNewSourceInfo(Timeline)
.
-
FakeMediaSource
public FakeMediaSource(@Nullable Timeline timeline, DrmSessionManager drmSessionManager, Format... formats)
Creates aFakeMediaSource
. This media source createsFakeMediaPeriod
s with aTrackGroupArray
using the givenFormat
s. It passesdrmSessionManager
into the created periods. The providedTimeline
may be null to prevent an immediate source info refresh message when preparing the media source. It can be manually set later usingsetNewSourceInfo(Timeline)
.
-
FakeMediaSource
public FakeMediaSource(@Nullable Timeline timeline, DrmSessionManager drmSessionManager, @Nullable FakeMediaPeriod.TrackDataFactory trackDataFactory, Format... formats)
Creates aFakeMediaSource
. This media source createsFakeMediaPeriod
s with aTrackGroupArray
using the givenFormat
s. It passesdrmSessionManager
andtrackDataFactory
into the created periods. The providedTimeline
may be null to prevent an immediate source info refresh message when preparing the media source. It can be manually set later usingsetNewSourceInfo(Timeline)
.
-
FakeMediaSource
public FakeMediaSource(@Nullable Timeline timeline, DrmSessionManager drmSessionManager, @Nullable FakeMediaPeriod.TrackDataFactory trackDataFactory, TrackGroupArray trackGroupArray)
Creates aFakeMediaSource
. This media source createsFakeMediaPeriod
s with the providedTrackGroupArray
,DrmSessionManager
andFakeMediaPeriod.TrackDataFactory
. The providedTimeline
may be null to prevent an immediate source info refresh message when preparing the media source. It can be manually set later usingsetNewSourceInfo(Timeline)
.
-
-
Method Detail
-
createWithWindowId
public static FakeMediaSource createWithWindowId(Object windowId)
Convenience method to create aFakeMediaSource
with the given window id.
-
setAllowPreparation
public void setAllowPreparation(boolean allowPreparation)
Sets whether the next call toBaseMediaSource.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 withallowPreparation
set to true will finish the preparation.- Parameters:
allowPreparation
- Whether preparation is allowed to finish.
-
getTimeline
@Nullable protected Timeline getTimeline()
-
getMediaItem
public MediaItem getMediaItem()
Description copied from interface:MediaSource
Returns theMediaItem
whose media is provided by the source.
-
getInitialTimeline
@Nullable public Timeline 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.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.
-
isSingleWindow
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.The default implementation returns
true
.- Returns:
- true if the source has exactly one window.
-
prepareSourceInternal
public void prepareSourceInternal(@Nullable TransferListener mediaTransferListener)
Description copied from class:BaseMediaSource
Starts source preparation and enables the source, seeBaseMediaSource.prepareSource(MediaSourceCaller, TransferListener)
. This method is called at most once until the next call toBaseMediaSource.releaseSourceInternal()
.- Specified by:
prepareSourceInternal
in classBaseMediaSource
- Parameters:
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.
-
maybeThrowSourceInfoRefreshError
public void maybeThrowSourceInfoRefreshError() throws IOException
Description copied from interface:MediaSource
Throws any pending error encountered while loading or refreshing source information.Should not be called directly from application code.
Must only be called after
MediaSource.prepareSource(MediaSourceCaller, TransferListener)
.- Throws:
IOException
-
createPeriod
public MediaPeriod createPeriod(MediaSource.MediaPeriodId id, Allocator allocator, long startPositionUs)
Description copied from interface:MediaSource
Returns a newMediaPeriod
identified byperiodId
.Should not be called directly from application code.
Must only be called if the source is enabled.
- Parameters:
id
- The identifier of the period.allocator
- AnAllocator
from which to obtain media buffer allocations.startPositionUs
- The expected start position, in microseconds.- Returns:
- A new
MediaPeriod
.
-
releasePeriod
public void releasePeriod(MediaPeriod mediaPeriod)
Description copied from interface:MediaSource
Releases the period.Should not be called directly from application code.
- Parameters:
mediaPeriod
- The period to release.
-
releaseSourceInternal
protected void releaseSourceInternal()
Description copied from class:BaseMediaSource
Releases the source, seeBaseMediaSource.releaseSource(MediaSourceCaller)
. This method is called exactly once after each call toBaseMediaSource.prepareSourceInternal(TransferListener)
.- Specified by:
releaseSourceInternal
in classBaseMediaSource
-
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.- Parameters:
newTimeline
- The newTimeline
.
-
setNewSourceInfo
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
.- Parameters:
newTimeline
- The newTimeline
.sendManifestLoadEvents
- Whether to treat this as a manifest refresh and send manifest load events to listeners.
-
isPrepared
public boolean isPrepared()
Returns whether the source is currently prepared.
-
assertReleased
public void assertReleased()
Assert that the source and all periods have been released.
-
assertMediaPeriodCreated
public void assertMediaPeriodCreated(MediaSource.MediaPeriodId mediaPeriodId)
Assert that a media period for the given id has been created.
-
getCreatedMediaPeriods
public List<MediaSource.MediaPeriodId> getCreatedMediaPeriods()
Returns a list ofMediaSource.MediaPeriodId
s, with one element for each created media period.
-
createMediaPeriod
@RequiresNonNull("this.timeline") protected MediaPeriod createMediaPeriod(MediaSource.MediaPeriodId id, TrackGroupArray trackGroupArray, Allocator allocator, MediaSourceEventListener.EventDispatcher mediaSourceEventDispatcher, DrmSessionManager drmSessionManager, DrmSessionEventListener.EventDispatcher drmEventDispatcher, @Nullable TransferListener transferListener)
Creates aMediaPeriod
for this media source.- Parameters:
id
- The identifier of the period.trackGroupArray
- TheTrackGroupArray
supported by the media period.allocator
- AnAllocator
from which to obtain media buffer allocations.mediaSourceEventDispatcher
- AnMediaSourceEventListener.EventDispatcher
to dispatch media source events.drmEventDispatcher
- AnMediaSourceEventListener.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
.
-
releaseMediaPeriod
protected void releaseMediaPeriod(MediaPeriod mediaPeriod)
-
-