DefaultMediaSourceFactory


class DefaultMediaSourceFactory : 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(
    dataSourceFactory: DataSource.Factory!,
    extractorsFactory: ExtractorsFactory!
)

Creates a new instance.

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

Creates a new instance.

Public functions

DefaultMediaSourceFactory!

Clear any values set via setLocalAdInsertionComponents.

MediaSource!

Creates a new MediaSource with the specified MediaItem.

DefaultMediaSourceFactory!

This function is deprecated.

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

Array<Int>!

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

DefaultMediaSourceFactory!

This function is deprecated.

Use setLocalAdInsertionComponents instead.

DefaultMediaSourceFactory!

This function is deprecated.

Use setLocalAdInsertionComponents instead.

DefaultMediaSourceFactory!

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(
    adsLoaderProvider: AdsLoader.Provider!,
    adViewProvider: AdViewProvider!
)

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

DefaultMediaSourceFactory!
@CanIgnoreReturnValue
setServerSideAdInsertionMediaSourceFactory(
    serverSideAdInsertionMediaSourceFactory: MediaSource.Factory?
)

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

DefaultMediaSourceFactory(context: Context!)

Creates a new instance.

Parameters
context: Context!

Any context.

DefaultMediaSourceFactory

@UnstableApi
DefaultMediaSourceFactory(dataSourceFactory: DataSource.Factory!)

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
dataSourceFactory: DataSource.Factory!

A DataSource.Factory to create DataSource instances for requesting media data.

DefaultMediaSourceFactory

@UnstableApi
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
DefaultMediaSourceFactory(
    dataSourceFactory: DataSource.Factory!,
    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
dataSourceFactory: DataSource.Factory!

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
DefaultMediaSourceFactory(
    dataSourceFactory: DataSource.Factory!,
    extractorsFactory: ExtractorsFactory!,
    subtitleParserFactory: SubtitleParser.Factory!
)

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
dataSourceFactory: DataSource.Factory!

A DataSource.Factory to create DataSource instances for requesting media data.

extractorsFactory: ExtractorsFactory!

An ExtractorsFactory used to extract progressive media from its container.

subtitleParserFactory: SubtitleParser.Factory!

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

Public functions

clearLocalAdInsertionComponents

@CanIgnoreReturnValue
fun clearLocalAdInsertionComponents(): DefaultMediaSourceFactory!

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
fun createMediaSource(mediaItem: MediaItem!): MediaSource!

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
fun experimentalParseSubtitlesDuringExtraction(
    parseSubtitlesDuringExtraction: Boolean
): DefaultMediaSourceFactory!

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
parseSubtitlesDuringExtraction: Boolean

Whether to parse subtitles during extraction or rendering.

Returns
DefaultMediaSourceFactory!

This factory, for convenience.

getSupportedTypes

@UnstableApi
@C.ContentType
fun getSupportedTypes(): Array<Int>!

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

setAdViewProvider

@CanIgnoreReturnValue
@UnstableApi
fun setAdViewProvider(adViewProvider: AdViewProvider?): DefaultMediaSourceFactory!

Sets the AdViewProvider that provides information about views for the ad playback UI.

This will override or clear the AdViewProvider set by setLocalAdInsertionComponents.

Parameters
adViewProvider: AdViewProvider?

A provider for information about views for the ad playback UI.

Returns
DefaultMediaSourceFactory!

This factory, for convenience.

setAdsLoaderProvider

@CanIgnoreReturnValue
@UnstableApi
fun setAdsLoaderProvider(adsLoaderProvider: AdsLoader.Provider?): DefaultMediaSourceFactory!

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
adsLoaderProvider: AdsLoader.Provider?

A provider for AdsLoader instances.

Returns
DefaultMediaSourceFactory!

This factory, for convenience.

setAlwaysWrapInClippingMediaSource

@CanIgnoreReturnValue
@UnstableApi
fun setAlwaysWrapInClippingMediaSource(
    alwaysWrapInClippingMediaSource: Boolean
): DefaultMediaSourceFactory!

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
alwaysWrapInClippingMediaSource: Boolean

Whether to always wrap created media sources in a ClippingMediaSource.

Returns
DefaultMediaSourceFactory!

This factory, for convenience.

setCmcdConfigurationFactory

@CanIgnoreReturnValue
@UnstableApi
fun setCmcdConfigurationFactory(
    cmcdConfigurationFactory: CmcdConfiguration.Factory!
): DefaultMediaSourceFactory!

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

Returns
DefaultMediaSourceFactory!

This factory, for convenience.

setDataSourceFactory

@CanIgnoreReturnValue
fun setDataSourceFactory(dataSourceFactory: DataSource.Factory!): DefaultMediaSourceFactory!

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

Parameters
dataSourceFactory: DataSource.Factory!

The DataSource.Factory.

Returns
DefaultMediaSourceFactory!

This factory, for convenience.

setDownloadExecutor

@UnstableApi
@CanIgnoreReturnValue
fun setDownloadExecutor(downloadExecutor: Supplier<ReleasableExecutor!>!): MediaSource.Factory!

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

Parameters
downloadExecutor: Supplier<ReleasableExecutor!>!

A Supplier that provides an externally managed ReleasableExecutor for downloading and extraction.

Returns
MediaSource.Factory!

This factory, for convenience.

setDrmSessionManagerProvider

@CanIgnoreReturnValue
@UnstableApi
fun setDrmSessionManagerProvider(
    drmSessionManagerProvider: DrmSessionManagerProvider!
): DefaultMediaSourceFactory!

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

Returns
DefaultMediaSourceFactory!

This factory, for convenience.

setEnableClippingInMediaPeriod

@ExperimentalApi
@CanIgnoreReturnValue
fun setEnableClippingInMediaPeriod(enableClippingInMediaPeriod: Boolean): DefaultMediaSourceFactory!

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

The default value is determined by FLAG_ENABLE_CLIPPING_IN_MEDIA_PERIOD.

Parameters
enableClippingInMediaPeriod: Boolean

Whether to delegate end-position clipping to MediaPeriod instances.

Returns
DefaultMediaSourceFactory!

This factory, for convenience.

setExternalImageLoader

@CanIgnoreReturnValue
@UnstableApi
fun setExternalImageLoader(externalImageLoader: ExternalLoader?): DefaultMediaSourceFactory!

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
externalImageLoader: ExternalLoader?

The ExternalLoader to load the media or null to remove a previously set ExternalLoader.

Returns
DefaultMediaSourceFactory!

This factory, for convenience.

setLiveMaxOffsetMs

@CanIgnoreReturnValue
@UnstableApi
fun setLiveMaxOffsetMs(liveMaxOffsetMs: Long): DefaultMediaSourceFactory!

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

Parameters
liveMaxOffsetMs: Long

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
fun setLiveMaxSpeed(maxSpeed: Float): DefaultMediaSourceFactory!

Sets the maximum playback speed for live streams.

Parameters
maxSpeed: Float

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
fun setLiveMinOffsetMs(liveMinOffsetMs: Long): DefaultMediaSourceFactory!

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

Parameters
liveMinOffsetMs: Long

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
fun setLiveMinSpeed(minSpeed: Float): DefaultMediaSourceFactory!

Sets the minimum playback speed for live streams.

Parameters
minSpeed: Float

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
fun setLiveTargetOffsetMs(liveTargetOffsetMs: Long): DefaultMediaSourceFactory!

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

Parameters
liveTargetOffsetMs: Long

The target live offset, in milliseconds, or TIME_UNSET to use the media-defined default.

Returns
DefaultMediaSourceFactory!

This factory, for convenience.

setLoadErrorHandlingPolicy

@CanIgnoreReturnValue
@UnstableApi
fun setLoadErrorHandlingPolicy(
    loadErrorHandlingPolicy: LoadErrorHandlingPolicy!
): DefaultMediaSourceFactory!

Sets an optional LoadErrorHandlingPolicy.

Returns
DefaultMediaSourceFactory!

This factory, for convenience.

setLoadOnlySelectedTracks

@CanIgnoreReturnValue
@UnstableApi
fun setLoadOnlySelectedTracks(loadOnlySelectedTracks: Boolean): DefaultMediaSourceFactory!

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
loadOnlySelectedTracks: Boolean

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
fun setLocalAdInsertionComponents(
    adsLoaderProvider: AdsLoader.Provider!,
    adViewProvider: AdViewProvider!
): DefaultMediaSourceFactory!

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
adsLoaderProvider: AdsLoader.Provider!

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
fun setServerSideAdInsertionMediaSourceFactory(
    serverSideAdInsertionMediaSourceFactory: MediaSource.Factory?
): DefaultMediaSourceFactory!

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
serverSideAdInsertionMediaSourceFactory: MediaSource.Factory?

The MediaSource.Factory for SSAI content, or null to remove a previously set MediaSource.Factory.

Returns
DefaultMediaSourceFactory!

This factory, for convenience.

setSubtitleParserFactory

@CanIgnoreReturnValue
@UnstableApi
fun setSubtitleParserFactory(subtitleParserFactory: SubtitleParser.Factory!): DefaultMediaSourceFactory!

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

Parameters
subtitleParserFactory: SubtitleParser.Factory!

The SubtitleParser.Factory for parsing subtitles during extraction.

Returns
DefaultMediaSourceFactory!

This factory, for convenience.