Package com.google.android.exoplayer2.source

## Class DefaultMediaSourceFactory

- java.lang.Object
- - com.google.android.exoplayer2.source.DefaultMediaSourceFactory

- All Implemented Interfaces:
    `MediaSourceFactory`

      public final class DefaultMediaSourceFactory
      extends Object
      implements MediaSourceFactory

  The default `MediaSourceFactory` 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.DefaultMediaSourceFactory.AdsLoaderProvider)` 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` | Provides `AdsLoader` instances for media items that have `ad tag URIs`.

  - ### 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
    --- | --- | ---
    `MediaSource` | `createMediaSource​(MediaItem mediaItem)` | Creates a new `MediaSource` with the specified `MediaItem`.
    `int[]` | `getSupportedTypes()` | Returns the `content types` supported by media sources created by this factory.
    `DefaultMediaSourceFactory` | `setAdsLoaderProvider​(DefaultMediaSourceFactory.AdsLoaderProvider adsLoaderProvider)` | Sets the `DefaultMediaSourceFactory.AdsLoaderProvider` that provides `AdsLoader` instances for media items that have `ads configurations`.
    `DefaultMediaSourceFactory` | `setAdViewProvider​(AdViewProvider adViewProvider)` | Sets the `AdViewProvider` that provides information about views for the ad playback UI.
    `DefaultMediaSourceFactory` | `setDrmHttpDataSourceFactory​(HttpDataSource.Factory drmHttpDataSourceFactory)` | Sets the `HttpDataSource.Factory` to be used for creating `HttpMediaDrmCallbacks` to execute key and provisioning requests over HTTP.
    `DefaultMediaSourceFactory` | `setDrmSessionManager​(DrmSessionManager drmSessionManager)` | Sets the `DrmSessionManager` to use for all media items regardless of their `MediaItem.DrmConfiguration`.
    `DefaultMediaSourceFactory` | `setDrmSessionManagerProvider​(DrmSessionManagerProvider drmSessionManagerProvider)` | Sets the `DrmSessionManagerProvider` used to obtain a `DrmSessionManager` for a `MediaItem`.
    `DefaultMediaSourceFactory` | `setDrmUserAgent​(String userAgent)` | Sets the optional user agent to be used for DRM requests.
    `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` | `setStreamKeys​(List<StreamKey> streamKeys)` | Deprecated. Use `MediaItem.Builder.setStreamKeys(List)` and `createMediaSource(MediaItem)` instead.

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

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

    - ### Methods inherited from interface com.google.android.exoplayer2.source.MediaSourceFactory

      `createMediaSource`

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

    - #### DefaultMediaSourceFactory

          public DefaultMediaSourceFactory​(DataSource.Factory dataSourceFactory)

      Creates a new instance.
      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.
      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

    - #### setAdsLoaderProvider

          public DefaultMediaSourceFactory setAdsLoaderProvider​(@Nullable
                                                                DefaultMediaSourceFactory.AdsLoaderProvider adsLoaderProvider)

      Sets the `DefaultMediaSourceFactory.AdsLoaderProvider` that provides `AdsLoader` instances for media items that have `ads configurations`.
      Parameters:
        `adsLoaderProvider` - A provider for `AdsLoader` instances.
      Returns:
        This factory, for convenience.

    - #### setAdViewProvider

          public DefaultMediaSourceFactory setAdViewProvider​(@Nullable
                                                             AdViewProvider adViewProvider)

      Sets the `AdViewProvider` that provides information about views for the ad playback UI.
      Parameters:
        `adViewProvider` - A provider for `AdsLoader` instances.
      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, or `C.TIME_UNSET` to 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, or `C.TIME_UNSET` to 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, or `C.TIME_UNSET` to 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, or `C.RATE_UNSET` to 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, or `C.RATE_UNSET` to use the media-defined default.
      Returns:
        This factory, for convenience.

    - #### setDrmHttpDataSourceFactory

          public DefaultMediaSourceFactory setDrmHttpDataSourceFactory​(@Nullable
                                                                       HttpDataSource.Factory drmHttpDataSourceFactory)

      Description copied from interface: `MediaSourceFactory`
      Sets the `HttpDataSource.Factory` to be used for creating `HttpMediaDrmCallbacks` to execute key and provisioning requests over HTTP.

      Calls to this method are ignored if either a `DrmSessionManager provider` or `concrete DrmSessionManager` are provided.

      Specified by:
        `setDrmHttpDataSourceFactory` in interface `MediaSourceFactory`
      Parameters:
        `drmHttpDataSourceFactory` - The HTTP data source factory, or `null` to use `DefaultHttpDataSourceFactory`.
      Returns:
        This factory, for convenience.

    - #### setDrmUserAgent

          public DefaultMediaSourceFactory setDrmUserAgent​(@Nullable
                                                           String userAgent)

      Description copied from interface: `MediaSourceFactory`
      Sets the optional user agent to be used for DRM requests.

      Calls to this method are ignored if any of the following are provided:

      - A `DrmSessionManager provider`.
      - A `concrete DrmSessionManager`.
      - A `DRM HttpDataSource.Factory`.
      Specified by:
        `setDrmUserAgent` in interface `MediaSourceFactory`
      Parameters:
        `userAgent` - The user agent to be used for DRM requests, or `null` to use the default.
      Returns:
        This factory, for convenience.

    - #### setDrmSessionManager

          public DefaultMediaSourceFactory setDrmSessionManager​(@Nullable
                                                                DrmSessionManager drmSessionManager)

      Description copied from interface: `MediaSourceFactory`
      Sets the `DrmSessionManager` to use for all media items regardless of their `MediaItem.DrmConfiguration`.

      Calling this with a non-null `drmSessionManager` is equivalent to calling `setDrmSessionManagerProvider(unusedMediaItem -> drmSessionManager)`.

      Specified by:
        `setDrmSessionManager` in interface `MediaSourceFactory`
      Parameters:
        `drmSessionManager` - The `DrmSessionManager`, or `null` to use the `DefaultDrmSessionManager`.
      Returns:
        This factory, for convenience.

    - #### setDrmSessionManagerProvider

          public DefaultMediaSourceFactory setDrmSessionManagerProvider​(@Nullable
                                                                        DrmSessionManagerProvider drmSessionManagerProvider)

      Description copied from interface: `MediaSourceFactory`
      Sets the `DrmSessionManagerProvider` used to obtain a `DrmSessionManager` for a `MediaItem`.

      If not set, `DefaultDrmSessionManagerProvider` is used.

      If set, calls to the following (deprecated) methods are ignored:

      - `MediaSourceFactory.setDrmUserAgent(String)`
      - `MediaSourceFactory.setDrmHttpDataSourceFactory(HttpDataSource.Factory)`
      Specified by:
        `setDrmSessionManagerProvider` in interface `MediaSourceFactory`
      Returns:
        This factory, for convenience.

    - #### setLoadErrorHandlingPolicy

          public DefaultMediaSourceFactory setLoadErrorHandlingPolicy​(@Nullable
                                                                      LoadErrorHandlingPolicy loadErrorHandlingPolicy)

      Description copied from interface: `MediaSourceFactory`
      Sets an optional `LoadErrorHandlingPolicy`.
      Specified by:
        `setLoadErrorHandlingPolicy` in interface `MediaSourceFactory`
      Parameters:
        `loadErrorHandlingPolicy` - A `LoadErrorHandlingPolicy`, or `null` to use the `DefaultLoadErrorHandlingPolicy`.
      Returns:
        This factory, for convenience.

    - #### setStreamKeys

          @Deprecated
          public DefaultMediaSourceFactory setStreamKeys​(@Nullable
                                                         List<StreamKey> streamKeys)

      Deprecated.
      Use `MediaItem.Builder.setStreamKeys(List)` and `createMediaSource(MediaItem)` instead.
      Specified by:
        `setStreamKeys` in interface `MediaSourceFactory`

    - #### getSupportedTypes

          public int[] getSupportedTypes()

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

    - #### createMediaSource

          public MediaSource createMediaSource​(MediaItem mediaItem)

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