docs/doc/reference/com/google/android/exoplayer2/testutil/FakeSampleStream.html
Package com.google.android.exoplayer2.testutil
All Implemented Interfaces:SampleStream
public classFakeSampleStreamextends[Object](https://developer.android.com/reference/java/lang/Object.html "class or interface in java.lang")implements[SampleStream](../source/SampleStream.html "interface in com.google.android.exoplayer2.source")
Fake SampleStream that outputs a given Format and any amount of items.
Nested Classes | Modifier and Type | Class | Description |
| --- | --- | --- |
| static class | FakeSampleStream.FakeSampleStreamItem |
Item to customize a return value of SampleStream.readData(com.google.android.exoplayer2.FormatHolder, com.google.android.exoplayer2.decoder.DecoderInputBuffer, @com.google.android.exoplayer2.source.SampleStream.ReadFlags int).
|
-
SampleStream.ReadDataResult, SampleStream.ReadFlags
-
FLAG_OMIT_SAMPLE_DATA, FLAG_PEEK, FLAG_REQUIRE_FORMAT
Constructors | Constructor | Description |
| --- | --- |
| FakeSampleStream(Allocator allocator, MediaSourceEventListener.EventDispatcher mediaSourceEventDispatcher, DrmSessionManager drmSessionManager, DrmSessionEventListener.EventDispatcher drmEventDispatcher, Format initialFormat, List<FakeSampleStream.FakeSampleStreamItem> fakeSampleStreamItems) |
Creates a fake sample stream which outputs the given Format followed by the provided items.
|
All Methods Instance Methods Concrete Methods | Modifier and Type | Method | Description |
| --- | --- | --- |
| void | append(List<FakeSampleStream.FakeSampleStreamItem> items) |
Appends FakeSampleStreamItems to the list of items that should be written to the queue.
|
| void | discardTo(long positionUs, boolean toKeyframe) |
Discards data from the queue.
|
| long | getLargestQueuedTimestampUs() |
Returns the timestamp of the largest queued sample in the queue, or Long.MIN_VALUE if no samples are queued.
|
| boolean | isLoadingFinished() |
Returns whether data has been written to the sample queue until the end of stream signal.
|
| boolean | isReady() |
Returns whether data is available to be read.
|
| void | maybeThrowError() |
Throws an error that's preventing data from being read.
|
| int | readData(FormatHolder formatHolder, DecoderInputBuffer buffer, @com.google.android.exoplayer2.source.SampleStream.ReadFlags int readFlags) |
Attempts to read from the stream.
|
| void | release() |
Release the stream and its underlying sample queue.
|
| void | reset() |
Resets the sample queue.
|
| boolean | seekToUs(long positionUs, boolean allowTimeBeyondBuffer) |
Seeks the stream to a new position using already available data in the queue.
|
| int | skipData(long positionUs) |
Attempts to skip to the keyframe before the specified position, or to the end of the stream if positionUs is beyond it.
|
| void | writeData(long startPositionUs) |
Writes all not yet written sample stream items to the sample queue starting at the given position.
|
-
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
public FakeSampleStream([Allocator](../upstream/Allocator.html "interface in com.google.android.exoplayer2.upstream")allocator,
@Nullable[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,[Format](../Format.html "class in com.google.android.exoplayer2")initialFormat,[List](https://developer.android.com/reference/java/util/List.html "class or interface in java.util")<[FakeSampleStream.FakeSampleStreamItem](FakeSampleStream.FakeSampleStreamItem.html "class in com.google.android.exoplayer2.testutil")> fakeSampleStreamItems)
Creates a fake sample stream which outputs the given Format followed by the provided items.
Parameters:allocator - An Allocator.mediaSourceEventDispatcher - A MediaSourceEventListener.EventDispatcher to notify of media events.drmSessionManager - A DrmSessionManager for DRM interactions.drmEventDispatcher - A DrmSessionEventListener.EventDispatcher to notify of DRM events.initialFormat - The first Format to output.fakeSampleStreamItems - The items to output.
-
public void append([List](https://developer.android.com/reference/java/util/List.html "class or interface in java.util")<[FakeSampleStream.FakeSampleStreamItem](FakeSampleStream.FakeSampleStreamItem.html "class in com.google.android.exoplayer2.testutil")> items)
Appends FakeSampleStreamItems to the list of items that should be written to the queue.
Note that this data is only written to the queue once writeData(long) is called.
Parameters:items - The items to append.
-
public void writeData(long startPositionUs)
Writes all not yet written sample stream items to the sample queue starting at the given position.
Parameters:startPositionUs - The start position, in microseconds.
-
public boolean seekToUs(long positionUs,
boolean allowTimeBeyondBuffer)
Seeks the stream to a new position using already available data in the queue.
Parameters:positionUs - The new position, in microseconds.allowTimeBeyondBuffer - Whether the operation can succeed if timeUs is beyond the end of the queue, by seeking to the last sample (or keyframe).Returns:Whether seeking inside the available data was possible.
-
public void reset()
Resets the sample queue.
A new call to writeData(long) is required to fill the queue again.
-
public boolean isLoadingFinished()
Returns whether data has been written to the sample queue until the end of stream signal.
-
public long getLargestQueuedTimestampUs()
Returns the timestamp of the largest queued sample in the queue, or Long.MIN_VALUE if no samples are queued.
-
public void discardTo(long positionUs,
boolean toKeyframe)
Discards data from the queue.
Parameters:positionUs - The position to discard to, in microseconds.toKeyframe - Whether to discard to keyframes only.
-
public void release()
Release the stream and its underlying sample queue.
-
public boolean isReady()
Description copied from interface: SampleStream
Returns whether data is available to be read.
Note: If the stream has ended then a buffer with the end of stream flag can always be read from SampleStream.readData(com.google.android.exoplayer2.FormatHolder, com.google.android.exoplayer2.decoder.DecoderInputBuffer, @com.google.android.exoplayer2.source.SampleStream.ReadFlags int). Hence an ended stream is always ready.
Specified by:isReady in interface SampleStreamReturns:Whether data is available to be read.
-
public void maybeThrowError()
throws[IOException](https://developer.android.com/reference/java/io/IOException.html "class or interface in java.io")
Description copied from interface: SampleStream
Throws an error that's preventing data from being read. Does nothing if no such error exists.
Specified by:maybeThrowError in interface SampleStreamThrows:IOException - The underlying error.
-
public int readData([FormatHolder](../FormatHolder.html "class in com.google.android.exoplayer2")formatHolder,[DecoderInputBuffer](../decoder/DecoderInputBuffer.html "class in com.google.android.exoplayer2.decoder")buffer,
@com.google.android.exoplayer2.source.SampleStream.ReadFlags int readFlags)
Description copied from interface: SampleStream
Attempts to read from the stream.
If the stream has ended then C.BUFFER_FLAG_END_OF_STREAM flag is set on buffer and C.RESULT_BUFFER_READ is returned. Else if no data is available then C.RESULT_NOTHING_READ is returned. Else if the format of the media is changing or if formatRequired is set then formatHolder is populated and C.RESULT_FORMAT_READ is returned. Else buffer is populated and C.RESULT_BUFFER_READ is returned.
Specified by:readData in interface SampleStreamParameters:formatHolder - A FormatHolder to populate in the case of reading a format.buffer - A DecoderInputBuffer to populate in the case of reading a sample or the end of the stream. If the end of the stream has been reached, the C.BUFFER_FLAG_END_OF_STREAM flag will be set on the buffer.readFlags - Flags controlling the behavior of this read operation.Returns:The result of the read operation.
-
public int skipData(long positionUs)
Description copied from interface: SampleStream
Attempts to skip to the keyframe before the specified position, or to the end of the stream if positionUs is beyond it.
Specified by:skipData in interface SampleStreamParameters:positionUs - The specified time.Returns:The number of samples that were skipped.