Class MediaItem.Builder

  • Enclosing class:
    MediaItem

    public static final class MediaItem.Builder
    extends Object
    A builder for MediaItem instances.
    • Constructor Detail

      • Builder

        public Builder()
        Creates a builder.
    • Method Detail

      • setMimeType

        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.

        If setUri(java.lang.String) is passed a non-null uri, the MIME type is used to create a MediaItem.PlaybackProperties object. Otherwise it will be ignored.

        Parameters:
        mimeType - The MIME type.
      • setClipStartPositionMs

        public MediaItem.Builder setClipStartPositionMs​(long startPositionMs)
        Sets the optional start position in milliseconds which must be a value larger than or equal to zero (Default: 0).
      • setClipEndPositionMs

        public MediaItem.Builder setClipEndPositionMs​(long endPositionMs)
        Sets the optional end position in milliseconds which must be a value larger than or equal to zero, or C.TIME_END_OF_SOURCE to end when playback reaches the end of media (Default: C.TIME_END_OF_SOURCE).
      • setClipRelativeToLiveWindow

        public MediaItem.Builder setClipRelativeToLiveWindow​(boolean relativeToLiveWindow)
        Sets whether the start/end positions should move with the live window for live streams. If false, live streams end when playback reaches the end position in live window seen when the media is first loaded (Default: false).
      • setClipRelativeToDefaultPosition

        public MediaItem.Builder setClipRelativeToDefaultPosition​(boolean relativeToDefaultPosition)
        Sets whether the start position and the end position are relative to the default position in the window (Default: false).
      • setClipStartsAtKeyFrame

        public MediaItem.Builder setClipStartsAtKeyFrame​(boolean startsAtKeyFrame)
        Sets whether the start point is guaranteed to be a key frame. If false, the playback transition into the clip may not be seamless (Default: false).
      • setDrmLicenseRequestHeaders

        public MediaItem.Builder setDrmLicenseRequestHeaders​(@Nullable
                                                             Map<String,​String> licenseRequestHeaders)
        Sets the optional request headers attached to the DRM license request.

        null or an empty Map can be used for a reset.

        If no valid DRM configuration is specified, the DRM license request headers are ignored.

      • setDrmForceDefaultLicenseUri

        public MediaItem.Builder setDrmForceDefaultLicenseUri​(boolean forceDefaultLicenseUri)
        Sets whether to force use the default DRM license server URI even if the media specifies its own DRM license server URI.

        If setUri(java.lang.String) is passed a non-null uri, the DRM force default license flag is used to create a MediaItem.PlaybackProperties object. Otherwise it will be ignored.

      • setDrmPlayClearContentWithoutKey

        public MediaItem.Builder setDrmPlayClearContentWithoutKey​(boolean playClearContentWithoutKey)
        Sets whether clear samples within protected content should be played when keys for the encrypted part of the content have yet to be loaded.
      • setDrmKeySetId

        public MediaItem.Builder setDrmKeySetId​(@Nullable
                                                byte[] keySetId)
        Sets the key set ID of the offline license.

        The key set ID identifies an offline license. The ID is required to query, renew or release an existing offline license (see DefaultDrmSessionManager#setMode(int mode,byte[] offlineLicenseKeySetId)).

        If no valid DRM configuration is specified, the key set ID is ignored.

      • setAdTagUri

        public MediaItem.Builder setAdTagUri​(@Nullable
                                             String adTagUri)
        Sets the optional ad tag Uri.

        If setUri(java.lang.String) is passed a non-null uri, the ad tag URI is used to create a MediaItem.PlaybackProperties object. Otherwise it will be ignored.

        Media items in the playlist with the same ad tag URI, media ID and ads loader will share the same ad playback state. To resume ad playback when recreating the playlist on returning from the background, pass media items with the same ad tag URIs and media IDs to the player.

        Parameters:
        adTagUri - The ad tag URI to load.
      • setAdTagUri

        public MediaItem.Builder setAdTagUri​(@Nullable
                                             Uri adTagUri)
        Sets the optional ad tag Uri.

        If setUri(java.lang.String) is passed a non-null uri, the ad tag URI is used to create a MediaItem.PlaybackProperties object. Otherwise it will be ignored.

        Media items in the playlist with the same ad tag URI, media ID and ads loader will share the same ad playback state. To resume ad playback when recreating the playlist on returning from the background, pass media items with the same ad tag URIs and media IDs to the player.

        Parameters:
        adTagUri - The ad tag URI to load.
      • setAdTagUri

        public MediaItem.Builder setAdTagUri​(@Nullable
                                             Uri adTagUri,
                                             @Nullable
                                             Object adsId)
        Sets the optional ad tag Uri and ads identifier.

        If setUri(java.lang.String) is passed a non-null uri, the ad tag URI is used to create a MediaItem.PlaybackProperties object. Otherwise it will be ignored.

        Media items in the playlist that have the same ads identifier and ads loader share the same ad playback state. To resume ad playback when recreating the playlist on returning from the background, pass the same ads IDs to the player.

        Parameters:
        adTagUri - The ad tag URI to load.
        adsId - An opaque identifier for ad playback state associated with this item. Ad loading and playback state is shared among all media items that have the same ads ID (by equality) and ads loader, so it is important to pass the same identifiers when constructing playlist items each time the player returns to the foreground.
      • setLiveTargetOffsetMs

        public MediaItem.Builder setLiveTargetOffsetMs​(long liveTargetOffsetMs)
        Sets the optional target offset from the live edge for live streams, in milliseconds.

        See Player#getCurrentLiveOffset().

        Parameters:
        liveTargetOffsetMs - The target offset, in milliseconds, or C.TIME_UNSET to use the media-defined default.
      • setLiveMinOffsetMs

        public MediaItem.Builder setLiveMinOffsetMs​(long liveMinOffsetMs)
        Sets the optional minimum offset from the live edge for live streams, in milliseconds.

        See Player#getCurrentLiveOffset().

        Parameters:
        liveMinOffsetMs - The minimum allowed offset, in milliseconds, or C.TIME_UNSET to use the media-defined default.
      • setLiveMaxOffsetMs

        public MediaItem.Builder setLiveMaxOffsetMs​(long liveMaxOffsetMs)
        Sets the optional maximum offset from the live edge for live streams, in milliseconds.

        See Player#getCurrentLiveOffset().

        Parameters:
        liveMaxOffsetMs - The maximum allowed offset, in milliseconds, or C.TIME_UNSET to use the media-defined default.
      • setLiveMinPlaybackSpeed

        public MediaItem.Builder setLiveMinPlaybackSpeed​(float minPlaybackSpeed)
        Sets the optional minimum playback speed for live stream speed adjustment.

        This value is ignored for other stream types.

        Parameters:
        minPlaybackSpeed - The minimum factor by which playback can be sped up for live streams, or C.RATE_UNSET to use the media-defined default.
      • setLiveMaxPlaybackSpeed

        public MediaItem.Builder setLiveMaxPlaybackSpeed​(float maxPlaybackSpeed)
        Sets the optional maximum playback speed for live stream speed adjustment.

        This value is ignored for other stream types.

        Parameters:
        maxPlaybackSpeed - The maximum factor by which playback can be sped up for live streams, or C.RATE_UNSET to use the media-defined default.
      • setTag

        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.

        If setUri(java.lang.String) is passed a non-null uri, the tag is used to create a MediaItem.PlaybackProperties object. Otherwise it will be ignored.

      • build

        public MediaItem build()
        Returns a new MediaItem instance with the current builder values.