@Deprecated public final class FrameworkSampleSource extends Object implements SampleSource, SampleSource.SampleSourceReader
MediaExtractor
.
Warning - This class is marked as deprecated because there are known device specific issues
associated with its use, including playbacks not starting, playbacks stuttering and other
miscellaneous failures. For mp4, m4a, mp3, webm, mkv, mpeg-ts, ogg, wav and aac playbacks it is
strongly recommended to use ExtractorSampleSource
instead. Where this is not possible
this class can still be used, but please be aware of the associated risks. Playing container
formats for which an ExoPlayer extractor does not yet exist (e.g. avi) is a valid use case of
this class.
Over time we hope to enhance ExtractorSampleSource
to support more formats, and hence
make use of this class unnecessary.
SampleSource.SampleSourceReader
END_OF_STREAM, FORMAT_READ, NO_DISCONTINUITY, NOTHING_READ, SAMPLE_READ
Constructor and Description |
---|
FrameworkSampleSource(Context context,
Uri uri,
Map<String,String> headers)
Deprecated.
Instantiates a new sample extractor reading from the specified
uri . |
FrameworkSampleSource(FileDescriptor fileDescriptor,
long fileDescriptorOffset,
long fileDescriptorLength)
Deprecated.
Instantiates a new sample extractor reading from the specified seekable
fileDescriptor . |
Modifier and Type | Method and Description |
---|---|
boolean |
continueBuffering(int track,
long positionUs)
Deprecated.
Indicates to the source that it should still be buffering data for the specified track.
|
void |
disable(int track)
Deprecated.
Disable the specified track.
|
void |
enable(int track,
long positionUs)
Deprecated.
Enable the specified track.
|
long |
getBufferedPositionUs()
Deprecated.
Returns an estimate of the position up to which data is buffered.
|
MediaFormat |
getFormat(int track)
Deprecated.
Returns the format of the specified track.
|
int |
getTrackCount()
Deprecated.
Returns the number of tracks exposed by the source.
|
void |
maybeThrowError()
Deprecated.
If the source is currently having difficulty preparing or loading samples, then this method
throws the underlying error.
|
boolean |
prepare(long positionUs)
Deprecated.
Prepares the source.
|
int |
readData(int track,
long positionUs,
MediaFormatHolder formatHolder,
SampleHolder sampleHolder)
Deprecated.
Attempts to read a sample or a new format from the source.
|
long |
readDiscontinuity(int track)
Deprecated.
Attempts to read a pending discontinuity from the source.
|
SampleSource.SampleSourceReader |
register()
Deprecated.
A consumer of samples should call this method to register themselves and gain access to the
source through the returned
SampleSource.SampleSourceReader . |
void |
release()
Deprecated.
Releases the
SampleSource.SampleSourceReader . |
void |
seekToUs(long positionUs)
Deprecated.
Seeks to the specified time in microseconds.
|
public FrameworkSampleSource(Context context, Uri uri, Map<String,String> headers)
uri
.context
- Context for resolving uri
.uri
- The content URI from which to extract data.headers
- Headers to send with requests for data.public FrameworkSampleSource(FileDescriptor fileDescriptor, long fileDescriptorOffset, long fileDescriptorLength)
fileDescriptor
.
The caller is responsible for releasing the file descriptor.fileDescriptor
- File descriptor from which to read.fileDescriptorOffset
- The offset in bytes where the data to be extracted starts.fileDescriptorLength
- The length in bytes of the data to be extracted.public SampleSource.SampleSourceReader register()
SampleSource
SampleSource.SampleSourceReader
.
SampleSource.SampleSourceReader.release()
should be called on the returned object when access is no
longer required.
register
in interface SampleSource
SampleSource.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.SampleSourceReader
positionUs
- The player's current playback position.public int getTrackCount()
SampleSource.SampleSourceReader
This method should only be called after the source has been prepared.
getTrackCount
in interface SampleSource.SampleSourceReader
public 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.SampleSourceReader
track
- The track index.public void enable(int track, long positionUs)
SampleSource.SampleSourceReader
SampleSource.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.SampleSourceReader
track
- The track to enable.positionUs
- The player's current playback position.public boolean continueBuffering(int track, long positionUs)
SampleSource.SampleSourceReader
This method should only be called when the specified track is enabled.
continueBuffering
in interface SampleSource.SampleSourceReader
track
- The track to continue buffering.positionUs
- The current playback position.public long readDiscontinuity(int track)
SampleSource.SampleSourceReader
This method should only be called when the specified track is enabled.
readDiscontinuity
in interface SampleSource.SampleSourceReader
track
- The track from which to read.SampleSource.NO_DISCONTINUITY
.public int readData(int track, long positionUs, MediaFormatHolder formatHolder, SampleHolder sampleHolder)
SampleSource.SampleSourceReader
This 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.SampleSourceReader
track
- 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 disable(int track)
SampleSource.SampleSourceReader
This method should only be called when the specified track is enabled.
disable
in interface SampleSource.SampleSourceReader
track
- The track to disable.public void maybeThrowError() throws IOException
SampleSource.SampleSourceReader
maybeThrowError
in interface SampleSource.SampleSourceReader
IOException
- The underlying error.public void seekToUs(long positionUs)
SampleSource.SampleSourceReader
This method should only be called when at least one track is enabled.
seekToUs
in interface SampleSource.SampleSourceReader
positionUs
- The seek position in microseconds.public long getBufferedPositionUs()
SampleSource.SampleSourceReader
This method should only be called when at least one track is enabled.
getBufferedPositionUs
in interface SampleSource.SampleSourceReader
TrackRenderer.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 release()
SampleSource.SampleSourceReader
SampleSource.SampleSourceReader
.
This method should be called when access to the SampleSource
is no longer required.
release
in interface SampleSource.SampleSourceReader