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
FakeMediaSourcethat provides a given timeline. Creating the period will return aFakeMediaPeriodwith aTrackGroupArrayusing the givenFormats.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classFakeMediaSource.InitialTimelineA 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 MediaItemFAKE_MEDIA_ITEMThe media item used by the fake media source.
-
Constructor Summary
Constructors Constructor Description FakeMediaSource()Creates aFakeMediaSourcewith 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 voidassertMediaPeriodCreated(MediaSource.MediaPeriodId mediaPeriodId)Assert that a media period for the given id has been created.voidassertReleased()Assert that the source and all periods have been released.protected MediaPeriodcreateMediaPeriod(MediaSource.MediaPeriodId id, TrackGroupArray trackGroupArray, Allocator allocator, MediaSourceEventListener.EventDispatcher mediaSourceEventDispatcher, DrmSessionManager drmSessionManager, DrmSessionEventListener.EventDispatcher drmEventDispatcher, TransferListener transferListener)Creates aMediaPeriodfor this media source.MediaPeriodcreatePeriod(MediaSource.MediaPeriodId id, Allocator allocator, long startPositionUs)Returns a newMediaPeriodidentified byperiodId.static FakeMediaSourcecreateWithWindowId(Object windowId)Convenience method to create aFakeMediaSourcewith the given window id.List<MediaSource.MediaPeriodId>getCreatedMediaPeriods()Returns a list ofMediaSource.MediaPeriodIds, with one element for each created media period.TimelinegetInitialTimeline()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.MediaItemgetMediaItem()Returns theMediaItemwhose media is provided by the source.protected TimelinegetTimeline()booleanisPrepared()Returns whether the source is currently prepared.booleanisSingleWindow()Returns true if the media source is guaranteed to never have zero or more than one window.voidmaybeThrowSourceInfoRefreshError()Throws any pending error encountered while loading or refreshing source information.voidprepareSourceInternal(TransferListener mediaTransferListener)Starts source preparation and enables the source, seeBaseMediaSource.prepareSource(MediaSourceCaller, TransferListener).protected voidreleaseMediaPeriod(MediaPeriod mediaPeriod)voidreleasePeriod(MediaPeriod mediaPeriod)Releases the period.protected voidreleaseSourceInternal()Releases the source, seeBaseMediaSource.releaseSource(MediaSourceCaller).voidsetAllowPreparation(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.voidsetNewSourceInfo(Timeline newTimeline)Sets a new timeline.voidsetNewSourceInfo(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 aFakeMediaSourcewith a defaultFakeTimeline.
-
FakeMediaSource
public FakeMediaSource(@Nullable Timeline timeline, Format... formats)Creates aFakeMediaSource. This media source createsFakeMediaPeriods with aTrackGroupArrayusing the givenFormats. The providedTimelinemay 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 createsFakeMediaPeriods with aTrackGroupArrayusing the givenFormats. It passesdrmSessionManagerinto the created periods. The providedTimelinemay 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 createsFakeMediaPeriods with aTrackGroupArrayusing the givenFormats. It passesdrmSessionManagerandtrackDataFactoryinto the created periods. The providedTimelinemay 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 createsFakeMediaPeriods with the providedTrackGroupArray,DrmSessionManagerandFakeMediaPeriod.TrackDataFactory. The providedTimelinemay 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 aFakeMediaSourcewith 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 withallowPreparationset 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:MediaSourceReturns theMediaItemwhose media is provided by the source.
-
getInitialTimeline
@Nullable public Timeline getInitialTimeline()
Description copied from interface:MediaSourceReturns 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:MediaSourceReturns 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:BaseMediaSourceStarts 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:
prepareSourceInternalin 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 IOExceptionDescription copied from interface:MediaSourceThrows 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:MediaSourceReturns a newMediaPeriodidentified 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- AnAllocatorfrom 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:MediaSourceReleases the period.Should not be called directly from application code.
- Parameters:
mediaPeriod- The period to release.
-
releaseSourceInternal
protected void releaseSourceInternal()
Description copied from class:BaseMediaSourceReleases the source, seeBaseMediaSource.releaseSource(MediaSourceCaller). This method is called exactly once after each call toBaseMediaSource.prepareSourceInternal(TransferListener).- Specified by:
releaseSourceInternalin 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.MediaPeriodIds, 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 aMediaPeriodfor this media source.- Parameters:
id- The identifier of the period.trackGroupArray- TheTrackGroupArraysupported by the media period.allocator- AnAllocatorfrom which to obtain media buffer allocations.mediaSourceEventDispatcher- AnMediaSourceEventListener.EventDispatcherto dispatch media source events.drmEventDispatcher- AnMediaSourceEventListener.EventDispatcherto 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)
-
-