Package com.google.android.exoplayer2.source

## 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 default `MediaSource.Factory` implementation.

  This implementation delegates calls to `createMediaSource(MediaItem)` to the following factories:

  - `DashMediaSource.Factory` if the item's `uri` ends in '.mpd' or if its `mimeType field` is explicitly set to `MimeTypes.APPLICATION_MPD` (Requires the exoplayer-dash module to be added to the app).
  - `HlsMediaSource.Factory` if the item's `uri` ends in '.m3u8' or if its `mimeType field` is explicitly set to `MimeTypes.APPLICATION_M3U8` (Requires the exoplayer-hls module to be added to the app).
  - `SsMediaSource.Factory` if the item's `uri` ends in '.ism', '.ism/Manifest' or if its `mimeType field` is explicitly set to `MimeTypes.APPLICATION_SS` (Requires the exoplayer-smoothstreaming module to be added to the app).
  - `ProgressiveMediaSource.Factory` serves as a fallback if the item's `uri` doesn't match one of the above. It tries to infer the required extractor by using the `DefaultExtractorsFactory` or the `ExtractorsFactory` provided in the constructor. An `UnrecognizedInputFormatException` is 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)` and `setAdViewProvider(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 interface` | `DefaultMediaSourceFactory.AdsLoaderProvider` | Deprecated. Use `AdsLoader.Provider` instead.

  - ### 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 Deprecated Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `DefaultMediaSourceFactory` | `clearLocalAdInsertionComponents()` | Clear any values set via `setLocalAdInsertionComponents(AdsLoader.Provider, AdViewProvider)`.
    `MediaSource` | `createMediaSource​(MediaItem mediaItem)` | Creates a new `MediaSource` with the specified `MediaItem`.
    `DefaultMediaSourceFactory` | `experimentalUseProgressiveMediaSourceForSubtitles​(boolean useProgressiveMediaSourceForSubtitles)` | Sets whether a `ProgressiveMediaSource` or `SingleSampleMediaSource` is constructed to handle `MediaItem.LocalConfiguration.subtitleConfigurations`.
    `@com.google.android.exoplayer2.C.ContentType int[]` | `getSupportedTypes()` | Returns the `content types` supported by media sources created by this factory.
    `DefaultMediaSourceFactory` | `setAdsLoaderProvider​(AdsLoader.Provider adsLoaderProvider)` | Deprecated. Use `setLocalAdInsertionComponents(AdsLoader.Provider, AdViewProvider)` instead.
    `DefaultMediaSourceFactory` | `setAdViewProvider​(AdViewProvider adViewProvider)` | Deprecated. Use `setLocalAdInsertionComponents(AdsLoader.Provider, AdViewProvider)` instead.
    `DefaultMediaSourceFactory` | `setDataSourceFactory​(DataSource.Factory dataSourceFactory)` | Sets the `DataSource.Factory` used to create `DataSource` instances for requesting media data.
    `DefaultMediaSourceFactory` | `setDrmSessionManagerProvider​(DrmSessionManagerProvider drmSessionManagerProvider)` | Sets the `DrmSessionManagerProvider` used to obtain a `DrmSessionManager` for a `MediaItem`.
    `DefaultMediaSourceFactory` | `setLiveMaxOffsetMs​(long liveMaxOffsetMs)` | Sets the maximum offset from the live edge for live streams, in milliseconds.
    `DefaultMediaSourceFactory` | `setLiveMaxSpeed​(float maxSpeed)` | Sets the maximum playback speed for live streams.
    `DefaultMediaSourceFactory` | `setLiveMinOffsetMs​(long liveMinOffsetMs)` | Sets the minimum offset from the live edge for live streams, in milliseconds.
    `DefaultMediaSourceFactory` | `setLiveMinSpeed​(float minSpeed)` | Sets the minimum playback speed for live streams.
    `DefaultMediaSourceFactory` | `setLiveTargetOffsetMs​(long liveTargetOffsetMs)` | Sets the target live offset for live streams, in milliseconds.
    `DefaultMediaSourceFactory` | `setLoadErrorHandlingPolicy​(LoadErrorHandlingPolicy loadErrorHandlingPolicy)` | Sets an optional `LoadErrorHandlingPolicy`.
    `DefaultMediaSourceFactory` | `setLocalAdInsertionComponents​(AdsLoader.Provider adsLoaderProvider, AdViewProvider adViewProvider)` | Sets the components required for local ad insertion for media items that have `ads configurations`
    `DefaultMediaSourceFactory` | `setServerSideAdInsertionMediaSourceFactory​(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).

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### 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.

      Note that this constructor is only useful to try and ensure that ExoPlayer's `DefaultExtractorsFactory` can be removed by ProGuard or R8.

      Parameters:
        `context` - Any context.
        `extractorsFactory` - An `ExtractorsFactory` used to extract progressive media from its container.

    - #### DefaultMediaSourceFactory

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

    - #### DefaultMediaSourceFactory

          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:
        `dataSourceFactory` - A `DataSource.Factory` to create `DataSource` instances for requesting media data.
        `extractorsFactory` - An `ExtractorsFactory` used to extract progressive media from its container.

  - ### Method Detail

    - #### experimentalUseProgressiveMediaSourceForSubtitles

          @CanIgnoreReturnValue
          public DefaultMediaSourceFactory experimentalUseProgressiveMediaSourceForSubtitles​(boolean useProgressiveMediaSourceForSubtitles)

      Sets whether a `ProgressiveMediaSource` or `SingleSampleMediaSource` is constructed to handle `MediaItem.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 that `ProgressiveMediaSource` should be used for subtitles instead of `SingleSampleMediaSource`.
      Returns:
        This factory, for convenience.

    - #### setAdsLoaderProvider

          @CanIgnoreReturnValue
          @Deprecated
          public DefaultMediaSourceFactory setAdsLoaderProvider​(@Nullable
                                                                AdsLoader.Provider adsLoaderProvider)

      Deprecated.
      Use `setLocalAdInsertionComponents(AdsLoader.Provider, AdViewProvider)` instead.
      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(AdsLoader.Provider, AdViewProvider)`.

      Parameters:
        `adsLoaderProvider` - A provider for `AdsLoader` instances.
      Returns:
        This factory, for convenience.

    - #### setAdViewProvider

          @CanIgnoreReturnValue
          @Deprecated
          public DefaultMediaSourceFactory setAdViewProvider​(@Nullable
                                                             AdViewProvider adViewProvider)

      Deprecated.
      Use `setLocalAdInsertionComponents(AdsLoader.Provider, AdViewProvider)` instead.
      Sets the `AdViewProvider` that provides information about views for the ad playback UI.

      This will override or clear the `AdViewProvider` set by `setLocalAdInsertionComponents(AdsLoader.Provider, AdViewProvider)`.

      Parameters:
        `adViewProvider` - A provider for information about views for the ad playback UI.
      Returns:
        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(AdsLoader.Provider)` and `setAdViewProvider(AdViewProvider)`.

      Parameters:
        `adsLoaderProvider` - A provider for `AdsLoader` instances.
        `adViewProvider` - A provider for information about views for the ad playback UI.
      Returns:
        This factory, for convenience.

    - #### clearLocalAdInsertionComponents

          @CanIgnoreReturnValue
          public DefaultMediaSourceFactory clearLocalAdInsertionComponents()

      Clear any values set via `setLocalAdInsertionComponents(AdsLoader.Provider, AdViewProvider)`.

      This will also clear any values set by `setAdsLoaderProvider(AdsLoader.Provider)` and `setAdViewProvider(AdViewProvider)`.

      Returns:
        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:
        `dataSourceFactory` - The `DataSource.Factory`.
      Returns:
        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 `C.SSAI_SCHEME`.

      Parameters:
        `serverSideAdInsertionMediaSourceFactory` - The `MediaSource.Factory` for SSAI content, or `null` to remove a previously set `MediaSource.Factory`.
      Returns:
        This factory, for convenience.

    - #### setLiveTargetOffsetMs

          @CanIgnoreReturnValue
          public DefaultMediaSourceFactory setLiveTargetOffsetMs​(long liveTargetOffsetMs)

      Sets the target live offset for live streams, in milliseconds.
      Parameters:
        `liveTargetOffsetMs` - The target live offset, in milliseconds, or `C.TIME_UNSET` to use the media-defined default.
      Returns:
        This factory, for convenience.

    - #### setLiveMinOffsetMs

          @CanIgnoreReturnValue
          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, or `C.TIME_UNSET` to use the media-defined default.
      Returns:
        This factory, for convenience.

    - #### setLiveMaxOffsetMs

          @CanIgnoreReturnValue
          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, or `C.TIME_UNSET` to use the media-defined default.
      Returns:
        This factory, for convenience.

    - #### setLiveMinSpeed

          @CanIgnoreReturnValue
          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, or `C.RATE_UNSET` to use the media-defined default.
      Returns:
        This factory, for convenience.

    - #### setLiveMaxSpeed

          @CanIgnoreReturnValue
          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, or `C.RATE_UNSET` to use the media-defined default.
      Returns:
        This factory, for convenience.

    - #### setDrmSessionManagerProvider

          @CanIgnoreReturnValue
          public DefaultMediaSourceFactory setDrmSessionManagerProvider​(DrmSessionManagerProvider drmSessionManagerProvider)

      Description copied from interface: `MediaSource.Factory`
      Sets the `DrmSessionManagerProvider` used to obtain a `DrmSessionManager` for a `MediaItem`.
      Specified by:
        `setDrmSessionManagerProvider` in interface `MediaSource.Factory`
      Returns:
        This factory, for convenience.

    - #### setLoadErrorHandlingPolicy

          @CanIgnoreReturnValue
          public DefaultMediaSourceFactory setLoadErrorHandlingPolicy​(LoadErrorHandlingPolicy loadErrorHandlingPolicy)

      Description copied from interface: `MediaSource.Factory`
      Sets an optional `LoadErrorHandlingPolicy`.
      Specified by:
        `setLoadErrorHandlingPolicy` in interface `MediaSource.Factory`
      Returns:
        This factory, for convenience.

    - #### getSupportedTypes

          @ContentType
          public @com.google.android.exoplayer2.C.ContentType int[] getSupportedTypes()

      Description copied from interface: `MediaSource.Factory`
      Returns the `content types` supported by media sources created by this factory.
      Specified by:
        `getSupportedTypes` in interface `MediaSource.Factory`

    - #### createMediaSource

          public MediaSource createMediaSource​(MediaItem mediaItem)

      Description copied from interface: `MediaSource.Factory`
      Creates a new `MediaSource` with the specified `MediaItem`.
      Specified by:
        `createMediaSource` in interface `MediaSource.Factory`
      Parameters:
        `mediaItem` - The media item to play.
      Returns:
        The new `media source`.