# FakeSampleStream

Artifact: [androidx.media3:media3-test-utils](https://developer.android.com/jetpack/androidx/releases/media3) [View Source](https://cs.android.com/search?q=file:androidx/media3/test/utils/FakeSampleStream.java+class:androidx.media3.test.utils.FakeSampleStream)

*** ** * ** ***


```
@UnstableApi
class FakeSampleStream : SampleStream
```

<br />

*** ** * ** ***

Fake `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/SampleStream` that outputs a given `https://developer.android.com/reference/kotlin/androidx/media3/common/Format` and any amount of `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeSampleStream.FakeSampleStreamItem`.

## Summary

| ### Nested types |
|---|
| `class https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeSampleStream.FakeSampleStreamItem` Item to customize a return value of `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/SampleStream#readData(androidx.media3.exoplayer.FormatHolder,androidx.media3.decoder.DecoderInputBuffer,int)`. |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeSampleStream#FakeSampleStream(androidx.media3.exoplayer.upstream.Allocator,androidx.media3.exoplayer.source.MediaSourceEventListener.EventDispatcher,androidx.media3.exoplayer.drm.DrmSessionManager,androidx.media3.exoplayer.drm.DrmSessionEventListener.EventDispatcher,androidx.media3.common.Format,java.util.List<androidx.media3.test.utils.FakeSampleStream.FakeSampleStreamItem>)( allocator: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Allocator!, mediaSourceEventDispatcher: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSourceEventListener.EventDispatcher?, drmSessionManager: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DrmSessionManager!, drmEventDispatcher: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DrmSessionEventListener.EventDispatcher!, initialFormat: https://developer.android.com/reference/kotlin/androidx/media3/common/Format!, fakeSampleStreamItems: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeSampleStream.FakeSampleStreamItem!>! )` Creates a fake sample stream which outputs the given `https://developer.android.com/reference/kotlin/androidx/media3/common/Format` followed by the provided `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeSampleStream.FakeSampleStreamItem`. |

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeSampleStream#append(java.util.List<androidx.media3.test.utils.FakeSampleStream.FakeSampleStreamItem>)(items: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeSampleStream.FakeSampleStreamItem!>!)` Appends `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeSampleStream.FakeSampleStreamItem` to the list of items that should be written to the queue. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeSampleStream#discardTo(long,boolean)(positionUs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html, toKeyframe: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)` Discards data from the queue. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeSampleStream#getLargestQueuedTimestampUs()()` Returns the timestamp of the largest queued sample in the queue, or `https://developer.android.com/reference/java/lang/Long.html#MIN_VALUE` if no samples are queued. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeSampleStream#isLoadingFinished()()` Returns whether data has been written to the sample queue until the end of stream signal. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeSampleStream#isReady()()` Returns whether data is available to be read. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeSampleStream#maybeThrowError()()` Throws an error that's preventing data from being read. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeSampleStream#readData(androidx.media3.exoplayer.FormatHolder,androidx.media3.decoder.DecoderInputBuffer,int)( formatHolder: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/FormatHolder!, buffer: https://developer.android.com/reference/kotlin/androidx/media3/decoder/DecoderInputBuffer!, @https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/SampleStream.ReadFlags readFlags: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html )` Attempts to read from the stream. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeSampleStream#release()()` Release the stream and its underlying sample queue. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeSampleStream#reset()()` Resets the sample queue. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeSampleStream#seekToUs(long,boolean)(positionUs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html, allowTimeBeyondBuffer: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)` Seeks the stream to a new position using already available data in the queue. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeSampleStream#skipData(long)(positionUs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)` Attempts to skip to the keyframe before the specified position, or to the end of the stream if `positionUs` is beyond it. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeSampleStream#writeData(long)(startPositionUs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)` Writes all not yet written `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeSampleStream.FakeSampleStreamItem` to the sample queue starting at the given position. |

| ### Public properties |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `@https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/SampleStream.Flags https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeSampleStream#flags()` |

| ### Inherited Constants |
|---|
| From [androidx.media3.exoplayer.source.SampleStream](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/SampleStream) |---|---| | `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/SampleStream#FLAG_HAS_PREROLL() = 4` Specifies that the stream contains a preroll of decode-only samples. | | `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/SampleStream#FLAG_MAYBE_HAS_PREROLL() = 2` Specifies that the stream may contain preroll samples. | | `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/SampleStream#FLAG_OMIT_SAMPLE_DATA() = 4` Specifies that `https://developer.android.com/reference/kotlin/androidx/media3/decoder/DecoderInputBuffer#data()`, `https://developer.android.com/reference/kotlin/androidx/media3/decoder/DecoderInputBuffer#supplementalData()` and `https://developer.android.com/reference/kotlin/androidx/media3/decoder/DecoderInputBuffer#cryptoInfo()` should not be populated when reading a sample buffer. | | `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/SampleStream#FLAG_PEEK() = 1` Specifies that the read position should not be advanced if a sample buffer is read. | | `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/SampleStream#FLAG_REQUIRE_FORMAT() = 2` Specifies that if a sample buffer would normally be read next, the format of the stream should be read instead. | | `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/SampleStream#FLAG_STRICT_DURATION() = 1` Specifies that playout of the stream should be stopped once the duration is reached. | |

## Public constructors

### FakeSampleStream

```
FakeSampleStream(
    allocator: Allocator!,
    mediaSourceEventDispatcher: MediaSourceEventListener.EventDispatcher?,
    drmSessionManager: DrmSessionManager!,
    drmEventDispatcher: DrmSessionEventListener.EventDispatcher!,
    initialFormat: Format!,
    fakeSampleStreamItems: (Mutable)List<FakeSampleStream.FakeSampleStreamItem!>!
)
```

Creates a fake sample stream which outputs the given `https://developer.android.com/reference/kotlin/androidx/media3/common/Format` followed by the provided `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeSampleStream.FakeSampleStreamItem`.

| Parameters |
|---|---|
| `allocator: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Allocator!` | An `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Allocator`. |
| `mediaSourceEventDispatcher: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSourceEventListener.EventDispatcher?` | A `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSourceEventListener.EventDispatcher` to notify of media events. |
| `drmSessionManager: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DrmSessionManager!` | A `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DrmSessionManager` for DRM interactions. |
| `drmEventDispatcher: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DrmSessionEventListener.EventDispatcher!` | A `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DrmSessionEventListener.EventDispatcher` to notify of DRM events. |
| `initialFormat: https://developer.android.com/reference/kotlin/androidx/media3/common/Format!` | The first `https://developer.android.com/reference/kotlin/androidx/media3/common/Format` to output. |
| `fakeSampleStreamItems: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeSampleStream.FakeSampleStreamItem!>!` | The `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeSampleStream.FakeSampleStreamItem` to output. |

## Public functions

### append

```
fun append(items: (Mutable)List<FakeSampleStream.FakeSampleStreamItem!>!): Unit
```

Appends `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeSampleStream.FakeSampleStreamItem` to the list of items that should be written to the queue.

Note that this data is only written to the queue once `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeSampleStream#writeData(long)` is called.

| Parameters |
|---|---|
| `items: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeSampleStream.FakeSampleStreamItem!>!` | The items to append. |

### discardTo

```
fun discardTo(positionUs: Long, toKeyframe: Boolean): Unit
```

Discards data from the queue.

| Parameters |
|---|---|
| `positionUs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | The position to discard to, in microseconds. |
| `toKeyframe: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | Whether to discard to keyframes only. |

### getLargestQueuedTimestampUs

```
fun getLargestQueuedTimestampUs(): Long
```

Returns the timestamp of the largest queued sample in the queue, or `https://developer.android.com/reference/java/lang/Long.html#MIN_VALUE` if no samples are queued.

### isLoadingFinished

```
fun isLoadingFinished(): Boolean
```

Returns whether data has been written to the sample queue until the end of stream signal.

### isReady

```
fun isReady(): Boolean
```

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 `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/SampleStream#readData(androidx.media3.exoplayer.FormatHolder,androidx.media3.decoder.DecoderInputBuffer,int)`. Hence an ended stream is always ready.

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | Whether data is available to be read. |

### maybeThrowError

```
fun maybeThrowError(): Unit
```

Throws an error that's preventing data from being read. Does nothing if no such error exists.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` | The underlying error. |

### readData

```
fun readData(
    formatHolder: FormatHolder!,
    buffer: DecoderInputBuffer!,
    @SampleStream.ReadFlags readFlags: Int
): Int
```

Attempts to read from the stream.

If the stream has ended then `https://developer.android.com/reference/kotlin/androidx/media3/common/C#BUFFER_FLAG_END_OF_STREAM()` flag is set on `
buffer` and `https://developer.android.com/reference/kotlin/androidx/media3/common/C#RESULT_BUFFER_READ()` is returned. Else if no data is available then `https://developer.android.com/reference/kotlin/androidx/media3/common/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 `https://developer.android.com/reference/kotlin/androidx/media3/common/C#RESULT_FORMAT_READ()` is returned. Else `buffer` is populated and `https://developer.android.com/reference/kotlin/androidx/media3/common/C#RESULT_BUFFER_READ()` is returned.

| Parameters |
|---|---|
| `formatHolder: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/FormatHolder!` | A `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/FormatHolder` to populate in the case of reading a format. |
| `buffer: https://developer.android.com/reference/kotlin/androidx/media3/decoder/DecoderInputBuffer!` | A `https://developer.android.com/reference/kotlin/androidx/media3/decoder/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 `https://developer.android.com/reference/kotlin/androidx/media3/common/C#BUFFER_FLAG_END_OF_STREAM()` flag will be set on the buffer. |
| `@https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/SampleStream.ReadFlags readFlags: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | Flags controlling the behavior of this read operation. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/SampleStream.ReadDataResult` of the read operation. |

| Throws |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/decoder/DecoderInputBuffer.InsufficientCapacityException` | If the `buffer` has insufficient capacity to hold the data of a sample being read. The buffer `https://developer.android.com/reference/kotlin/androidx/media3/decoder/DecoderInputBuffer#timeUs()` and flags are populated if this exception is thrown, but the read position is not advanced. |

### release

```
fun release(): Unit
```

Release the stream and its underlying sample queue.

### reset

```
fun reset(): Unit
```

Resets the sample queue.

A new call to `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeSampleStream#writeData(long)` is required to fill the queue again.

### seekToUs

```
fun seekToUs(positionUs: Long, allowTimeBeyondBuffer: Boolean): Boolean
```

Seeks the stream to a new position using already available data in the queue.

| Parameters |
|---|---|
| `positionUs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | The new position, in microseconds. |
| `allowTimeBeyondBuffer: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | Whether the operation can succeed if timeUs is beyond the end of the queue, by seeking to the last sample (or keyframe). |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | Whether seeking inside the available data was possible. |

### skipData

```
fun skipData(positionUs: Long): Int
```

Attempts to skip to the keyframe before the specified position, or to the end of the stream if `positionUs` is beyond it.

| Parameters |
|---|---|
| `positionUs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | The specified time. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The number of samples that were skipped. |

### writeData

```
fun writeData(startPositionUs: Long): Unit
```

Writes all not yet written `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeSampleStream.FakeSampleStreamItem` to the sample queue starting at the given position.

| Parameters |
|---|---|
| `startPositionUs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | The start position, in microseconds. |

## Public properties

### flags

```
@SampleStream.Flags
var flags: Int
```