public abstract class DataChunk extends Chunk
Chunk implementations where the data should be loaded into a
byte[] before being consumed.dataSource, dataSpec, format, NO_PARENT_ID, parentId, trigger, TRIGGER_ADAPTIVE, TRIGGER_CUSTOM_BASE, TRIGGER_INITIAL, TRIGGER_MANUAL, TRIGGER_TRICK_PLAY, TRIGGER_UNSPECIFIED, type, TYPE_CUSTOM_BASE, TYPE_DRM, TYPE_MANIFEST, TYPE_MEDIA, TYPE_MEDIA_INITIALIZATION, TYPE_UNSPECIFIED| Constructor and Description |
|---|
DataChunk(DataSource dataSource,
DataSpec dataSpec,
int type,
int trigger,
Format format,
int parentId,
byte[] data) |
| Modifier and Type | Method and Description |
|---|---|
long |
bytesLoaded()
Gets the number of bytes that have been loaded.
|
void |
cancelLoad()
Cancels the load.
|
protected abstract void |
consume(byte[] data,
int limit)
Invoked by
load(). |
byte[] |
getDataHolder()
Returns the array in which the data is held.
|
boolean |
isLoadCanceled()
Whether the load has been canceled.
|
void |
load()
Performs the load, returning on completion or cancelation.
|
public DataChunk(DataSource dataSource, DataSpec dataSpec, int type, int trigger, Format format, int parentId, byte[] data)
dataSource - The source from which the data should be loaded.dataSpec - Defines the data to be loaded. dataSpec.length must not exceed
Integer.MAX_VALUE. If dataSpec.length == C.LENGTH_UNBOUNDED then
the length resolved by dataSource.open(dataSpec) must not exceed
Integer.MAX_VALUE.type - See Chunk.type.trigger - See Chunk.trigger.format - See Chunk.format.parentId - Identifier for a parent from which this chunk originates.data - An optional recycled array that can be used as a holder for the data.public byte[] getDataHolder()
This method should be used for recycling the holder only, and not for reading the data.
public long bytesLoaded()
ChunkbytesLoaded in class Chunkpublic final void cancelLoad()
Loader.Loadablepublic final boolean isLoadCanceled()
Loader.Loadablepublic final void load()
throws IOException,
InterruptedException
Loader.LoadableIOExceptionInterruptedExceptionprotected abstract void consume(byte[] data,
int limit)
throws IOException
load(). Implementations should override this method to consume the loaded
data.data - An array containing the data.limit - The limit of the data.IOException - If an error occurs consuming the loaded data.