DataChunk
@UnstableApi
public abstract class DataChunk extends Chunk
| java.lang.Object | ||
| ↳ | androidx.media3.exoplayer.source.chunk.Chunk | |
| ↳ | androidx.media3.exoplayer.source.chunk.DataChunk |
A base class for Chunk implementations where the data should be loaded into a
byte[] before being consumed.
Summary
Public constructors |
|---|
DataChunk( |
Public methods |
|
|---|---|
final void |
Cancels the load. |
byte[] |
Returns the array in which the data is held. |
final void |
load()Performs the load, returning on completion or cancellation. |
Inherited fields |
||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Inherited methods |
|---|
Public constructors
DataChunk
public DataChunk(
DataSource dataSource,
DataSpec dataSpec,
@C.DataType int type,
Format trackFormat,
@C.SelectionReason int trackSelectionReason,
@Nullable Object trackSelectionData,
@Nullable byte[] data
)
| Parameters | |
|---|---|
DataSource dataSource |
The source from which the data should be loaded. |
DataSpec dataSpec |
Defines the data to be loaded. |
@C.DataType int type |
See |
Format trackFormat |
See |
@C.SelectionReason int trackSelectionReason |
See |
@Nullable Object trackSelectionData |
See |
@Nullable byte[] data |
An optional recycled array that can be used as a holder for the data. |
Public methods
cancelLoad
public final void cancelLoad()
Cancels the load.
Loadable implementations should ensure that a currently executing load call will exit reasonably quickly after this method is called. The load call may exit either by returning or by throwing an IOException.
If there is a currently executing load call, then the thread on which that call is being made will be interrupted immediately after the call to this method. Hence implementations do not need to (and should not attempt to) interrupt the loading thread themselves.
Although the loading thread will be interrupted, Loadable implementations should not use the interrupted status of the loading thread in load to determine whether the load has been canceled. This approach is not robust [Internal ref: b/79223737]. Instead, implementations should use their own flag to signal cancelation (for example, using AtomicBoolean).
getDataHolder
public byte[] getDataHolder()
Returns the array in which the data is held.
This method should be used for recycling the holder only, and not for reading the data.
| Returns | |
|---|---|
byte[] |
The array in which the data is held. |
load
public final void load()
Performs the load, returning on completion or cancellation.
| Throws | |
|---|---|
java.io.IOException |
If the input could not be loaded. |
Protected methods
consume
protected abstract void consume(byte[] data, int limit)
Called by load. Implementations should override this method to consume the loaded data.
| Parameters | |
|---|---|
byte[] data |
An array containing the data. |
int limit |
The limit of the data. |
| Throws | |
|---|---|
java.io.IOException |
If an error occurs consuming the loaded data. |