DefaultMediaSourceFactory


public final class DefaultMediaSourceFactory implements MediaSourceFactory


The default MediaSource.Factory implementation.

This implementation delegates calls to createMediaSource to the following factories:

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

This interface is deprecated.

Use AdsLoader.Provider instead.

Public constructors

Creates a new instance.

Creates a new instance.

@UnstableApi
DefaultMediaSourceFactory(
    Context context,
    ExtractorsFactory extractorsFactory
)

Creates a new instance.

@UnstableApi
DefaultMediaSourceFactory(
    DataSource.Factory dataSourceFactory,
    ExtractorsFactory extractorsFactory
)

Creates a new instance.

@UnstableApi
DefaultMediaSourceFactory(
    DataSource.Factory dataSourceFactory,
    ExtractorsFactory extractorsFactory,
    SubtitleParser.Factory subtitleParserFactory
)

Creates a new instance.

Public methods

DefaultMediaSourceFactory

Clear any values set via setLocalAdInsertionComponents.

MediaSource

Creates a new MediaSource with the specified MediaItem.

DefaultMediaSourceFactory
@CanIgnoreReturnValue
@UnstableApi
experimentalParseSubtitlesDuringExtraction(
    boolean parseSubtitlesDuringExtraction
)

This method is deprecated.

This method (and all support for 'legacy' subtitle decoding during rendering) will be removed in a future release.

int[]

Returns the content types supported by media sources created by this factory.

DefaultMediaSourceFactory

This method is deprecated.

Use setLocalAdInsertionComponents instead.

DefaultMediaSourceFactory

This method is deprecated.

Use setLocalAdInsertionComponents instead.

DefaultMediaSourceFactory
@CanIgnoreReturnValue
@UnstableApi
setAlwaysWrapInClippingMediaSource(
    boolean alwaysWrapInClippingMediaSource
)

Sets whether to always wrap created media sources in a ClippingMediaSource, even when the MediaItem has no clipping configuration.

DefaultMediaSourceFactory

Sets the CmcdConfiguration.Factory used to obtain a CmcdConfiguration for a MediaItem.

DefaultMediaSourceFactory

Sets the DataSource.Factory used to create DataSource instances for requesting media data.

MediaSource.Factory

Sets a supplier for an ReleasableExecutor that is used for loading the media.

DefaultMediaSourceFactory

Sets the DrmSessionManagerProvider used to obtain a DrmSessionManager for a MediaItem.

DefaultMediaSourceFactory

Sets whether to delegate end-position clipping to MediaPeriod instances.

DefaultMediaSourceFactory

Sets the ExternalLoader to be called when loading starts in ExternallyLoadedMediaSource when loading images in an external Image Management Framework (for example, Glide).

DefaultMediaSourceFactory

Sets the maximum offset from the live edge for live streams, in milliseconds.

DefaultMediaSourceFactory

Sets the maximum playback speed for live streams.

DefaultMediaSourceFactory

Sets the minimum offset from the live edge for live streams, in milliseconds.

DefaultMediaSourceFactory

Sets the minimum playback speed for live streams.

DefaultMediaSourceFactory

Sets the target live offset for live streams, in milliseconds.

DefaultMediaSourceFactory

Sets an optional LoadErrorHandlingPolicy.

DefaultMediaSourceFactory

Sets whether to load only the video and image tracks selected by the track selection policy.

DefaultMediaSourceFactory
@CanIgnoreReturnValue
setLocalAdInsertionComponents(
    AdsLoader.Provider adsLoaderProvider,
    AdViewProvider adViewProvider
)

Sets the components required for local ad insertion for media items that have ads configurations

DefaultMediaSourceFactory

Sets the MediaSource.Factory used to handle MediaItem instances containing a Uri identified as resolving to content with server side ad insertion (SSAI).

DefaultMediaSourceFactory

Sets the SubtitleParser.Factory to be used for parsing subtitles during extraction.

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 DataSource.Factory to create DataSource instances for requesting media data.

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 ExtractorsFactory used to extract progressive media from its container.

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 DataSource.Factory to create DataSource instances for requesting media data.

ExtractorsFactory extractorsFactory

An ExtractorsFactory used to extract progressive media from its container.

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 DataSource.Factory to create DataSource instances for requesting media data.

ExtractorsFactory extractorsFactory

An ExtractorsFactory used to extract progressive media from its container.

SubtitleParser.Factory subtitleParserFactory

A SubtitleParser.Factory to create SubtitleParser instances used to parse subtitles.

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 media source.

experimentalParseSubtitlesDuringExtraction

@CanIgnoreReturnValue
@UnstableApi
public DefaultMediaSourceFactory experimentalParseSubtitlesDuringExtraction(
    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.

getSupportedTypes

@UnstableApi
@C.ContentType
public int[] getSupportedTypes()

Returns the content types supported by media sources created by this factory.

setAdViewProvider

@CanIgnoreReturnValue
@UnstableApi
public DefaultMediaSourceFactory setAdViewProvider(@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 DefaultMediaSourceFactory setAdsLoaderProvider(@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 AdsLoader instances.

Returns
DefaultMediaSourceFactory

This factory, for convenience.

setAlwaysWrapInClippingMediaSource

@CanIgnoreReturnValue
@UnstableApi
public DefaultMediaSourceFactory setAlwaysWrapInClippingMediaSource(
    boolean alwaysWrapInClippingMediaSource
)

Sets whether to always wrap created media sources in a ClippingMediaSource, even when the MediaItem has no clipping configuration.

By default a ClippingMediaSource is only added when clippingConfiguration is non-trivial. This means an item that starts unclipped has no ClippingMediaSource in its source structure, and a later replaceMediaItem that adds a clipping configuration is silently ignored, because the existing media source reports that it can be updated in place. Enabling this ensures the wrapper is always present, so clipping configuration changes take effect. To apply them without re-preparing the media source, also enable setEnableClippingInMediaPeriod.

This applies to all media sources created by this factory, except for items with SSAI_SCHEME URIs, which are never clipped.

Note:ClippingMediaSource only supports single-period content, so enabling this makes playback of multi-period content fail, even if it isn't clipped.

The default value is false.

Parameters
boolean alwaysWrapInClippingMediaSource

Whether to always wrap created media sources in a ClippingMediaSource.

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 DataSource.Factory.

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 Supplier that provides an externally managed ReleasableExecutor for downloading and extraction.

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 to delegate end-position clipping to MediaPeriod instances.

The default value is determined by FLAG_ENABLE_CLIPPING_IN_MEDIA_PERIOD.

Parameters
boolean enableClippingInMediaPeriod

Whether to delegate end-position clipping to MediaPeriod instances.

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 ExternalLoader to load the media or null to remove a previously set ExternalLoader.

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 TIME_UNSET to use the media-defined default.

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 RATE_UNSET to use the media-defined default.

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 TIME_UNSET to use the media-defined default.

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 RATE_UNSET to use the media-defined default.

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 TIME_UNSET to use the media-defined default.

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 video and image tracks selected by the track selection policy.

Audio, text, and metadata tracks are always loaded regardless of track selection, as they have relatively low bitrate and are more likely to be toggled mid-playback (e.g., changing audio languages or subtitle tracks, or disabling audio during scrubbing mode). Always loading them allows seamlessly switching mid-playback without re-buffering or seeking.

Note that while this saves memory, it may cause additional buffering or latency if unselected video or image tracks are enabled mid-playback, as the player may need to perform additional network requests to fetch the newly selected track data.

The default is true.

Parameters
boolean loadOnlySelectedTracks

Whether to load only the video and image 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 AdsLoader instances.

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 MediaSource.Factory for SSAI content, or null to remove a previously set MediaSource.Factory.

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 SubtitleParser.Factory for parsing subtitles during extraction.

Returns
DefaultMediaSourceFactory

This factory, for convenience.