public final class SingleSampleSource extends Object implements SampleSource, SampleSource.SampleSourceReader, Loader.Callback, Loader.Loadable
SampleSource that loads the data at a given Uri as a single sample.| Modifier and Type | Class and Description |
|---|---|
static interface |
SingleSampleSource.EventListener
Interface definition for a callback to be notified of
SingleSampleSource events. |
SampleSource.SampleSourceReader| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_MIN_LOADABLE_RETRY_COUNT
The default minimum number of times to retry loading data prior to failing.
|
END_OF_STREAM, FORMAT_READ, NO_DISCONTINUITY, NOTHING_READ, SAMPLE_READ| Constructor and Description |
|---|
SingleSampleSource(Uri uri,
DataSource dataSource,
MediaFormat format) |
SingleSampleSource(Uri uri,
DataSource dataSource,
MediaFormat format,
int minLoadableRetryCount) |
SingleSampleSource(Uri uri,
DataSource dataSource,
MediaFormat format,
int minLoadableRetryCount,
Handler eventHandler,
SingleSampleSource.EventListener eventListener,
int eventSourceId) |
| Modifier and Type | Method and Description |
|---|---|
void |
cancelLoad()
Cancels the load.
|
boolean |
continueBuffering(int track,
long positionUs)
Indicates to the source that it should still be buffering data for the specified track.
|
void |
disable(int track)
Disable the specified track.
|
void |
enable(int track,
long positionUs)
Enable the specified track.
|
long |
getBufferedPositionUs()
Returns an estimate of the position up to which data is buffered.
|
MediaFormat |
getFormat(int track)
Returns the format of the specified track.
|
int |
getTrackCount()
Returns the number of tracks exposed by the source.
|
boolean |
isLoadCanceled()
Whether the load has been canceled.
|
void |
load()
Performs the load, returning on completion or cancelation.
|
void |
maybeThrowError()
If the source is currently having difficulty preparing or loading samples, then this method
throws the underlying error.
|
void |
onLoadCanceled(Loader.Loadable loadable)
Invoked when loading has been canceled.
|
void |
onLoadCompleted(Loader.Loadable loadable)
Invoked when the data source has been fully loaded.
|
void |
onLoadError(Loader.Loadable loadable,
IOException e)
Invoked when the data source is stopped due to an error.
|
boolean |
prepare(long positionUs)
Prepares the source.
|
int |
readData(int track,
long positionUs,
MediaFormatHolder formatHolder,
SampleHolder sampleHolder)
Attempts to read a sample or a new format from the source.
|
long |
readDiscontinuity(int track)
Attempts to read a pending discontinuity from the source.
|
SampleSource.SampleSourceReader |
register()
A consumer of samples should call this method to register themselves and gain access to the
source through the returned
SampleSource.SampleSourceReader. |
void |
release()
Releases the
SampleSource.SampleSourceReader. |
void |
seekToUs(long positionUs)
Seeks to the specified time in microseconds.
|
public static final int DEFAULT_MIN_LOADABLE_RETRY_COUNT
public SingleSampleSource(Uri uri, DataSource dataSource, MediaFormat format)
public SingleSampleSource(Uri uri, DataSource dataSource, MediaFormat format, int minLoadableRetryCount)
public SingleSampleSource(Uri uri, DataSource dataSource, MediaFormat format, int minLoadableRetryCount, Handler eventHandler, SingleSampleSource.EventListener eventListener, int eventSourceId)
public SampleSource.SampleSourceReader register()
SampleSourceSampleSource.SampleSourceReader.
SampleSource.SampleSourceReader.release() should be called on the returned object when access is no
longer required.
register in interface SampleSourceSampleSource.SampleSourceReader that provides access to the source.public boolean prepare(long positionUs)
SampleSource.SampleSourceReader
Preparation may require reading from the data source (e.g. to determine the available tracks
and formats). If insufficient data is available then the call will return false
rather than block. The method can be called repeatedly until the return value indicates
success.
prepare in interface SampleSource.SampleSourceReaderpositionUs - The player's current playback position.public int getTrackCount()
SampleSource.SampleSourceReaderThis method should only be called after the source has been prepared.
getTrackCount in interface SampleSource.SampleSourceReaderpublic MediaFormat getFormat(int track)
SampleSource.SampleSourceReader
Note that whilst the format of a track will remain constant, the format of the actual media
stream may change dynamically. An example of this is where the track is adaptive
(i.e. @link MediaFormat.adaptive is true). Hence the track formats returned through
this method should not be used to configure decoders. Decoder configuration should be
performed using the formats obtained when reading the media stream through calls to
SampleSource.SampleSourceReader.readData(int, long, MediaFormatHolder, SampleHolder).
This method should only be called after the source has been prepared.
getFormat in interface SampleSource.SampleSourceReadertrack - The track index.public void enable(int track,
long positionUs)
SampleSource.SampleSourceReaderSampleSource.SampleSourceReader.readData(int, long, MediaFormatHolder, SampleHolder).
This method should only be called after the source has been prepared, and when the specified track is disabled.
enable in interface SampleSource.SampleSourceReadertrack - The track to enable.positionUs - The player's current playback position.public boolean continueBuffering(int track,
long positionUs)
SampleSource.SampleSourceReaderThis method should only be called when the specified track is enabled.
continueBuffering in interface SampleSource.SampleSourceReadertrack - The track to continue buffering.positionUs - The current playback position.public void maybeThrowError()
throws IOException
SampleSource.SampleSourceReadermaybeThrowError in interface SampleSource.SampleSourceReaderIOException - The underlying error.public long readDiscontinuity(int track)
SampleSource.SampleSourceReaderThis method should only be called when the specified track is enabled.
readDiscontinuity in interface SampleSource.SampleSourceReadertrack - The track from which to read.SampleSource.NO_DISCONTINUITY.public int readData(int track,
long positionUs,
MediaFormatHolder formatHolder,
SampleHolder sampleHolder)
SampleSource.SampleSourceReaderThis method should only be called when the specified track is enabled.
Note that where multiple tracks are enabled, SampleSource.NOTHING_READ may be returned if the
next piece of data to be read from the SampleSource corresponds to a different track
than the one for which data was requested.
This method will always return SampleSource.NOTHING_READ in the case that there's a pending
discontinuity to be read from SampleSource.SampleSourceReader.readDiscontinuity(int) for the specified track.
readData in interface SampleSource.SampleSourceReadertrack - The track from which to read.positionUs - The current playback position.formatHolder - A MediaFormatHolder object to populate in the case of a new
format.sampleHolder - A SampleHolder object to populate in the case of a new sample.
If the caller requires the sample data then it must ensure that SampleHolder.data
references a valid output buffer.SampleSource.SAMPLE_READ, SampleSource.FORMAT_READ,
SampleSource.NOTHING_READ or SampleSource.END_OF_STREAM.public void seekToUs(long positionUs)
SampleSource.SampleSourceReaderThis method should only be called when at least one track is enabled.
seekToUs in interface SampleSource.SampleSourceReaderpositionUs - The seek position in microseconds.public long getBufferedPositionUs()
SampleSource.SampleSourceReaderThis method should only be called when at least one track is enabled.
getBufferedPositionUs in interface SampleSource.SampleSourceReaderTrackRenderer.END_OF_TRACK_US if data is buffered to the end of the stream,
or TrackRenderer.UNKNOWN_TIME_US if no estimate is available.public void disable(int track)
SampleSource.SampleSourceReaderThis method should only be called when the specified track is enabled.
disable in interface SampleSource.SampleSourceReadertrack - The track to disable.public void release()
SampleSource.SampleSourceReaderSampleSource.SampleSourceReader.
This method should be called when access to the SampleSource is no longer required.
release in interface SampleSource.SampleSourceReaderpublic void onLoadCompleted(Loader.Loadable loadable)
Loader.CallbackonLoadCompleted in interface Loader.Callbackloadable - The loadable whose load has completed.public void onLoadCanceled(Loader.Loadable loadable)
Loader.CallbackonLoadCanceled in interface Loader.Callbackloadable - The loadable whose load has been canceled.public void onLoadError(Loader.Loadable loadable, IOException e)
Loader.CallbackonLoadError in interface Loader.Callbackloadable - The loadable whose load has failed.public void cancelLoad()
Loader.LoadablecancelLoad in interface Loader.Loadablepublic boolean isLoadCanceled()
Loader.LoadableisLoadCanceled in interface Loader.Loadablepublic void load()
throws IOException,
InterruptedException
Loader.Loadableload in interface Loader.LoadableIOExceptionInterruptedException