# SimpleSubtitleDecoder

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

*** ** * ** ***


```
@UnstableApi
public abstract class SimpleSubtitleDecoder extends SimpleDecoder<SubtitleInputBuffer, SubtitleOutputBuffer, SubtitleDecoderException> implements SubtitleDecoder
```

<br />

|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) |||
| ↳ | [androidx.media3.decoder.SimpleDecoder](https://developer.android.com/reference/androidx/media3/decoder/SimpleDecoder)\<[SubtitleInputBuffer](https://developer.android.com/reference/androidx/media3/extractor/text/SubtitleInputBuffer), [SubtitleOutputBuffer](https://developer.android.com/reference/androidx/media3/extractor/text/SubtitleOutputBuffer), [SubtitleDecoderException](https://developer.android.com/reference/androidx/media3/extractor/text/SubtitleDecoderException)\> ||
|   | ↳ | [androidx.media3.extractor.text.SimpleSubtitleDecoder](https://developer.android.com/reference/androidx/media3/extractor/text/SimpleSubtitleDecoder) |

*** ** * ** ***

Base class for subtitle parsers that use their own decode thread.

## Summary

| ### Public fields |
|---|---|
| `final https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/media3/extractor/text/SimpleSubtitleDecoder#name()` |

| ### Protected constructors |
|---|
| `https://developer.android.com/reference/androidx/media3/extractor/text/SimpleSubtitleDecoder#SimpleSubtitleDecoder(java.lang.String)(https://developer.android.com/reference/java/lang/String.html name)` |

| ### Public methods |
|---|---|
| `final https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/media3/extractor/text/SimpleSubtitleDecoder#getName()()` Returns the name of the decoder. |
| `void` | `https://developer.android.com/reference/androidx/media3/extractor/text/SimpleSubtitleDecoder#setPositionUs(long)(long positionUs)` Informs the decoder of the current playback position. |

| ### Protected methods |
|---|---|
| `final https://developer.android.com/reference/androidx/media3/extractor/text/SubtitleInputBuffer` | `https://developer.android.com/reference/androidx/media3/extractor/text/SimpleSubtitleDecoder#createInputBuffer()()` Creates a new input buffer. |
| `final https://developer.android.com/reference/androidx/media3/extractor/text/SubtitleOutputBuffer` | `https://developer.android.com/reference/androidx/media3/extractor/text/SimpleSubtitleDecoder#createOutputBuffer()()` Creates a new output buffer. |
| `final https://developer.android.com/reference/androidx/media3/extractor/text/SubtitleDecoderException` | `https://developer.android.com/reference/androidx/media3/extractor/text/SimpleSubtitleDecoder#createUnexpectedDecodeException(java.lang.Throwable)(https://developer.android.com/reference/java/lang/Throwable.html error)` Creates an exception to propagate for an unexpected decode error. |
| `abstract https://developer.android.com/reference/androidx/media3/extractor/text/Subtitle` | `https://developer.android.com/reference/androidx/media3/extractor/text/SimpleSubtitleDecoder#decode(byte[],int,boolean)(byte[] data, int length, boolean reset)` Decodes data into a `https://developer.android.com/reference/androidx/media3/extractor/text/Subtitle`. |
| `final @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/extractor/text/SubtitleDecoderException` | `https://developer.android.com/reference/androidx/media3/extractor/text/SimpleSubtitleDecoder#decode(androidx.media3.extractor.text.SubtitleInputBuffer,androidx.media3.extractor.text.SubtitleOutputBuffer,boolean)( https://developer.android.com/reference/androidx/media3/extractor/text/SubtitleInputBuffer inputBuffer, https://developer.android.com/reference/androidx/media3/extractor/text/SubtitleOutputBuffer outputBuffer, boolean reset )` Decodes the `inputBuffer` and stores any decoded output in `outputBuffer`. |

### Inherited methods

From [androidx.media3.decoder.SimpleDecoder](https://developer.android.com/reference/androidx/media3/decoder/SimpleDecoder) `final @https://developer.android.com/reference/androidx/annotation/Nullable I` `https://developer.android.com/reference/androidx/media3/decoder/SimpleDecoder#dequeueInputBuffer()()`

Dequeues the next input buffer to be filled and queued to the decoder.
`final @https://developer.android.com/reference/androidx/annotation/Nullable O` `https://developer.android.com/reference/androidx/media3/decoder/SimpleDecoder#dequeueOutputBuffer()()`

Dequeues the next output buffer from the decoder.
`final void` `https://developer.android.com/reference/androidx/media3/decoder/SimpleDecoder#flush()()`

Flushes the decoder.
`final boolean` `https://developer.android.com/reference/androidx/media3/decoder/SimpleDecoder#isAtLeastOutputStartTimeUs(long)(long timeUs)`

Returns whether a sample time is greater or equal to the `https://developer.android.com/reference/androidx/media3/decoder/SimpleDecoder#setOutputStartTimeUs(long)`, if set.
`final void` `https://developer.android.com/reference/androidx/media3/decoder/SimpleDecoder#queueInputBuffer(I)(I inputBuffer)`

Queues an input buffer to the decoder.
`void` `@https://developer.android.com/reference/androidx/annotation/CallSuper
https://developer.android.com/reference/androidx/media3/decoder/SimpleDecoder#release()()`

Releases the decoder.
`void` `@https://developer.android.com/reference/androidx/annotation/CallSuper
https://developer.android.com/reference/androidx/media3/decoder/SimpleDecoder#releaseOutputBuffer(O)(O outputBuffer)`

Releases an output buffer back to the decoder.
`final void` `https://developer.android.com/reference/androidx/media3/decoder/SimpleDecoder#setCallback(androidx.media3.decoder.Decoder.Callback,java.util.concurrent.Executor)(https://developer.android.com/reference/androidx/media3/decoder/Decoder.Callback callback, https://developer.android.com/reference/java/util/concurrent/Executor.html executor)`

Sets the callback and executor.
`final void` `https://developer.android.com/reference/androidx/media3/decoder/SimpleDecoder#setInitialInputBufferSize(int)(int size)`

Sets the initial size of each input buffer.
`final void` `https://developer.android.com/reference/androidx/media3/decoder/SimpleDecoder#setOutputStartTimeUs(long)(long outputStartTimeUs)`

Sets the timestamp from which output buffers should be produced, in microseconds.

## Public fields

### name

```
public final String name
```

## Protected constructors

### SimpleSubtitleDecoder

```
protected SimpleSubtitleDecoder(String name)
```

| Parameters |
|---|---|
| `https://developer.android.com/reference/java/lang/String.html name` | The name of the decoder. |

## Public methods

### getName

```
public final String getName()
```

Returns the name of the decoder.

| Returns |
|---|---|
| `https://developer.android.com/reference/java/lang/String.html` | The name of the decoder. |

### setPositionUs

```
public void setPositionUs(long positionUs)
```

Informs the decoder of the current playback position.

Must be called prior to each attempt to dequeue output buffers from the decoder.

| Parameters |
|---|---|
| `long positionUs` | The current playback position in microseconds. |

## Protected methods

### createInputBuffer

```
protected final SubtitleInputBuffer createInputBuffer()
```

Creates a new input buffer.

### createOutputBuffer

```
protected final SubtitleOutputBuffer createOutputBuffer()
```

Creates a new output buffer.

### createUnexpectedDecodeException

```
protected final SubtitleDecoderException createUnexpectedDecodeException(Throwable error)
```

Creates an exception to propagate for an unexpected decode error.

| Parameters |
|---|---|
| `https://developer.android.com/reference/java/lang/Throwable.html error` | The unexpected decode error. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/extractor/text/SubtitleDecoderException` | The exception to propagate. |

### decode

```
protected abstract Subtitle decode(byte[] data, int length, boolean reset)
```

Decodes data into a `https://developer.android.com/reference/androidx/media3/extractor/text/Subtitle`.

| Parameters |
|---|---|
| `byte[] data` | An array holding the data to be decoded, starting at position 0. |
| `int length` | The number of bytes from `data` to be decoded. |
| `boolean reset` | Whether the decoder must be reset before decoding. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/extractor/text/Subtitle` | The decoded `https://developer.android.com/reference/androidx/media3/extractor/text/Subtitle`. |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/extractor/text/SubtitleDecoderException` | If a decoding error occurs. |

### decode

```
protected final @Nullable SubtitleDecoderException decode(
    SubtitleInputBuffer inputBuffer,
    SubtitleOutputBuffer outputBuffer,
    boolean reset
)
```

Decodes the `inputBuffer` and stores any decoded output in `outputBuffer`.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/extractor/text/SubtitleInputBuffer inputBuffer` | The buffer to decode. |
| `https://developer.android.com/reference/androidx/media3/extractor/text/SubtitleOutputBuffer outputBuffer` | The output buffer to store decoded data. The output buffer will not be made available to dequeue if its `https://developer.android.com/reference/androidx/media3/decoder/DecoderOutputBuffer#timeUs()` is not `https://developer.android.com/reference/androidx/media3/decoder/SimpleDecoder#isAtLeastOutputStartTimeUs(long)` or when it's marked with `https://developer.android.com/reference/androidx/media3/decoder/DecoderOutputBuffer#shouldBeSkipped()`. The output buffer may not have been populated in these cases. |
| `boolean reset` | Whether the decoder must be reset before decoding. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/extractor/text/SubtitleDecoderException` | A decoder exception if an error occurred, or null if decoding was successful. |