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.Factoryimplementation.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.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 interfaceDefaultMediaSourceFactory.AdsLoaderProviderDeprecated.UseAdsLoader.Providerinstead.
-
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 MediaSourcecreateMediaSource(MediaItem mediaItem)Creates a newMediaSourcewith the specifiedMediaItem.DefaultMediaSourceFactoryexperimentalUseProgressiveMediaSourceForSubtitles(boolean useProgressiveMediaSourceForSubtitles)Sets whether aProgressiveMediaSourceorSingleSampleMediaSourceis constructed to handleMediaItem.LocalConfiguration.subtitleConfigurations.int[]getSupportedTypes()Returns thecontent typessupported by media sources created by this factory.DefaultMediaSourceFactorysetAdsLoaderProvider(AdsLoader.Provider adsLoaderProvider)Sets theAdsLoader.Providerthat providesAdsLoaderinstances for media items that haveads configurations.DefaultMediaSourceFactorysetAdViewProvider(AdViewProvider adViewProvider)Sets theAdViewProviderthat provides information about views for the ad playback UI.DefaultMediaSourceFactorysetDrmSessionManagerProvider(DrmSessionManagerProvider drmSessionManagerProvider)DefaultMediaSourceFactorysetLiveMaxOffsetMs(long liveMaxOffsetMs)Sets the maximum offset from the live edge for live streams, in milliseconds.DefaultMediaSourceFactorysetLiveMaxSpeed(float maxSpeed)Sets the maximum playback speed for live streams.DefaultMediaSourceFactorysetLiveMinOffsetMs(long liveMinOffsetMs)Sets the minimum offset from the live edge for live streams, in milliseconds.DefaultMediaSourceFactorysetLiveMinSpeed(float minSpeed)Sets the minimum playback speed for live streams.DefaultMediaSourceFactorysetLiveTargetOffsetMs(long liveTargetOffsetMs)Sets the target live offset for live streams, in milliseconds.DefaultMediaSourceFactorysetLoadErrorHandlingPolicy(LoadErrorHandlingPolicy loadErrorHandlingPolicy)Sets an optionalLoadErrorHandlingPolicy.DefaultMediaSourceFactorysetServerSideAdInsertionMediaSourceFactory(MediaSource.Factory serverSideAdInsertionMediaSourceFactory)Sets theMediaSource.Factoryused to handleMediaIteminstances containing aUriidentified 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- 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 AdsLoader.Provider adsLoaderProvider)
Sets theAdsLoader.Providerthat 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.
-
setServerSideAdInsertionMediaSourceFactory
public DefaultMediaSourceFactory setServerSideAdInsertionMediaSourceFactory(@Nullable MediaSource.Factory serverSideAdInsertionMediaSourceFactory)
Sets theMediaSource.Factoryused to handleMediaIteminstances containing aUriidentified as resolving to content with server side ad insertion (SSAI).SSAI URIs are those with a
schemeofC.SSAI_SCHEME.- Parameters:
serverSideAdInsertionMediaSourceFactory- TheMediaSource.Factoryfor SSAI content, ornullto 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_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.
-
setDrmSessionManagerProvider
public DefaultMediaSourceFactory setDrmSessionManagerProvider(@Nullable DrmSessionManagerProvider drmSessionManagerProvider)
Description copied from interface:MediaSource.FactorySets theDrmSessionManagerProviderused to obtain aDrmSessionManagerfor aMediaItem.If not set,
DefaultDrmSessionManagerProvideris used.- Specified by:
setDrmSessionManagerProviderin interfaceMediaSource.Factory- Returns:
- This factory, for convenience.
-
setLoadErrorHandlingPolicy
public DefaultMediaSourceFactory setLoadErrorHandlingPolicy(@Nullable LoadErrorHandlingPolicy loadErrorHandlingPolicy)
Description copied from interface:MediaSource.FactorySets an optionalLoadErrorHandlingPolicy.- Specified by:
setLoadErrorHandlingPolicyin interfaceMediaSource.Factory- Parameters:
loadErrorHandlingPolicy- ALoadErrorHandlingPolicy, ornullto use theDefaultLoadErrorHandlingPolicy.- Returns:
- This factory, for convenience.
-
getSupportedTypes
public int[] getSupportedTypes()
Description copied from interface:MediaSource.FactoryReturns thecontent typessupported by media sources created by this factory.- Specified by:
getSupportedTypesin interfaceMediaSource.Factory
-
createMediaSource
public MediaSource createMediaSource(MediaItem mediaItem)
Description copied from interface:MediaSource.FactoryCreates a newMediaSourcewith the specifiedMediaItem.- Specified by:
createMediaSourcein interfaceMediaSource.Factory- Parameters:
mediaItem- The media item to play.- Returns:
- The new
media source.
-
-