Class DefaultMediaSourceFactory
- java.lang.Object
-
- com.google.android.exoplayer2.source.DefaultMediaSourceFactory
-
- All Implemented Interfaces:
MediaSource.Factory
,MediaSourceFactory
public final class DefaultMediaSourceFactory extends Object implements MediaSourceFactory
The defaultMediaSource.Factory
implementation.This implementation delegates calls to
createMediaSource(MediaItem)
to the following factories:DashMediaSource.Factory
if the item'suri
ends in '.mpd' or if itsmimeType field
is explicitly set toMimeTypes.APPLICATION_MPD
(Requires the exoplayer-dash module to be added to the app).HlsMediaSource.Factory
if the item'suri
ends in '.m3u8' or if itsmimeType field
is explicitly set toMimeTypes.APPLICATION_M3U8
(Requires the exoplayer-hls module to be added to the app).SsMediaSource.Factory
if the item'suri
ends in '.ism', '.ism/Manifest' or if itsmimeType field
is explicitly set toMimeTypes.APPLICATION_SS
(Requires the exoplayer-smoothstreaming module to be added to the app).ProgressiveMediaSource.Factory
serves as a fallback if the item'suri
doesn't match one of the above. It tries to infer the required extractor by using theDefaultExtractorsFactory
or theExtractorsFactory
provided in the constructor. AnUnrecognizedInputFormatException
is 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(com.google.android.exoplayer2.source.ads.AdsLoader.Provider)
andsetAdViewProvider(com.google.android.exoplayer2.ui.AdViewProvider)
need to be called to configure the factory with the required providers.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
DefaultMediaSourceFactory.AdsLoaderProvider
Deprecated.UseAdsLoader.Provider
instead.
-
Field Summary
-
Fields inherited from interface com.google.android.exoplayer2.source.MediaSourceFactory
UNSUPPORTED
-
-
Constructor Summary
Constructors Constructor Description DefaultMediaSourceFactory(Context context)
Creates a new instance.DefaultMediaSourceFactory(Context context, ExtractorsFactory extractorsFactory)
Creates a new instance.DefaultMediaSourceFactory(DataSource.Factory dataSourceFactory)
Creates a new instance.DefaultMediaSourceFactory(DataSource.Factory dataSourceFactory, ExtractorsFactory extractorsFactory)
Creates a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description MediaSource
createMediaSource(MediaItem mediaItem)
Creates a newMediaSource
with the specifiedMediaItem
.DefaultMediaSourceFactory
experimentalUseProgressiveMediaSourceForSubtitles(boolean useProgressiveMediaSourceForSubtitles)
Sets whether aProgressiveMediaSource
orSingleSampleMediaSource
is constructed to handleMediaItem.LocalConfiguration.subtitleConfigurations
.int[]
getSupportedTypes()
Returns thecontent types
supported by media sources created by this factory.DefaultMediaSourceFactory
setAdsLoaderProvider(AdsLoader.Provider adsLoaderProvider)
Sets theAdsLoader.Provider
that providesAdsLoader
instances for media items that haveads configurations
.DefaultMediaSourceFactory
setAdViewProvider(AdViewProvider adViewProvider)
Sets theAdViewProvider
that provides information about views for the ad playback UI.DefaultMediaSourceFactory
setDrmSessionManagerProvider(DrmSessionManagerProvider drmSessionManagerProvider)
DefaultMediaSourceFactory
setLiveMaxOffsetMs(long liveMaxOffsetMs)
Sets the maximum offset from the live edge for live streams, in milliseconds.DefaultMediaSourceFactory
setLiveMaxSpeed(float maxSpeed)
Sets the maximum playback speed for live streams.DefaultMediaSourceFactory
setLiveMinOffsetMs(long liveMinOffsetMs)
Sets the minimum offset from the live edge for live streams, in milliseconds.DefaultMediaSourceFactory
setLiveMinSpeed(float minSpeed)
Sets the minimum playback speed for live streams.DefaultMediaSourceFactory
setLiveTargetOffsetMs(long liveTargetOffsetMs)
Sets the target live offset for live streams, in milliseconds.DefaultMediaSourceFactory
setLoadErrorHandlingPolicy(LoadErrorHandlingPolicy loadErrorHandlingPolicy)
Sets an optionalLoadErrorHandlingPolicy
.DefaultMediaSourceFactory
setServerSideAdInsertionMediaSourceFactory(MediaSource.Factory serverSideAdInsertionMediaSourceFactory)
Sets theMediaSource.Factory
used to handleMediaItem
instances containing aUri
identified as resolving to content with server side ad insertion (SSAI).
-
-
-
Constructor Detail
-
DefaultMediaSourceFactory
public DefaultMediaSourceFactory(Context context)
Creates a new instance.- Parameters:
context
- Any context.
-
DefaultMediaSourceFactory
public DefaultMediaSourceFactory(Context context, ExtractorsFactory extractorsFactory)
Creates a new instance.- Parameters:
context
- Any context.extractorsFactory
- AnExtractorsFactory
used to extract progressive media from its container.
-
DefaultMediaSourceFactory
public DefaultMediaSourceFactory(DataSource.Factory dataSourceFactory)
Creates a new instance.- Parameters:
dataSourceFactory
- ADataSource.Factory
to createDataSource
instances for requesting media data.
-
DefaultMediaSourceFactory
public DefaultMediaSourceFactory(DataSource.Factory dataSourceFactory, ExtractorsFactory extractorsFactory)
Creates a new instance.- Parameters:
dataSourceFactory
- ADataSource.Factory
to createDataSource
instances for requesting media data.extractorsFactory
- AnExtractorsFactory
used to extract progressive media from its container.
-
-
Method Detail
-
experimentalUseProgressiveMediaSourceForSubtitles
public DefaultMediaSourceFactory experimentalUseProgressiveMediaSourceForSubtitles(boolean useProgressiveMediaSourceForSubtitles)
Sets whether aProgressiveMediaSource
orSingleSampleMediaSource
is constructed to handleMediaItem.LocalConfiguration.subtitleConfigurations
. Defaults to false (i.e.SingleSampleMediaSource
.This method is experimental, and will be renamed or removed in a future release.
- Parameters:
useProgressiveMediaSourceForSubtitles
- Indicates thatProgressiveMediaSource
should be used for subtitles instead ofSingleSampleMediaSource
.- Returns:
- This factory, for convenience.
-
setAdsLoaderProvider
public DefaultMediaSourceFactory setAdsLoaderProvider(@Nullable AdsLoader.Provider adsLoaderProvider)
Sets theAdsLoader.Provider
that providesAdsLoader
instances for media items that haveads configurations
.- Parameters:
adsLoaderProvider
- A provider forAdsLoader
instances.- Returns:
- This factory, for convenience.
-
setAdViewProvider
public DefaultMediaSourceFactory setAdViewProvider(@Nullable AdViewProvider adViewProvider)
Sets theAdViewProvider
that provides information about views for the ad playback UI.- Parameters:
adViewProvider
- A provider forAdsLoader
instances.- Returns:
- This factory, for convenience.
-
setServerSideAdInsertionMediaSourceFactory
public DefaultMediaSourceFactory setServerSideAdInsertionMediaSourceFactory(@Nullable MediaSource.Factory serverSideAdInsertionMediaSourceFactory)
Sets theMediaSource.Factory
used to handleMediaItem
instances containing aUri
identified as resolving to content with server side ad insertion (SSAI).SSAI URIs are those with a
scheme
ofC.SSAI_SCHEME
.- Parameters:
serverSideAdInsertionMediaSourceFactory
- TheMediaSource.Factory
for SSAI content, ornull
to remove a previously setMediaSource.Factory
.- Returns:
- This factory, for convenience.
-
setLiveTargetOffsetMs
public DefaultMediaSourceFactory setLiveTargetOffsetMs(long liveTargetOffsetMs)
Sets the target live offset for live streams, in milliseconds.- Parameters:
liveTargetOffsetMs
- The target live offset, in milliseconds, orC.TIME_UNSET
to use the media-defined default.- Returns:
- This factory, for convenience.
-
setLiveMinOffsetMs
public DefaultMediaSourceFactory setLiveMinOffsetMs(long liveMinOffsetMs)
Sets the minimum offset from the live edge for live streams, in milliseconds.- Parameters:
liveMinOffsetMs
- The minimum allowed live offset, in milliseconds, orC.TIME_UNSET
to use the media-defined default.- Returns:
- This factory, for convenience.
-
setLiveMaxOffsetMs
public DefaultMediaSourceFactory setLiveMaxOffsetMs(long liveMaxOffsetMs)
Sets the maximum offset from the live edge for live streams, in milliseconds.- Parameters:
liveMaxOffsetMs
- The maximum allowed live offset, in milliseconds, orC.TIME_UNSET
to use the media-defined default.- Returns:
- This factory, for convenience.
-
setLiveMinSpeed
public DefaultMediaSourceFactory setLiveMinSpeed(float minSpeed)
Sets the minimum playback speed for live streams.- Parameters:
minSpeed
- The minimum factor by which playback can be sped up for live streams, orC.RATE_UNSET
to use the media-defined default.- Returns:
- This factory, for convenience.
-
setLiveMaxSpeed
public DefaultMediaSourceFactory setLiveMaxSpeed(float maxSpeed)
Sets the maximum playback speed for live streams.- Parameters:
maxSpeed
- The maximum factor by which playback can be sped up for live streams, orC.RATE_UNSET
to use the media-defined default.- Returns:
- This factory, for convenience.
-
setDrmSessionManagerProvider
public DefaultMediaSourceFactory setDrmSessionManagerProvider(@Nullable DrmSessionManagerProvider drmSessionManagerProvider)
Description copied from interface:MediaSource.Factory
Sets theDrmSessionManagerProvider
used to obtain aDrmSessionManager
for aMediaItem
.If not set,
DefaultDrmSessionManagerProvider
is used.- Specified by:
setDrmSessionManagerProvider
in interfaceMediaSource.Factory
- Returns:
- This factory, for convenience.
-
setLoadErrorHandlingPolicy
public DefaultMediaSourceFactory setLoadErrorHandlingPolicy(@Nullable LoadErrorHandlingPolicy loadErrorHandlingPolicy)
Description copied from interface:MediaSource.Factory
Sets an optionalLoadErrorHandlingPolicy
.- Specified by:
setLoadErrorHandlingPolicy
in interfaceMediaSource.Factory
- Parameters:
loadErrorHandlingPolicy
- ALoadErrorHandlingPolicy
, ornull
to use theDefaultLoadErrorHandlingPolicy
.- Returns:
- This factory, for convenience.
-
getSupportedTypes
public int[] getSupportedTypes()
Description copied from interface:MediaSource.Factory
Returns thecontent types
supported by media sources created by this factory.- Specified by:
getSupportedTypes
in interfaceMediaSource.Factory
-
createMediaSource
public MediaSource createMediaSource(MediaItem mediaItem)
Description copied from interface:MediaSource.Factory
Creates a newMediaSource
with the specifiedMediaItem
.- Specified by:
createMediaSource
in interfaceMediaSource.Factory
- Parameters:
mediaItem
- The media item to play.- Returns:
- The new
media source
.
-
-