DefaultMediaSourceFactory
public final class DefaultMediaSourceFactory implements MediaSourceFactory
The default MediaSource.Factory implementation.
This implementation delegates calls to createMediaSource to the following factories:
DashMediaSource.Factoryif the item'suriends in '.mpd' or if itsmimeType fieldis explicitly set toAPPLICATION_MPD(Requires the exoplayer-dash module to be added to the app).HlsMediaSource.Factoryif the item'suriends in '.m3u8' or if itsmimeType fieldis explicitly set toAPPLICATION_M3U8(Requires the exoplayer-hls module to be added to the app).SsMediaSource.Factoryif the item'suriends in '.ism', '.ism/Manifest' or if itsmimeType fieldis explicitly set toAPPLICATION_SS(Requires the exoplayer-smoothstreaming module to be added to the app).ProgressiveMediaSource.Factoryserves as a fallback if the item'suridoesn't match one of the above. It tries to infer the required extractor by using theDefaultExtractorsFactoryor theExtractorsFactoryprovided in the constructor. AnUnrecognizedInputFormatExceptionis thrown if none of the available extractors can read the stream.
Ad support for media items with ad tag URIs
To support media items with ads configuration, setAdsLoaderProvider and setAdViewProvider need to be called to configure the factory with the required providers.
Summary
Nested types |
|---|
@UnstableApiThis interface is deprecated. Use |
Public constructors |
|---|
DefaultMediaSourceFactory(Context context)Creates a new instance. |
@UnstableApiCreates a new instance. |
@UnstableApiCreates a new instance. |
@UnstableApiCreates a new instance. |
@UnstableApiCreates a new instance. |
Inherited Constants |
||
|---|---|---|
|
||
|
Public constructors
DefaultMediaSourceFactory
public DefaultMediaSourceFactory(Context context)
Creates a new instance.
| Parameters | |
|---|---|
Context context |
Any context. |
DefaultMediaSourceFactory
@UnstableApi
public DefaultMediaSourceFactory(DataSource.Factory dataSourceFactory)
Creates a new instance.
Note that this constructor is only useful to try and ensure that ExoPlayer's DefaultDataSource.Factory can be removed by ProGuard or R8.
| Parameters | |
|---|---|
DataSource.Factory dataSourceFactory |
A |
DefaultMediaSourceFactory
@UnstableApi
public DefaultMediaSourceFactory(
Context context,
ExtractorsFactory extractorsFactory
)
Creates a new instance.
Note that this constructor is only useful to try and ensure that ExoPlayer's DefaultExtractorsFactory can be removed by ProGuard or R8.
| Parameters | |
|---|---|
Context context |
Any context. |
ExtractorsFactory extractorsFactory |
An |
DefaultMediaSourceFactory
@UnstableApi
public DefaultMediaSourceFactory(
DataSource.Factory dataSourceFactory,
ExtractorsFactory extractorsFactory
)
Creates a new instance.
Note that this constructor is only useful to try and ensure that ExoPlayer's DefaultDataSource.Factory and DefaultExtractorsFactory can be removed by ProGuard or R8.
| Parameters | |
|---|---|
DataSource.Factory dataSourceFactory |
A |
ExtractorsFactory extractorsFactory |
An |
DefaultMediaSourceFactory
@UnstableApi
public DefaultMediaSourceFactory(
DataSource.Factory dataSourceFactory,
ExtractorsFactory extractorsFactory,
SubtitleParser.Factory subtitleParserFactory
)
Creates a new instance.
Note that this constructor is only useful to try and ensure that ExoPlayer's DefaultDataSource.Factory, DefaultExtractorsFactory and DefaultSubtitleParserFactory can be removed by ProGuard or R8.
| Parameters | |
|---|---|
DataSource.Factory dataSourceFactory |
A |
ExtractorsFactory extractorsFactory |
An |
SubtitleParser.Factory subtitleParserFactory |
A |
Public methods
clearLocalAdInsertionComponents
@CanIgnoreReturnValue
public DefaultMediaSourceFactory clearLocalAdInsertionComponents()
Clear any values set via setLocalAdInsertionComponents.
This will also clear any values set by setAdsLoaderProvider and setAdViewProvider.
| Returns | |
|---|---|
DefaultMediaSourceFactory |
This factory, for convenience. |
createMediaSource
@UnstableApi
public MediaSource createMediaSource(MediaItem mediaItem)
Creates a new MediaSource with the specified MediaItem.
| Parameters | |
|---|---|
MediaItem mediaItem |
The media item to play. |
| Returns | |
|---|---|
MediaSource |
The new |
experimentalParseSubtitlesDuringExtraction
@CanIgnoreReturnValue
@UnstableApi
public DefaultMediaSourceFactoryexperimentalParseSubtitlesDuringExtraction(
boolean parseSubtitlesDuringExtraction
)
Sets whether subtitles should be parsed as part of extraction (before being added to the sample queue) or as part of rendering (when being taken from the sample queue). Defaults to true (i.e. subtitles will be parsed during extraction).
This method is experimental and will be renamed or removed in a future release.
| Parameters | |
|---|---|
boolean parseSubtitlesDuringExtraction |
Whether to parse subtitles during extraction or rendering. |
| Returns | |
|---|---|
DefaultMediaSourceFactory |
This factory, for convenience. |
experimentalSetCodecsToParseWithinGopSampleDependencies
@CanIgnoreReturnValue
@UnstableApi
public DefaultMediaSourceFactory experimentalSetCodecsToParseWithinGopSampleDependencies(
@C.VideoCodecFlags int codecsToParseWithinGopSampleDependencies
)
Sets the set of video codecs for which within GOP sample dependency information should be parsed as part of extraction. Defaults to H.264 and H.265.
Having access to additional sample dependency information can speed up seeking. See FLAG_READ_WITHIN_GOP_SAMPLE_DEPENDENCIES.
This method is experimental and will be renamed or removed in a future release.
| Parameters | |
|---|---|
@C.VideoCodecFlags int codecsToParseWithinGopSampleDependencies |
The set of codecs for which to parse within GOP sample dependency information. |
| Returns | |
|---|---|
DefaultMediaSourceFactory |
This factory, for convenience. |
getSupportedTypes
@UnstableApi
@C.ContentType
public int[] getSupportedTypes()
Returns the content types supported by media sources created by this factory.
setAdViewProvider
@CanIgnoreReturnValue
@UnstableApi
public DefaultMediaSourceFactorysetAdViewProvider(@Nullable AdViewProvider adViewProvider)
Sets the AdViewProvider that provides information about views for the ad playback UI.
This will override or clear the AdViewProvider set by setLocalAdInsertionComponents.
| Parameters | |
|---|---|
@Nullable AdViewProvider adViewProvider |
A provider for information about views for the ad playback UI. |
| Returns | |
|---|---|
DefaultMediaSourceFactory |
This factory, for convenience. |
setAdsLoaderProvider
@CanIgnoreReturnValue
@UnstableApi
public DefaultMediaSourceFactorysetAdsLoaderProvider(@Nullable AdsLoader.Provider adsLoaderProvider)
Sets the AdsLoader.Provider that provides AdsLoader instances for media items that have ads configurations.
This will override or clear the AdsLoader.Provider set by setLocalAdInsertionComponents.
| Parameters | |
|---|---|
@Nullable AdsLoader.Provider adsLoaderProvider |
A provider for |
| Returns | |
|---|---|
DefaultMediaSourceFactory |
This factory, for convenience. |
setCmcdConfigurationFactory
@CanIgnoreReturnValue
@UnstableApi
public DefaultMediaSourceFactory setCmcdConfigurationFactory(
CmcdConfiguration.Factory cmcdConfigurationFactory
)
Sets the CmcdConfiguration.Factory used to obtain a CmcdConfiguration for a MediaItem.
| Returns | |
|---|---|
DefaultMediaSourceFactory |
This factory, for convenience. |
setDataSourceFactory
@CanIgnoreReturnValue
public DefaultMediaSourceFactory setDataSourceFactory(DataSource.Factory dataSourceFactory)
Sets the DataSource.Factory used to create DataSource instances for requesting media data.
| Parameters | |
|---|---|
DataSource.Factory dataSourceFactory |
The |
| Returns | |
|---|---|
DefaultMediaSourceFactory |
This factory, for convenience. |
setDownloadExecutor
@UnstableApi
@CanIgnoreReturnValue
public MediaSource.Factory setDownloadExecutor(Supplier<ReleasableExecutor> downloadExecutor)
Sets a supplier for an ReleasableExecutor that is used for loading the media.
| Parameters | |
|---|---|
Supplier<ReleasableExecutor> downloadExecutor |
A |
| Returns | |
|---|---|
MediaSource.Factory |
This factory, for convenience. |
setDrmSessionManagerProvider
@CanIgnoreReturnValue
@UnstableApi
public DefaultMediaSourceFactory setDrmSessionManagerProvider(
DrmSessionManagerProvider drmSessionManagerProvider
)
Sets the DrmSessionManagerProvider used to obtain a DrmSessionManager for a MediaItem.
| Returns | |
|---|---|
DefaultMediaSourceFactory |
This factory, for convenience. |
setEnableClippingInMediaPeriod
@ExperimentalApi
@CanIgnoreReturnValue
public DefaultMediaSourceFactory setEnableClippingInMediaPeriod(boolean enableClippingInMediaPeriod)
Sets whether an experimental setting to delegate end position clipping to a wrapped MediaPeriod is enabled.
The default value is false.
| Parameters | |
|---|---|
boolean enableClippingInMediaPeriod |
Whether the end clipping should be delegated to the wrapped |
| Returns | |
|---|---|
DefaultMediaSourceFactory |
This factory, for convenience. |
setExperimentalEnableHagcPlayback
@CanIgnoreReturnValue
@UnstableApi
public DefaultMediaSourceFactory setExperimentalEnableHagcPlayback(boolean enableHagcPlayback)
Sets whether to enable experimental HAGC (ST 2094-50) metadata playback support. When enabled, the player will automatically merge HAGC metadata tracks with the associated video track and deliver the metadata out-of-band to the decoder on API 37+.
The default value is true.
| Parameters | |
|---|---|
boolean enableHagcPlayback |
Whether experimental HAGC metadata playback is enabled. |
| Returns | |
|---|---|
DefaultMediaSourceFactory |
This factory, for convenience. |
setExternalImageLoader
@CanIgnoreReturnValue
@UnstableApi
public DefaultMediaSourceFactory setExternalImageLoader(@Nullable ExternalLoader externalImageLoader)
Sets the ExternalLoader to be called when loading starts in ExternallyLoadedMediaSource when loading images in an external Image Management Framework (for example, Glide).
This loader is only used when the mimeType is set to APPLICATION_EXTERNALLY_LOADED_IMAGE.
| Parameters | |
|---|---|
@Nullable ExternalLoader externalImageLoader |
The |
| Returns | |
|---|---|
DefaultMediaSourceFactory |
This factory, for convenience. |
setLiveMaxOffsetMs
@CanIgnoreReturnValue
@UnstableApi
public DefaultMediaSourceFactory setLiveMaxOffsetMs(long liveMaxOffsetMs)
Sets the maximum offset from the live edge for live streams, in milliseconds.
| Parameters | |
|---|---|
long liveMaxOffsetMs |
The maximum allowed live offset, in milliseconds, or |
| Returns | |
|---|---|
DefaultMediaSourceFactory |
This factory, for convenience. |
setLiveMaxSpeed
@CanIgnoreReturnValue
@UnstableApi
public DefaultMediaSourceFactory setLiveMaxSpeed(float maxSpeed)
Sets the maximum playback speed for live streams.
| Parameters | |
|---|---|
float maxSpeed |
The maximum factor by which playback can be sped up for live streams, or |
| Returns | |
|---|---|
DefaultMediaSourceFactory |
This factory, for convenience. |
setLiveMinOffsetMs
@CanIgnoreReturnValue
@UnstableApi
public DefaultMediaSourceFactory setLiveMinOffsetMs(long liveMinOffsetMs)
Sets the minimum offset from the live edge for live streams, in milliseconds.
| Parameters | |
|---|---|
long liveMinOffsetMs |
The minimum allowed live offset, in milliseconds, or |
| Returns | |
|---|---|
DefaultMediaSourceFactory |
This factory, for convenience. |
setLiveMinSpeed
@CanIgnoreReturnValue
@UnstableApi
public DefaultMediaSourceFactory setLiveMinSpeed(float minSpeed)
Sets the minimum playback speed for live streams.
| Parameters | |
|---|---|
float minSpeed |
The minimum factor by which playback can be sped up for live streams, or |
| Returns | |
|---|---|
DefaultMediaSourceFactory |
This factory, for convenience. |
setLiveTargetOffsetMs
@CanIgnoreReturnValue
@UnstableApi
public DefaultMediaSourceFactory setLiveTargetOffsetMs(long liveTargetOffsetMs)
Sets the target live offset for live streams, in milliseconds.
| Parameters | |
|---|---|
long liveTargetOffsetMs |
The target live offset, in milliseconds, or |
| Returns | |
|---|---|
DefaultMediaSourceFactory |
This factory, for convenience. |
setLoadErrorHandlingPolicy
@CanIgnoreReturnValue
@UnstableApi
public DefaultMediaSourceFactory setLoadErrorHandlingPolicy(
LoadErrorHandlingPolicy loadErrorHandlingPolicy
)
Sets an optional LoadErrorHandlingPolicy.
| Returns | |
|---|---|
DefaultMediaSourceFactory |
This factory, for convenience. |
setLoadOnlySelectedTracks
@CanIgnoreReturnValue
@UnstableApi
public DefaultMediaSourceFactory setLoadOnlySelectedTracks(boolean loadOnlySelectedTracks)
Sets whether to load only the tracks selected by the track selection policy.
| Parameters | |
|---|---|
boolean loadOnlySelectedTracks |
Whether to load only the tracks selected by the track selection policy, instead of loading all tracks. |
| Returns | |
|---|---|
DefaultMediaSourceFactory |
This factory, for convenience. |
setLocalAdInsertionComponents
@CanIgnoreReturnValue
public DefaultMediaSourceFactory setLocalAdInsertionComponents(
AdsLoader.Provider adsLoaderProvider,
AdViewProvider adViewProvider
)
Sets the components required for local ad insertion for media items that have ads configurations
This will override the values set by setAdsLoaderProvider and setAdViewProvider.
| Parameters | |
|---|---|
AdsLoader.Provider adsLoaderProvider |
A provider for |
AdViewProvider adViewProvider |
A provider for information about views for the ad playback UI. |
| Returns | |
|---|---|
DefaultMediaSourceFactory |
This factory, for convenience. |
setServerSideAdInsertionMediaSourceFactory
@CanIgnoreReturnValue
public DefaultMediaSourceFactory setServerSideAdInsertionMediaSourceFactory(
@Nullable MediaSource.Factory serverSideAdInsertionMediaSourceFactory
)
Sets the MediaSource.Factory used to handle MediaItem instances containing a Uri identified as resolving to content with server side ad insertion (SSAI).
SSAI URIs are those with a scheme of SSAI_SCHEME.
| Parameters | |
|---|---|
@Nullable MediaSource.Factory serverSideAdInsertionMediaSourceFactory |
The |
| Returns | |
|---|---|
DefaultMediaSourceFactory |
This factory, for convenience. |
setSubtitleParserFactory
@CanIgnoreReturnValue
@UnstableApi
public DefaultMediaSourceFactory setSubtitleParserFactory(SubtitleParser.Factory subtitleParserFactory)
Sets the SubtitleParser.Factory to be used for parsing subtitles during extraction.
| Parameters | |
|---|---|
SubtitleParser.Factory subtitleParserFactory |
The |
| Returns | |
|---|---|
DefaultMediaSourceFactory |
This factory, for convenience. |