public final class ExtractorMediaSource extends java.lang.Object implements MediaSource
Uri
and extracted using an Extractor
.
If the possible input stream container formats are known, pass a factory that instantiates
extractors for them to the constructor. Otherwise, pass a DefaultExtractorsFactory
to
use the default extractors. When reading a new stream, the first Extractor
in the array
of extractors created by the factory that returns true
from Extractor.sniff(com.google.android.exoplayer2.extractor.ExtractorInput)
will
be used to extract samples from the input stream.
Note that the built-in extractors for AAC, MPEG PS/TS and FLV streams do not support seeking.
Modifier and Type | Class and Description |
---|---|
static interface |
ExtractorMediaSource.EventListener
Listener of
ExtractorMediaSource events. |
MediaSource.Listener, MediaSource.MediaPeriodId
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_LOADING_CHECK_INTERVAL_BYTES
The default number of bytes that should be loaded between each each invocation of
SequenceableLoader.Callback.onContinueLoadingRequested(SequenceableLoader) . |
static int |
DEFAULT_MIN_LOADABLE_RETRY_COUNT_LIVE
The default minimum number of times to retry loading prior to failing for live streams.
|
static int |
DEFAULT_MIN_LOADABLE_RETRY_COUNT_ON_DEMAND
The default minimum number of times to retry loading prior to failing for on-demand streams.
|
static int |
MIN_RETRY_COUNT_DEFAULT_FOR_MEDIA
Value for
minLoadableRetryCount that causes the loader to retry
DEFAULT_MIN_LOADABLE_RETRY_COUNT_LIVE times for live streams and
DEFAULT_MIN_LOADABLE_RETRY_COUNT_ON_DEMAND for on-demand streams. |
Constructor and Description |
---|
ExtractorMediaSource(android.net.Uri uri,
DataSource.Factory dataSourceFactory,
ExtractorsFactory extractorsFactory,
android.os.Handler eventHandler,
ExtractorMediaSource.EventListener eventListener) |
ExtractorMediaSource(android.net.Uri uri,
DataSource.Factory dataSourceFactory,
ExtractorsFactory extractorsFactory,
android.os.Handler eventHandler,
ExtractorMediaSource.EventListener eventListener,
java.lang.String customCacheKey) |
ExtractorMediaSource(android.net.Uri uri,
DataSource.Factory dataSourceFactory,
ExtractorsFactory extractorsFactory,
int minLoadableRetryCount,
android.os.Handler eventHandler,
ExtractorMediaSource.EventListener eventListener,
java.lang.String customCacheKey,
int continueLoadingCheckIntervalBytes) |
Modifier and Type | Method and Description |
---|---|
MediaPeriod |
createPeriod(MediaSource.MediaPeriodId id,
Allocator allocator)
Returns a new
MediaPeriod identified by periodId . |
void |
maybeThrowSourceInfoRefreshError()
Throws any pending error encountered while loading or refreshing source information.
|
void |
onSourceInfoRefreshed(long durationUs,
boolean isSeekable)
Called when the duration or ability to seek within the period changes.
|
void |
prepareSource(ExoPlayer player,
boolean isTopLevelSource,
MediaSource.Listener listener)
Starts preparation of the source.
|
void |
releasePeriod(MediaPeriod mediaPeriod)
Releases the period.
|
void |
releaseSource()
Releases the source.
|
public static final int DEFAULT_MIN_LOADABLE_RETRY_COUNT_ON_DEMAND
public static final int DEFAULT_MIN_LOADABLE_RETRY_COUNT_LIVE
public static final int MIN_RETRY_COUNT_DEFAULT_FOR_MEDIA
minLoadableRetryCount
that causes the loader to retry
DEFAULT_MIN_LOADABLE_RETRY_COUNT_LIVE
times for live streams and
DEFAULT_MIN_LOADABLE_RETRY_COUNT_ON_DEMAND
for on-demand streams.public static final int DEFAULT_LOADING_CHECK_INTERVAL_BYTES
SequenceableLoader.Callback.onContinueLoadingRequested(SequenceableLoader)
.public ExtractorMediaSource(android.net.Uri uri, DataSource.Factory dataSourceFactory, ExtractorsFactory extractorsFactory, android.os.Handler eventHandler, ExtractorMediaSource.EventListener eventListener)
uri
- The Uri
of the media stream.dataSourceFactory
- A factory for DataSource
s to read the media.extractorsFactory
- A factory for Extractor
s to process the media stream. If the
possible formats are known, pass a factory that instantiates extractors for those formats.
Otherwise, pass a DefaultExtractorsFactory
to use default extractors.eventHandler
- A handler for events. May be null if delivery of events is not required.eventListener
- A listener of events. May be null if delivery of events is not required.public ExtractorMediaSource(android.net.Uri uri, DataSource.Factory dataSourceFactory, ExtractorsFactory extractorsFactory, android.os.Handler eventHandler, ExtractorMediaSource.EventListener eventListener, java.lang.String customCacheKey)
uri
- The Uri
of the media stream.dataSourceFactory
- A factory for DataSource
s to read the media.extractorsFactory
- A factory for Extractor
s to process the media stream. If the
possible formats are known, pass a factory that instantiates extractors for those formats.
Otherwise, pass a DefaultExtractorsFactory
to use default extractors.eventHandler
- A handler for events. May be null if delivery of events is not required.eventListener
- A listener of events. May be null if delivery of events is not required.customCacheKey
- A custom key that uniquely identifies the original stream. Used for cache
indexing. May be null.public ExtractorMediaSource(android.net.Uri uri, DataSource.Factory dataSourceFactory, ExtractorsFactory extractorsFactory, int minLoadableRetryCount, android.os.Handler eventHandler, ExtractorMediaSource.EventListener eventListener, java.lang.String customCacheKey, int continueLoadingCheckIntervalBytes)
uri
- The Uri
of the media stream.dataSourceFactory
- A factory for DataSource
s to read the media.extractorsFactory
- A factory for Extractor
s to process the media stream. If the
possible formats are known, pass a factory that instantiates extractors for those formats.
Otherwise, pass a DefaultExtractorsFactory
to use default extractors.minLoadableRetryCount
- The minimum number of times to retry if a loading error occurs.eventHandler
- A handler for events. May be null if delivery of events is not required.eventListener
- A listener of events. May be null if delivery of events is not required.customCacheKey
- A custom key that uniquely identifies the original stream. Used for cache
indexing. May be null.continueLoadingCheckIntervalBytes
- The number of bytes that should be loaded between each
invocation of SequenceableLoader.Callback.onContinueLoadingRequested(SequenceableLoader)
.public void prepareSource(ExoPlayer player, boolean isTopLevelSource, MediaSource.Listener listener)
MediaSource
prepareSource
in interface MediaSource
player
- The player for which this source is being prepared.isTopLevelSource
- Whether this source has been passed directly to
ExoPlayer.prepare(MediaSource)
or
ExoPlayer.prepare(MediaSource, boolean, boolean)
. If false
, this source is
being prepared by another source (e.g. ConcatenatingMediaSource
) for composition.listener
- The listener for source events.public void maybeThrowSourceInfoRefreshError() throws java.io.IOException
MediaSource
maybeThrowSourceInfoRefreshError
in interface MediaSource
java.io.IOException
public MediaPeriod createPeriod(MediaSource.MediaPeriodId id, Allocator allocator)
MediaSource
MediaPeriod
identified by periodId
. This method may be called
multiple times with the same period identifier without an intervening call to
MediaSource.releasePeriod(MediaPeriod)
.createPeriod
in interface MediaSource
id
- The identifier of the period.allocator
- An Allocator
from which to obtain media buffer allocations.MediaPeriod
.public void releasePeriod(MediaPeriod mediaPeriod)
MediaSource
releasePeriod
in interface MediaSource
mediaPeriod
- The period to release.public void releaseSource()
MediaSource
This method should be called when the source is no longer required. It may be called in any state.
releaseSource
in interface MediaSource
public void onSourceInfoRefreshed(long durationUs, boolean isSeekable)
durationUs
- The duration of the period, or C.TIME_UNSET
.isSeekable
- Whether the period is seekable.