Package com.google.android.exoplayer2

## Class MediaItem.Builder

- java.lang.Object
- - com.google.android.exoplayer2.MediaItem.Builder

- Enclosing class:
    MediaItem

      public static final class MediaItem.Builder
      extends Object

  A builder for `MediaItem` instances.

- - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `Builder()` | Creates a builder.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods Deprecated Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `MediaItem` | `build()` | Returns a new `MediaItem` instance with the current builder values.
    `MediaItem.Builder` | `setAdsConfiguration​(MediaItem.AdsConfiguration adsConfiguration)` | Sets the optional `MediaItem.AdsConfiguration`.
    `MediaItem.Builder` | `setAdTagUri​(Uri adTagUri)` | Deprecated. Use `setAdsConfiguration(AdsConfiguration)` and pass the `adTagUri` to `Builder(Uri)` instead.
    `MediaItem.Builder` | `setAdTagUri​(Uri adTagUri, Object adsId)` | Deprecated. Use `setAdsConfiguration(AdsConfiguration)`, pass the `adTagUri` to `Builder(Uri)` and the `adsId` to `MediaItem.AdsConfiguration.Builder.setAdsId(Object)` instead.
    `MediaItem.Builder` | `setAdTagUri​(String adTagUri)` | Deprecated. Use `setAdsConfiguration(AdsConfiguration)`, parse the `adTagUri` with `Uri.parse(String)` and pass the result to `Builder(Uri)` instead.
    `MediaItem.Builder` | `setClipEndPositionMs​(long endPositionMs)` | Deprecated. Use `setClippingConfiguration(ClippingConfiguration)` and `MediaItem.ClippingConfiguration.Builder.setEndPositionMs(long)` instead.
    `MediaItem.Builder` | `setClippingConfiguration​(MediaItem.ClippingConfiguration clippingConfiguration)` | Sets the `MediaItem.ClippingConfiguration`, defaults to `MediaItem.ClippingConfiguration.UNSET`.
    `MediaItem.Builder` | `setClipRelativeToDefaultPosition​(boolean relativeToDefaultPosition)` | Deprecated. Use `setClippingConfiguration(ClippingConfiguration)` and `MediaItem.ClippingConfiguration.Builder.setRelativeToDefaultPosition(boolean)` instead.
    `MediaItem.Builder` | `setClipRelativeToLiveWindow​(boolean relativeToLiveWindow)` | Deprecated. Use `setClippingConfiguration(ClippingConfiguration)` and `MediaItem.ClippingConfiguration.Builder.setRelativeToLiveWindow(boolean)` instead.
    `MediaItem.Builder` | `setClipStartPositionMs​(long startPositionMs)` | Deprecated. Use `setClippingConfiguration(ClippingConfiguration)` and `MediaItem.ClippingConfiguration.Builder.setStartPositionMs(long)` instead.
    `MediaItem.Builder` | `setClipStartsAtKeyFrame​(boolean startsAtKeyFrame)` | Deprecated. Use `setClippingConfiguration(ClippingConfiguration)` and `MediaItem.ClippingConfiguration.Builder.setStartsAtKeyFrame(boolean)` instead.
    `MediaItem.Builder` | `setCustomCacheKey​(String customCacheKey)` | Sets the optional custom cache key (only used for progressive streams).
    `MediaItem.Builder` | `setDrmConfiguration​(MediaItem.DrmConfiguration drmConfiguration)` | Sets the optional DRM configuration.
    `MediaItem.Builder` | `setDrmForceDefaultLicenseUri​(boolean forceDefaultLicenseUri)` | Deprecated. Use `setDrmConfiguration(DrmConfiguration)` and `MediaItem.DrmConfiguration.Builder.setForceDefaultLicenseUri(boolean)` instead.
    `MediaItem.Builder` | `setDrmKeySetId​(byte[] keySetId)` | Deprecated. Use `setDrmConfiguration(DrmConfiguration)` and `MediaItem.DrmConfiguration.Builder.setKeySetId(byte[])` instead.
    `MediaItem.Builder` | `setDrmLicenseRequestHeaders​(Map<String,​String> licenseRequestHeaders)` | Deprecated. Use `setDrmConfiguration(DrmConfiguration)` and `MediaItem.DrmConfiguration.Builder.setLicenseRequestHeaders(Map)` instead.
    `MediaItem.Builder` | `setDrmLicenseUri​(Uri licenseUri)` | Deprecated. Use `setDrmConfiguration(DrmConfiguration)` and `MediaItem.DrmConfiguration.Builder.setLicenseUri(Uri)` instead.
    `MediaItem.Builder` | `setDrmLicenseUri​(String licenseUri)` | Deprecated. Use `setDrmConfiguration(DrmConfiguration)` and `MediaItem.DrmConfiguration.Builder.setLicenseUri(String)` instead.
    `MediaItem.Builder` | `setDrmMultiSession​(boolean multiSession)` | Deprecated. Use `setDrmConfiguration(DrmConfiguration)` and `MediaItem.DrmConfiguration.Builder.setMultiSession(boolean)` instead.
    `MediaItem.Builder` | `setDrmPlayClearContentWithoutKey​(boolean playClearContentWithoutKey)` | Deprecated. Use `setDrmConfiguration(DrmConfiguration)` and `MediaItem.DrmConfiguration.Builder.setPlayClearContentWithoutKey(boolean)` instead.
    `MediaItem.Builder` | `setDrmSessionForClearPeriods​(boolean sessionForClearPeriods)` | Deprecated. Use `setDrmConfiguration(DrmConfiguration)` and `MediaItem.DrmConfiguration.Builder.setForceSessionsForAudioAndVideoTracks(boolean)` instead.
    `MediaItem.Builder` | `setDrmSessionForClearTypes​(List<@TrackType Integer> sessionForClearTypes)` | Deprecated. Use `setDrmConfiguration(DrmConfiguration)` and `MediaItem.DrmConfiguration.Builder.setForcedSessionTrackTypes(List)` instead.
    `MediaItem.Builder` | `setDrmUuid​(UUID uuid)` | Deprecated. Use `setDrmConfiguration(DrmConfiguration)` and pass the `uuid` to `Builder(UUID)` instead.
    `MediaItem.Builder` | `setLiveConfiguration​(MediaItem.LiveConfiguration liveConfiguration)` | Sets the `MediaItem.LiveConfiguration`.
    `MediaItem.Builder` | `setLiveMaxOffsetMs​(long liveMaxOffsetMs)` | Deprecated. Use `setLiveConfiguration(LiveConfiguration)` and `MediaItem.LiveConfiguration.Builder.setMaxOffsetMs(long)`.
    `MediaItem.Builder` | `setLiveMaxPlaybackSpeed​(float maxPlaybackSpeed)` | Deprecated. Use `setLiveConfiguration(LiveConfiguration)` and `MediaItem.LiveConfiguration.Builder.setMaxPlaybackSpeed(float)`.
    `MediaItem.Builder` | `setLiveMinOffsetMs​(long liveMinOffsetMs)` | Deprecated. Use `setLiveConfiguration(LiveConfiguration)` and `MediaItem.LiveConfiguration.Builder.setMinOffsetMs(long)`.
    `MediaItem.Builder` | `setLiveMinPlaybackSpeed​(float minPlaybackSpeed)` | Deprecated. Use `setLiveConfiguration(LiveConfiguration)` and `MediaItem.LiveConfiguration.Builder.setMinPlaybackSpeed(float)`.
    `MediaItem.Builder` | `setLiveTargetOffsetMs​(long liveTargetOffsetMs)` | Deprecated. Use `setLiveConfiguration(LiveConfiguration)` and `MediaItem.LiveConfiguration.Builder.setTargetOffsetMs(long)`.
    `MediaItem.Builder` | `setMediaId​(String mediaId)` | Sets the optional media ID which identifies the media item.
    `MediaItem.Builder` | `setMediaMetadata​(MediaMetadata mediaMetadata)` | Sets the media metadata.
    `MediaItem.Builder` | `setMimeType​(String mimeType)` | Sets the optional MIME type.
    `MediaItem.Builder` | `setRequestMetadata​(MediaItem.RequestMetadata requestMetadata)` | Sets the request metadata.
    `MediaItem.Builder` | `setStreamKeys​(List<StreamKey> streamKeys)` | Sets the optional stream keys by which the manifest is filtered (only used for adaptive streams).
    `MediaItem.Builder` | `setSubtitleConfigurations​(List<MediaItem.SubtitleConfiguration> subtitleConfigurations)` | Sets the optional subtitles.
    `MediaItem.Builder` | `setSubtitles​(List<MediaItem.Subtitle> subtitles)` | Deprecated. Use `setSubtitleConfigurations(List)` instead.
    `MediaItem.Builder` | `setTag​(Object tag)` | Sets the optional tag for custom attributes.
    `MediaItem.Builder` | `setUri​(Uri uri)` | Sets the optional URI.
    `MediaItem.Builder` | `setUri​(String uri)` | Sets the optional URI.

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

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

- - ### Constructor Detail

    - #### Builder

          public Builder()

      Creates a builder.

  - ### Method Detail

    - #### setMediaId

          @CanIgnoreReturnValue
          public MediaItem.Builder setMediaId​(String mediaId)

      Sets the optional media ID which identifies the media item.

      By default `MediaItem.DEFAULT_MEDIA_ID` is used.

    - #### setUri

          @CanIgnoreReturnValue
          public MediaItem.Builder setUri​(@Nullable
                                          String uri)

      Sets the optional URI.

      If `uri` is null or unset then no `MediaItem.LocalConfiguration` object is created during `build()` and no other `Builder` methods that would populate `MediaItem.localConfiguration` should be called.

    - #### setUri

          @CanIgnoreReturnValue
          public MediaItem.Builder setUri​(@Nullable
                                          Uri uri)

      Sets the optional URI.

      If `uri` is null or unset then no `MediaItem.LocalConfiguration` object is created during `build()` and no other `Builder` methods that would populate `MediaItem.localConfiguration` should be called.

    - #### setMimeType

          @CanIgnoreReturnValue
          public MediaItem.Builder setMimeType​(@Nullable
                                               String mimeType)

      Sets the optional MIME type.

      The MIME type may be used as a hint for inferring the type of the media item.

      This method should only be called if `setUri(java.lang.String)` is passed a non-null value.

      Parameters:
        `mimeType` - The MIME type.

    - #### setClippingConfiguration

          @CanIgnoreReturnValue
          public MediaItem.Builder setClippingConfiguration​(MediaItem.ClippingConfiguration clippingConfiguration)

      Sets the `MediaItem.ClippingConfiguration`, defaults to `MediaItem.ClippingConfiguration.UNSET`.

    - #### setClipStartPositionMs

          @CanIgnoreReturnValue
          @Deprecated
          public MediaItem.Builder setClipStartPositionMs​(@IntRange(from=0L)
                                                          long startPositionMs)

      Deprecated.
      Use `setClippingConfiguration(ClippingConfiguration)` and `MediaItem.ClippingConfiguration.Builder.setStartPositionMs(long)` instead.

    - #### setClipEndPositionMs

          @CanIgnoreReturnValue
          @Deprecated
          public MediaItem.Builder setClipEndPositionMs​(long endPositionMs)

      Deprecated.
      Use `setClippingConfiguration(ClippingConfiguration)` and `MediaItem.ClippingConfiguration.Builder.setEndPositionMs(long)` instead.

    - #### setClipRelativeToLiveWindow

          @CanIgnoreReturnValue
          @Deprecated
          public MediaItem.Builder setClipRelativeToLiveWindow​(boolean relativeToLiveWindow)

      Deprecated.
      Use `setClippingConfiguration(ClippingConfiguration)` and `MediaItem.ClippingConfiguration.Builder.setRelativeToLiveWindow(boolean)` instead.

    - #### setClipRelativeToDefaultPosition

          @CanIgnoreReturnValue
          @Deprecated
          public MediaItem.Builder setClipRelativeToDefaultPosition​(boolean relativeToDefaultPosition)

      Deprecated.
      Use `setClippingConfiguration(ClippingConfiguration)` and `MediaItem.ClippingConfiguration.Builder.setRelativeToDefaultPosition(boolean)` instead.

    - #### setClipStartsAtKeyFrame

          @CanIgnoreReturnValue
          @Deprecated
          public MediaItem.Builder setClipStartsAtKeyFrame​(boolean startsAtKeyFrame)

      Deprecated.
      Use `setClippingConfiguration(ClippingConfiguration)` and `MediaItem.ClippingConfiguration.Builder.setStartsAtKeyFrame(boolean)` instead.

    - #### setDrmConfiguration

          @CanIgnoreReturnValue
          public MediaItem.Builder setDrmConfiguration​(@Nullable
                                                       MediaItem.DrmConfiguration drmConfiguration)

      Sets the optional DRM configuration.

    - #### setDrmLicenseUri

          @CanIgnoreReturnValue
          @Deprecated
          public MediaItem.Builder setDrmLicenseUri​(@Nullable
                                                    Uri licenseUri)

      Deprecated.
      Use `setDrmConfiguration(DrmConfiguration)` and `MediaItem.DrmConfiguration.Builder.setLicenseUri(Uri)` instead.

    - #### setDrmLicenseUri

          @CanIgnoreReturnValue
          @Deprecated
          public MediaItem.Builder setDrmLicenseUri​(@Nullable
                                                    String licenseUri)

      Deprecated.
      Use `setDrmConfiguration(DrmConfiguration)` and `MediaItem.DrmConfiguration.Builder.setLicenseUri(String)` instead.

    - #### setDrmLicenseRequestHeaders

          @CanIgnoreReturnValue
          @Deprecated
          public MediaItem.Builder setDrmLicenseRequestHeaders​(@Nullable
                                                               Map<String,​String> licenseRequestHeaders)

      Deprecated.
      Use `setDrmConfiguration(DrmConfiguration)` and `MediaItem.DrmConfiguration.Builder.setLicenseRequestHeaders(Map)` instead. Note that `MediaItem.DrmConfiguration.Builder.setLicenseRequestHeaders(Map)` doesn't accept null, use an empty map to clear the headers.

    - #### setDrmUuid

          @CanIgnoreReturnValue
          @Deprecated
          public MediaItem.Builder setDrmUuid​(@Nullable
                                              UUID uuid)

      Deprecated.
      Use `setDrmConfiguration(DrmConfiguration)` and pass the `uuid` to `Builder(UUID)` instead.

    - #### setDrmMultiSession

          @CanIgnoreReturnValue
          @Deprecated
          public MediaItem.Builder setDrmMultiSession​(boolean multiSession)

      Deprecated.
      Use `setDrmConfiguration(DrmConfiguration)` and `MediaItem.DrmConfiguration.Builder.setMultiSession(boolean)` instead.

    - #### setDrmForceDefaultLicenseUri

          @CanIgnoreReturnValue
          @Deprecated
          public MediaItem.Builder setDrmForceDefaultLicenseUri​(boolean forceDefaultLicenseUri)

      Deprecated.
      Use `setDrmConfiguration(DrmConfiguration)` and `MediaItem.DrmConfiguration.Builder.setForceDefaultLicenseUri(boolean)` instead.

    - #### setDrmPlayClearContentWithoutKey

          @CanIgnoreReturnValue
          @Deprecated
          public MediaItem.Builder setDrmPlayClearContentWithoutKey​(boolean playClearContentWithoutKey)

      Deprecated.
      Use `setDrmConfiguration(DrmConfiguration)` and `MediaItem.DrmConfiguration.Builder.setPlayClearContentWithoutKey(boolean)` instead.

    - #### setDrmSessionForClearPeriods

          @CanIgnoreReturnValue
          @Deprecated
          public MediaItem.Builder setDrmSessionForClearPeriods​(boolean sessionForClearPeriods)

      Deprecated.
      Use `setDrmConfiguration(DrmConfiguration)` and `MediaItem.DrmConfiguration.Builder.setForceSessionsForAudioAndVideoTracks(boolean)` instead.

    - #### setDrmSessionForClearTypes

          @CanIgnoreReturnValue
          @Deprecated
          public MediaItem.Builder setDrmSessionForClearTypes​(@Nullable
                                                              List<@TrackType Integer> sessionForClearTypes)

      Deprecated.
      Use `setDrmConfiguration(DrmConfiguration)` and `MediaItem.DrmConfiguration.Builder.setForcedSessionTrackTypes(List)` instead. Note that `MediaItem.DrmConfiguration.Builder.setForcedSessionTrackTypes(List)` doesn't accept null, use an empty list to clear the contents.

    - #### setDrmKeySetId

          @CanIgnoreReturnValue
          @Deprecated
          public MediaItem.Builder setDrmKeySetId​(@Nullable
                                                  byte[] keySetId)

      Deprecated.
      Use `setDrmConfiguration(DrmConfiguration)` and `MediaItem.DrmConfiguration.Builder.setKeySetId(byte[])` instead.

    - #### setStreamKeys

          @CanIgnoreReturnValue
          public MediaItem.Builder setStreamKeys​(@Nullable
                                                 List<StreamKey> streamKeys)

      Sets the optional stream keys by which the manifest is filtered (only used for adaptive streams).

      `null` or an empty `List` can be used for a reset.

      If `setUri(java.lang.String)` is passed a non-null `uri`, the stream keys are used to create a `MediaItem.LocalConfiguration` object. Otherwise they will be ignored.

    - #### setCustomCacheKey

          @CanIgnoreReturnValue
          public MediaItem.Builder setCustomCacheKey​(@Nullable
                                                     String customCacheKey)

      Sets the optional custom cache key (only used for progressive streams).

      This method should only be called if `setUri(java.lang.String)` is passed a non-null value.

    - #### setSubtitles

          @CanIgnoreReturnValue
          @Deprecated
          public MediaItem.Builder setSubtitles​(@Nullable
                                                List<MediaItem.Subtitle> subtitles)

      Deprecated.
      Use `setSubtitleConfigurations(List)` instead. Note that `setSubtitleConfigurations(List)` doesn't accept null, use an empty list to clear the contents.

    - #### setSubtitleConfigurations

          @CanIgnoreReturnValue
          public MediaItem.Builder setSubtitleConfigurations​(List<MediaItem.SubtitleConfiguration> subtitleConfigurations)

      Sets the optional subtitles.

      This method should only be called if `setUri(java.lang.String)` is passed a non-null value.

    - #### setAdsConfiguration

          @CanIgnoreReturnValue
          public MediaItem.Builder setAdsConfiguration​(@Nullable
                                                       MediaItem.AdsConfiguration adsConfiguration)

      Sets the optional `MediaItem.AdsConfiguration`.

      This method should only be called if `setUri(java.lang.String)` is passed a non-null value.

    - #### setAdTagUri

          @CanIgnoreReturnValue
          @Deprecated
          public MediaItem.Builder setAdTagUri​(@Nullable
                                               String adTagUri)

      Deprecated.
      Use `setAdsConfiguration(AdsConfiguration)`, parse the `adTagUri` with `Uri.parse(String)` and pass the result to `Builder(Uri)` instead.

    - #### setAdTagUri

          @CanIgnoreReturnValue
          @Deprecated
          public MediaItem.Builder setAdTagUri​(@Nullable
                                               Uri adTagUri)

      Deprecated.
      Use `setAdsConfiguration(AdsConfiguration)` and pass the `adTagUri` to `Builder(Uri)` instead.

    - #### setAdTagUri

          @CanIgnoreReturnValue
          @Deprecated
          public MediaItem.Builder setAdTagUri​(@Nullable
                                               Uri adTagUri,
                                               @Nullable
                                               Object adsId)

      Deprecated.
      Use `setAdsConfiguration(AdsConfiguration)`, pass the `adTagUri` to `Builder(Uri)` and the `adsId` to `MediaItem.AdsConfiguration.Builder.setAdsId(Object)` instead.

    - #### setLiveConfiguration

          @CanIgnoreReturnValue
          public MediaItem.Builder setLiveConfiguration​(MediaItem.LiveConfiguration liveConfiguration)

      Sets the `MediaItem.LiveConfiguration`. Defaults to `MediaItem.LiveConfiguration.UNSET`.

    - #### setLiveTargetOffsetMs

          @CanIgnoreReturnValue
          @Deprecated
          public MediaItem.Builder setLiveTargetOffsetMs​(long liveTargetOffsetMs)

      Deprecated.
      Use `setLiveConfiguration(LiveConfiguration)` and `MediaItem.LiveConfiguration.Builder.setTargetOffsetMs(long)`.

    - #### setLiveMinOffsetMs

          @CanIgnoreReturnValue
          @Deprecated
          public MediaItem.Builder setLiveMinOffsetMs​(long liveMinOffsetMs)

      Deprecated.
      Use `setLiveConfiguration(LiveConfiguration)` and `MediaItem.LiveConfiguration.Builder.setMinOffsetMs(long)`.

    - #### setLiveMaxOffsetMs

          @CanIgnoreReturnValue
          @Deprecated
          public MediaItem.Builder setLiveMaxOffsetMs​(long liveMaxOffsetMs)

      Deprecated.
      Use `setLiveConfiguration(LiveConfiguration)` and `MediaItem.LiveConfiguration.Builder.setMaxOffsetMs(long)`.

    - #### setLiveMinPlaybackSpeed

          @CanIgnoreReturnValue
          @Deprecated
          public MediaItem.Builder setLiveMinPlaybackSpeed​(float minPlaybackSpeed)

      Deprecated.
      Use `setLiveConfiguration(LiveConfiguration)` and `MediaItem.LiveConfiguration.Builder.setMinPlaybackSpeed(float)`.

    - #### setLiveMaxPlaybackSpeed

          @CanIgnoreReturnValue
          @Deprecated
          public MediaItem.Builder setLiveMaxPlaybackSpeed​(float maxPlaybackSpeed)

      Deprecated.
      Use `setLiveConfiguration(LiveConfiguration)` and `MediaItem.LiveConfiguration.Builder.setMaxPlaybackSpeed(float)`.

    - #### setTag

          @CanIgnoreReturnValue
          public MediaItem.Builder setTag​(@Nullable
                                          Object tag)

      Sets the optional tag for custom attributes. The tag for the media source which will be published in the `com.google.android.exoplayer2.Timeline` of the source as `com.google.android.exoplayer2.Timeline.Window#tag`.

      This method should only be called if `setUri(java.lang.String)` is passed a non-null value.

    - #### setMediaMetadata

          @CanIgnoreReturnValue
          public MediaItem.Builder setMediaMetadata​(MediaMetadata mediaMetadata)

      Sets the media metadata.

    - #### setRequestMetadata

          @CanIgnoreReturnValue
          public MediaItem.Builder setRequestMetadata​(MediaItem.RequestMetadata requestMetadata)

      Sets the request metadata.

    - #### build

          public MediaItem build()

      Returns a new `MediaItem` instance with the current builder values.