Class DefaultMediaSourceFactory
- java.lang.Object
-
- com.google.android.exoplayer2.source.DefaultMediaSourceFactory
-
- All Implemented Interfaces:
MediaSourceFactory
public final class DefaultMediaSourceFactory extends Object implements MediaSourceFactory
The defaultMediaSourceFactoryimplementation.This implementation delegates calls to
createMediaSource(MediaItem)to the following factories:DashMediaSource.Factoryif the item'suriends in '.mpd' or if itsmimeType fieldis explicitly set toMimeTypes.APPLICATION_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 toMimeTypes.APPLICATION_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 toMimeTypes.APPLICATION_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(com.google.android.exoplayer2.source.DefaultMediaSourceFactory.AdsLoaderProvider)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 interfaceDefaultMediaSourceFactory.AdsLoaderProviderProvidesAdsLoaderinstances for media items that havead tag URIs.
-
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
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.google.android.exoplayer2.source.MediaSourceFactory
createMediaSource
-
-
-
-
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- AnExtractorsFactoryused to extract progressive media from its container.
-
DefaultMediaSourceFactory
public DefaultMediaSourceFactory(DataSource.Factory dataSourceFactory)
Creates a new instance.- Parameters:
dataSourceFactory- ADataSource.Factoryto createDataSourceinstances for requesting media data.
-
DefaultMediaSourceFactory
public DefaultMediaSourceFactory(DataSource.Factory dataSourceFactory, ExtractorsFactory extractorsFactory)
Creates a new instance.- Parameters:
dataSourceFactory- ADataSource.Factoryto createDataSourceinstances for requesting media data.extractorsFactory- AnExtractorsFactoryused to extract progressive media from its container.
-
-
Method Detail
-
experimentalUseProgressiveMediaSourceForSubtitles
public DefaultMediaSourceFactory experimentalUseProgressiveMediaSourceForSubtitles(boolean useProgressiveMediaSourceForSubtitles)
Sets whether aProgressiveMediaSourceorSingleSampleMediaSourceis 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 thatProgressiveMediaSourceshould be used for subtitles instead ofSingleSampleMediaSource.- Returns:
- This factory, for convenience.
-
setAdsLoaderProvider
public DefaultMediaSourceFactory setAdsLoaderProvider(@Nullable DefaultMediaSourceFactory.AdsLoaderProvider adsLoaderProvider)
Sets theDefaultMediaSourceFactory.AdsLoaderProviderthat providesAdsLoaderinstances for media items that haveads configurations.- Parameters:
adsLoaderProvider- A provider forAdsLoaderinstances.- Returns:
- This factory, for convenience.
-
setAdViewProvider
public DefaultMediaSourceFactory setAdViewProvider(@Nullable AdViewProvider adViewProvider)
Sets theAdViewProviderthat provides information about views for the ad playback UI.- Parameters:
adViewProvider- A provider forAdsLoaderinstances.- 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_UNSETto 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_UNSETto 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_UNSETto 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_UNSETto 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_UNSETto use the media-defined default.- Returns:
- This factory, for convenience.
-
setDrmHttpDataSourceFactory
@Deprecated public DefaultMediaSourceFactory setDrmHttpDataSourceFactory(@Nullable HttpDataSource.Factory drmHttpDataSourceFactory)
Deprecated.Description copied from interface:MediaSourceFactorySets theHttpDataSource.Factoryto be used for creatingHttpMediaDrmCallbacksto execute key and provisioning requests over HTTP.Calls to this method are ignored if either a
DrmSessionManager providerorconcrete DrmSessionManagerare provided.- Specified by:
setDrmHttpDataSourceFactoryin interfaceMediaSourceFactory- Parameters:
drmHttpDataSourceFactory- The HTTP data source factory, ornullto useDefaultHttpDataSource.Factory.- Returns:
- This factory, for convenience.
-
setDrmUserAgent
@Deprecated public DefaultMediaSourceFactory setDrmUserAgent(@Nullable String userAgent)
Deprecated.Description copied from interface:MediaSourceFactorySets the optional user agent to be used for DRM requests.Calls to this method are ignored if any of the following are provided:
- Specified by:
setDrmUserAgentin interfaceMediaSourceFactory- Parameters:
userAgent- The user agent to be used for DRM requests, ornullto use the default.- Returns:
- This factory, for convenience.
-
setDrmSessionManager
@Deprecated public DefaultMediaSourceFactory setDrmSessionManager(@Nullable DrmSessionManager drmSessionManager)
Deprecated.Description copied from interface:MediaSourceFactorySets theDrmSessionManagerto use for all media items regardless of theirMediaItem.DrmConfiguration.Calling this with a non-null
drmSessionManageris equivalent to callingsetDrmSessionManagerProvider(unusedMediaItem -> drmSessionManager).- Specified by:
setDrmSessionManagerin interfaceMediaSourceFactory- Parameters:
drmSessionManager- TheDrmSessionManager, ornullto use theDefaultDrmSessionManager.- Returns:
- This factory, for convenience.
-
setDrmSessionManagerProvider
public DefaultMediaSourceFactory setDrmSessionManagerProvider(@Nullable DrmSessionManagerProvider drmSessionManagerProvider)
Description copied from interface:MediaSourceFactorySets theDrmSessionManagerProviderused to obtain aDrmSessionManagerfor aMediaItem.If not set,
DefaultDrmSessionManagerProvideris used.If set, calls to the following (deprecated) methods are ignored:
- Specified by:
setDrmSessionManagerProviderin interfaceMediaSourceFactory- Returns:
- This factory, for convenience.
-
setLoadErrorHandlingPolicy
public DefaultMediaSourceFactory setLoadErrorHandlingPolicy(@Nullable LoadErrorHandlingPolicy loadErrorHandlingPolicy)
Description copied from interface:MediaSourceFactorySets an optionalLoadErrorHandlingPolicy.- Specified by:
setLoadErrorHandlingPolicyin interfaceMediaSourceFactory- Parameters:
loadErrorHandlingPolicy- ALoadErrorHandlingPolicy, ornullto use theDefaultLoadErrorHandlingPolicy.- Returns:
- This factory, for convenience.
-
setStreamKeys
@Deprecated public DefaultMediaSourceFactory setStreamKeys(@Nullable List<StreamKey> streamKeys)
Deprecated.UseMediaItem.Builder.setStreamKeys(List)andcreateMediaSource(MediaItem)instead.- Specified by:
setStreamKeysin interfaceMediaSourceFactory
-
getSupportedTypes
public int[] getSupportedTypes()
Description copied from interface:MediaSourceFactoryReturns thecontent typessupported by media sources created by this factory.- Specified by:
getSupportedTypesin interfaceMediaSourceFactory
-
createMediaSource
public MediaSource createMediaSource(MediaItem mediaItem)
Description copied from interface:MediaSourceFactoryCreates a newMediaSourcewith the specifiedMediaItem.- Specified by:
createMediaSourcein interfaceMediaSourceFactory- Parameters:
mediaItem- The media item to play.- Returns:
- The new
media source.
-
-