# MediaSource.Factory

Artifact: [androidx.media3:media3-exoplayer](https://developer.android.com/jetpack/androidx/releases/media3) [View Source](https://cs.android.com/search?q=file:androidx/media3/exoplayer/source/MediaSource.java+class:androidx.media3.exoplayer.source.MediaSource.Factory)

*** ** * ** ***


```
public interface MediaSource.Factory
```

<br />

Known direct subclasses [ExternallyLoadedMediaSource.Factory](https://developer.android.com/reference/androidx/media3/exoplayer/source/ExternallyLoadedMediaSource.Factory), [ForwardingMediaSourceFactory](https://developer.android.com/reference/androidx/media3/exoplayer/source/ForwardingMediaSourceFactory), [HlsInterstitialsAdsLoader.AdsMediaSourceFactory](https://developer.android.com/reference/androidx/media3/exoplayer/hls/HlsInterstitialsAdsLoader.AdsMediaSourceFactory), [ImaServerSideAdInsertionMediaSource.Factory](https://developer.android.com/reference/androidx/media3/exoplayer/ima/ImaServerSideAdInsertionMediaSource.Factory), [MediaSourceFactory](https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSourceFactory), [PreloadMediaSource.Factory](https://developer.android.com/reference/androidx/media3/exoplayer/source/preload/PreloadMediaSource.Factory)

|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/ExternallyLoadedMediaSource.Factory` | Factory for `https://developer.android.com/reference/androidx/media3/exoplayer/source/ExternallyLoadedMediaSource`. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/ForwardingMediaSourceFactory` | A forwarding `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.Factory` that forwards all methods to the underlying implementation. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/hls/HlsInterstitialsAdsLoader.AdsMediaSourceFactory` | A `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.Factory` to create a media source to play HLS streams with interstitials. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/ima/ImaServerSideAdInsertionMediaSource.Factory` | Factory for creating `https://developer.android.com/reference/androidx/media3/exoplayer/ima/ImaServerSideAdInsertionMediaSource`. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSourceFactory` | **This interface is deprecated.** Use `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.Factory`. <br /> |
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/preload/PreloadMediaSource.Factory` | Factory for `https://developer.android.com/reference/androidx/media3/exoplayer/source/preload/PreloadMediaSource`. |

Known indirect subclasses [DashMediaSource.Factory](https://developer.android.com/reference/androidx/media3/exoplayer/dash/DashMediaSource.Factory), [DefaultMediaSourceFactory](https://developer.android.com/reference/androidx/media3/exoplayer/source/DefaultMediaSourceFactory), [FakeMediaSourceFactory](https://developer.android.com/reference/androidx/media3/test/utils/FakeMediaSourceFactory), [HlsMediaSource.Factory](https://developer.android.com/reference/androidx/media3/exoplayer/hls/HlsMediaSource.Factory), [ProgressiveMediaSource.Factory](https://developer.android.com/reference/androidx/media3/exoplayer/source/ProgressiveMediaSource.Factory), [RtspMediaSource.Factory](https://developer.android.com/reference/androidx/media3/exoplayer/rtsp/RtspMediaSource.Factory), [SsMediaSource.Factory](https://developer.android.com/reference/androidx/media3/exoplayer/smoothstreaming/SsMediaSource.Factory)

|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/dash/DashMediaSource.Factory` | Factory for `https://developer.android.com/reference/androidx/media3/exoplayer/dash/DashMediaSource`s. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/DefaultMediaSourceFactory` | The default `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.Factory` implementation. |
| `https://developer.android.com/reference/androidx/media3/test/utils/FakeMediaSourceFactory` | Fake `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSourceFactory` that creates a `https://developer.android.com/reference/androidx/media3/test/utils/FakeMediaSource`. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/hls/HlsMediaSource.Factory` | Factory for `https://developer.android.com/reference/androidx/media3/exoplayer/hls/HlsMediaSource`s. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/ProgressiveMediaSource.Factory` | Factory for `https://developer.android.com/reference/androidx/media3/exoplayer/source/ProgressiveMediaSource`s. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/rtsp/RtspMediaSource.Factory` | Factory for `https://developer.android.com/reference/androidx/media3/exoplayer/rtsp/RtspMediaSource` |
| `https://developer.android.com/reference/androidx/media3/exoplayer/smoothstreaming/SsMediaSource.Factory` | Factory for `https://developer.android.com/reference/androidx/media3/exoplayer/smoothstreaming/SsMediaSource`. |

*** ** * ** ***

Factory for creating `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource` from `https://developer.android.com/reference/androidx/media3/common/MediaItem`.

## Summary

| ### Constants |
|---|---|
| `default static final https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.Factory` | `@https://developer.android.com/reference/androidx/media3/common/util/UnstableApi https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.Factory#UNSUPPORTED()` An instance that throws `https://developer.android.com/reference/java/lang/UnsupportedOperationException.html` from `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.Factory#createMediaSource(androidx.media3.common.MediaItem)` and `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.Factory#getSupportedTypes()`. |

| ### Public methods |
|---|---|
| `abstract https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource` | `@https://developer.android.com/reference/androidx/media3/common/util/UnstableApi https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.Factory#createMediaSource(androidx.media3.common.MediaItem)(https://developer.android.com/reference/androidx/media3/common/MediaItem mediaItem)` Creates a new `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource` with the specified `https://developer.android.com/reference/androidx/media3/common/MediaItem`. |
| `default https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.Factory` | `@https://developer.android.com/reference/androidx/media3/common/util/UnstableApi @https://developer.android.com/reference/androidx/media3/common/util/ExperimentalApi [experimentalParseSubtitlesDuringExtraction](https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.Factory#experimentalParseSubtitlesDuringExtraction(boolean))( boolean parseSubtitlesDuringExtraction )` **This method is deprecated.** This method (and all support for 'legacy' subtitle decoding during rendering) will be removed in a future release. <br /> |
| `abstract int[]` | `@https://developer.android.com/reference/androidx/media3/common/util/UnstableApi @https://developer.android.com/reference/androidx/media3/common/C.ContentType https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.Factory#getSupportedTypes()()` Returns the `https://developer.android.com/reference/androidx/media3/common/C.ContentType` supported by media sources created by this factory. |
| `default https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.Factory` | `@https://developer.android.com/reference/androidx/media3/common/util/UnstableApi https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.Factory#setCmcdConfigurationFactory(androidx.media3.exoplayer.upstream.CmcdConfiguration.Factory)( https://developer.android.com/reference/androidx/media3/exoplayer/upstream/CmcdConfiguration.Factory cmcdConfigurationFactory )` Sets the `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/CmcdConfiguration.Factory` used to obtain a `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/CmcdConfiguration` for a `https://developer.android.com/reference/androidx/media3/common/MediaItem`. |
| `default https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.Factory` | `@https://developer.android.com/reference/androidx/media3/common/util/UnstableApi @https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.Factory#setDownloadExecutor(com.google.common.base.Supplier<androidx.media3.exoplayer.util.ReleasableExecutor>)(https://guava.dev/releases/snapshot-android/api/docs/com/google/common/base/Supplier.html<https://developer.android.com/reference/androidx/media3/exoplayer/util/ReleasableExecutor> downloadExecutor)` Sets a supplier for an `https://developer.android.com/reference/androidx/media3/exoplayer/util/ReleasableExecutor` that is used for loading the media. |
| `abstract https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.Factory` | `@https://developer.android.com/reference/androidx/media3/common/util/UnstableApi https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.Factory#setDrmSessionManagerProvider(androidx.media3.exoplayer.drm.DrmSessionManagerProvider)( https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSessionManagerProvider drmSessionManagerProvider )` Sets the `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSessionManagerProvider` used to obtain a `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSessionManager` for a `https://developer.android.com/reference/androidx/media3/common/MediaItem`. |
| `abstract https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.Factory` | `@https://developer.android.com/reference/androidx/media3/common/util/UnstableApi https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.Factory#setLoadErrorHandlingPolicy(androidx.media3.exoplayer.upstream.LoadErrorHandlingPolicy)( https://developer.android.com/reference/androidx/media3/exoplayer/upstream/LoadErrorHandlingPolicy loadErrorHandlingPolicy )` Sets an optional `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/LoadErrorHandlingPolicy`. |
| `default https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.Factory` | `@https://developer.android.com/reference/androidx/media3/common/util/UnstableApi https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.Factory#setSubtitleParserFactory(androidx.media3.extractor.text.SubtitleParser.Factory)(https://developer.android.com/reference/androidx/media3/extractor/text/SubtitleParser.Factory subtitleParserFactory)` Sets the `https://developer.android.com/reference/androidx/media3/extractor/text/SubtitleParser.Factory` to be used for parsing subtitles during extraction. |

## Constants

### UNSUPPORTED

```
@UnstableApi
default static final MediaSource.Factory UNSUPPORTED
```

An instance that throws `https://developer.android.com/reference/java/lang/UnsupportedOperationException.html` from `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.Factory#createMediaSource(androidx.media3.common.MediaItem)` and `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.Factory#getSupportedTypes()`.

## Public methods

### createMediaSource

```
@UnstableApi
abstract MediaSource createMediaSource(MediaItem mediaItem)
```

Creates a new `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource` with the specified `https://developer.android.com/reference/androidx/media3/common/MediaItem`.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/MediaItem mediaItem` | The media item to play. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource` | The new `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource`. |

### experimentalParseSubtitlesDuringExtraction

```
@UnstableApi
@ExperimentalApi
default MediaSource.Factory [experimentalParseSubtitlesDuringExtraction](https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.Factory#experimentalParseSubtitlesDuringExtraction(boolean))(
    boolean parseSubtitlesDuringExtraction
)
```

> [!CAUTION]
> **This method is deprecated.**   
>
> This method (and all support for 'legacy' subtitle decoding during rendering) will be removed in a future release.

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 |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.Factory` | This factory, for convenience. |

### getSupportedTypes

```
@UnstableApi
@C.ContentType
abstract int[] getSupportedTypes()
```

Returns the `https://developer.android.com/reference/androidx/media3/common/C.ContentType` supported by media sources created by this factory.

### setCmcdConfigurationFactory

```
@UnstableApi
default MediaSource.Factory setCmcdConfigurationFactory(
    CmcdConfiguration.Factory cmcdConfigurationFactory
)
```

Sets the `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/CmcdConfiguration.Factory` used to obtain a `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/CmcdConfiguration` for a `https://developer.android.com/reference/androidx/media3/common/MediaItem`.

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.Factory` | This factory, for convenience. |

### setDownloadExecutor

```
@UnstableApi
@CanIgnoreReturnValue
default MediaSource.Factory setDownloadExecutor(Supplier<ReleasableExecutor> downloadExecutor)
```

Sets a supplier for an `https://developer.android.com/reference/androidx/media3/exoplayer/util/ReleasableExecutor` that is used for loading the media.

| Parameters |
|---|---|
| `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/base/Supplier.html<https://developer.android.com/reference/androidx/media3/exoplayer/util/ReleasableExecutor> downloadExecutor` | A `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/base/Supplier.html` that provides an externally managed `https://developer.android.com/reference/androidx/media3/exoplayer/util/ReleasableExecutor` for downloading and extraction. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.Factory` | This factory, for convenience. |

### setDrmSessionManagerProvider

```
@UnstableApi
abstract MediaSource.Factory setDrmSessionManagerProvider(
    DrmSessionManagerProvider drmSessionManagerProvider
)
```

Sets the `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSessionManagerProvider` used to obtain a `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSessionManager` for a `https://developer.android.com/reference/androidx/media3/common/MediaItem`.

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.Factory` | This factory, for convenience. |

### setLoadErrorHandlingPolicy

```
@UnstableApi
abstract MediaSource.Factory setLoadErrorHandlingPolicy(
    LoadErrorHandlingPolicy loadErrorHandlingPolicy
)
```

Sets an optional `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/LoadErrorHandlingPolicy`.

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.Factory` | This factory, for convenience. |

### setSubtitleParserFactory

```
@UnstableApi
default MediaSource.Factory setSubtitleParserFactory(SubtitleParser.Factory subtitleParserFactory)
```

Sets the `https://developer.android.com/reference/androidx/media3/extractor/text/SubtitleParser.Factory` to be used for parsing subtitles during extraction.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/extractor/text/SubtitleParser.Factory subtitleParserFactory` | The `https://developer.android.com/reference/androidx/media3/extractor/text/SubtitleParser.Factory` for parsing subtitles during extraction. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.Factory` | This factory, for convenience. |