Class MediaItem.Builder
- java.lang.Object
-
- com.google.android.exoplayer2.MediaItem.Builder
-
-
Constructor Summary
Constructors Constructor Description Builder()Creates a builder.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description MediaItembuild()Returns a newMediaIteminstance with the current builder values.MediaItem.BuildersetAdTagUri(Uri adTagUri)Sets the optional ad tagUri.MediaItem.BuildersetAdTagUri(Uri adTagUri, Object adsId)Sets the optional ad tagUriand ads identifier.MediaItem.BuildersetAdTagUri(String adTagUri)Sets the optional ad tagUri.MediaItem.BuildersetClipEndPositionMs(long endPositionMs)Sets the optional end position in milliseconds which must be a value larger than or equal to zero, orC.TIME_END_OF_SOURCEto end when playback reaches the end of media (Default:C.TIME_END_OF_SOURCE).MediaItem.BuildersetClipRelativeToDefaultPosition(boolean relativeToDefaultPosition)Sets whether the start position and the end position are relative to the default position in the window (Default:false).MediaItem.BuildersetClipRelativeToLiveWindow(boolean relativeToLiveWindow)Sets whether the start/end positions should move with the live window for live streams.MediaItem.BuildersetClipStartPositionMs(long startPositionMs)Sets the optional start position in milliseconds which must be a value larger than or equal to zero (Default: 0).MediaItem.BuildersetClipStartsAtKeyFrame(boolean startsAtKeyFrame)Sets whether the start point is guaranteed to be a key frame.MediaItem.BuildersetCustomCacheKey(String customCacheKey)Sets the optional custom cache key (only used for progressive streams).MediaItem.BuildersetDrmForceDefaultLicenseUri(boolean forceDefaultLicenseUri)Sets whether to force use the default DRM license server URI even if the media specifies its own DRM license server URI.MediaItem.BuildersetDrmKeySetId(byte[] keySetId)Sets the key set ID of the offline license.MediaItem.BuildersetDrmLicenseRequestHeaders(Map<String,String> licenseRequestHeaders)Sets the optional request headers attached to the DRM license request.MediaItem.BuildersetDrmLicenseUri(Uri licenseUri)Sets the optional default DRM license server URI.MediaItem.BuildersetDrmLicenseUri(String licenseUri)Sets the optional default DRM license server URI.MediaItem.BuildersetDrmMultiSession(boolean multiSession)Sets whether the DRM configuration is multi session enabled.MediaItem.BuildersetDrmPlayClearContentWithoutKey(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.MediaItem.BuildersetDrmSessionForClearPeriods(boolean sessionForClearPeriods)Sets whether a DRM session should be used for clear tracks of typeC.TRACK_TYPE_VIDEOandC.TRACK_TYPE_AUDIO.MediaItem.BuildersetDrmSessionForClearTypes(List<Integer> sessionForClearTypes)Sets a list ofC.TRACK_TYPE_*constants for which to use a DRM session even when the tracks are in the clear.MediaItem.BuildersetDrmUuid(UUID uuid)Sets theUUIDof the protection scheme.MediaItem.BuildersetLiveMaxOffsetMs(long liveMaxOffsetMs)Sets the optional maximum offset from the live edge for live streams, in milliseconds.MediaItem.BuildersetLiveMaxPlaybackSpeed(float maxPlaybackSpeed)Sets the optional maximum playback speed for live stream speed adjustment.MediaItem.BuildersetLiveMinOffsetMs(long liveMinOffsetMs)Sets the optional minimum offset from the live edge for live streams, in milliseconds.MediaItem.BuildersetLiveMinPlaybackSpeed(float minPlaybackSpeed)Sets the optional minimum playback speed for live stream speed adjustment.MediaItem.BuildersetLiveTargetOffsetMs(long liveTargetOffsetMs)Sets the optional target offset from the live edge for live streams, in milliseconds.MediaItem.BuildersetMediaId(String mediaId)Sets the optional media ID which identifies the media item.MediaItem.BuildersetMediaMetadata(MediaMetadata mediaMetadata)Sets the media metadata.MediaItem.BuildersetMimeType(String mimeType)Sets the optional MIME type.MediaItem.BuildersetStreamKeys(List<StreamKey> streamKeys)Sets the optional stream keys by which the manifest is filtered (only used for adaptive streams).MediaItem.BuildersetSubtitles(List<MediaItem.Subtitle> subtitles)Sets the optional subtitles.MediaItem.BuildersetTag(Object tag)Sets the optional tag for custom attributes.MediaItem.BuildersetUri(Uri uri)Sets the optional URI.MediaItem.BuildersetUri(String uri)Sets the optional URI.
-
-
-
Method Detail
-
setMediaId
public MediaItem.Builder setMediaId(String mediaId)
Sets the optional media ID which identifies the media item.By default
MediaItem.DEFAULT_MEDIA_IDis used.
-
setUri
public MediaItem.Builder setUri(@Nullable String uri)
Sets the optional URI.If
uriis null or unset then noMediaItem.PlaybackPropertiesobject is created duringbuild()and no otherBuildermethods that would populateMediaItem.playbackPropertiesshould be called.
-
setUri
public MediaItem.Builder setUri(@Nullable Uri uri)
Sets the optional URI.If
uriis null or unset then noMediaItem.PlaybackPropertiesobject is created duringbuild()and no otherBuildermethods that would populateMediaItem.playbackPropertiesshould be called.
-
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.
This method should only be called if
setUri(java.lang.String)is passed a non-null value.- 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, orC.TIME_END_OF_SOURCEto 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. Iffalse, 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. Iffalse, the playback transition into the clip may not be seamless (Default:false).
-
setDrmLicenseUri
public MediaItem.Builder setDrmLicenseUri(@Nullable Uri licenseUri)
Sets the optional default DRM license server URI. If this URI is set, theMediaItem.DrmConfiguration.uuidneeds to be specified as well.This method should only be called if both
setUri(java.lang.String)andsetDrmUuid(UUID)are passed non-null values.
-
setDrmLicenseUri
public MediaItem.Builder setDrmLicenseUri(@Nullable String licenseUri)
Sets the optional default DRM license server URI. If this URI is set, theMediaItem.DrmConfiguration.uuidneeds to be specified as well.This method should only be called if both
setUri(java.lang.String)andsetDrmUuid(UUID)are passed non-null values.
-
setDrmLicenseRequestHeaders
public MediaItem.Builder setDrmLicenseRequestHeaders(@Nullable Map<String,String> licenseRequestHeaders)
Sets the optional request headers attached to the DRM license request.nullor an emptyMapcan be used for a reset.This method should only be called if both
setUri(java.lang.String)andsetDrmUuid(UUID)are passed non-null values.
-
setDrmUuid
public MediaItem.Builder setDrmUuid(@Nullable UUID uuid)
Sets theUUIDof the protection scheme.If
uuidis null or unset then noMediaItem.DrmConfigurationobject is created duringbuild()and no otherBuildermethods that would populateMediaItem.PlaybackProperties.drmConfigurationshould be called.This method should only be called if
setUri(java.lang.String)is passed a non-null value.
-
setDrmMultiSession
public MediaItem.Builder setDrmMultiSession(boolean multiSession)
Sets whether the DRM configuration is multi session enabled.This method should only be called if both
setUri(java.lang.String)andsetDrmUuid(UUID)are passed non-null values.
-
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.This method should only be called if both
setUri(java.lang.String)andsetDrmUuid(UUID)are passed non-null values.
-
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.This method should only be called if both
setUri(java.lang.String)andsetDrmUuid(UUID)are passed non-null values.
-
setDrmSessionForClearPeriods
public MediaItem.Builder setDrmSessionForClearPeriods(boolean sessionForClearPeriods)
Sets whether a DRM session should be used for clear tracks of typeC.TRACK_TYPE_VIDEOandC.TRACK_TYPE_AUDIO.This method overrides what has been set by previously calling
setDrmSessionForClearTypes(List).This method should only be called if both
setUri(java.lang.String)andsetDrmUuid(UUID)are passed non-null values.
-
setDrmSessionForClearTypes
public MediaItem.Builder setDrmSessionForClearTypes(@Nullable List<Integer> sessionForClearTypes)
Sets a list ofC.TRACK_TYPE_*constants for which to use a DRM session even when the tracks are in the clear.For the common case of using a DRM session for
C.TRACK_TYPE_VIDEOandC.TRACK_TYPE_AUDIOthesetDrmSessionForClearPeriods(boolean)can be used.This method overrides what has been set by previously calling
setDrmSessionForClearPeriods(boolean).nullor an emptyListcan be used for a reset.This method should only be called if both
setUri(java.lang.String)andsetDrmUuid(UUID)are passed non-null values.
-
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)).This method should only be called if both
setUri(java.lang.String)andsetDrmUuid(UUID)are passed non-null values.
-
setStreamKeys
public MediaItem.Builder setStreamKeys(@Nullable List<StreamKey> streamKeys)
Sets the optional stream keys by which the manifest is filtered (only used for adaptive streams).nullor an emptyListcan be used for a reset.If
setUri(java.lang.String)is passed a non-nulluri, the stream keys are used to create aMediaItem.PlaybackPropertiesobject. Otherwise they will be ignored.
-
setCustomCacheKey
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
public MediaItem.Builder setSubtitles(@Nullable List<MediaItem.Subtitle> subtitles)
Sets the optional subtitles.nullor an emptyListcan be used for a reset.This method should only be called if
setUri(java.lang.String)is passed a non-null value.
-
setAdTagUri
public MediaItem.Builder setAdTagUri(@Nullable String adTagUri)
Sets the optional ad tagUri.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.
This method should only be called if
setUri(java.lang.String)is passed a non-null value.- Parameters:
adTagUri- The ad tag URI to load.
-
setAdTagUri
public MediaItem.Builder setAdTagUri(@Nullable Uri adTagUri)
Sets the optional ad tagUri.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.
This method should only be called if
setUri(java.lang.String)is passed a non-null value.- Parameters:
adTagUri- The ad tag URI to load.
-
setAdTagUri
public MediaItem.Builder setAdTagUri(@Nullable Uri adTagUri, @Nullable Object adsId)
Sets the optional ad tagUriand ads identifier.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.
This method should only be called if
setUri(java.lang.String)is passed a non-null value.- 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 (byequality) 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, orC.TIME_UNSETto 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, orC.TIME_UNSETto 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, orC.TIME_UNSETto 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, orC.RATE_UNSETto 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, orC.RATE_UNSETto 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 thecom.google.android.exoplayer2.Timelineof the source ascom.google.android.exoplayer2.Timeline.Window#tag.This method should only be called if
setUri(java.lang.String)is passed a non-null value.
-
setMediaMetadata
public MediaItem.Builder setMediaMetadata(MediaMetadata mediaMetadata)
Sets the media metadata.
-
-