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 MediaItem
build()
Returns a newMediaItem
instance with the current builder values.MediaItem.Builder
setAdTagUri(Uri adTagUri)
Sets the optional ad tagUri
.MediaItem.Builder
setAdTagUri(Uri adTagUri, Object adsId)
Sets the optional ad tagUri
and ads identifier.MediaItem.Builder
setAdTagUri(String adTagUri)
Sets the optional ad tagUri
.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_SOURCE
to end when playback reaches the end of media (Default:C.TIME_END_OF_SOURCE
).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
).MediaItem.Builder
setClipRelativeToLiveWindow(boolean relativeToLiveWindow)
Sets whether the start/end positions should move with the live window for live streams.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).MediaItem.Builder
setClipStartsAtKeyFrame(boolean startsAtKeyFrame)
Sets whether the start point is guaranteed to be a key frame.MediaItem.Builder
setCustomCacheKey(String customCacheKey)
Sets the optional custom cache key (only used for progressive streams).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.MediaItem.Builder
setDrmKeySetId(byte[] keySetId)
Sets the key set ID of the offline license.MediaItem.Builder
setDrmLicenseRequestHeaders(Map<String,String> licenseRequestHeaders)
Sets the optional request headers attached to the DRM license request.MediaItem.Builder
setDrmLicenseUri(Uri licenseUri)
Sets the optional default DRM license server URI.MediaItem.Builder
setDrmLicenseUri(String licenseUri)
Sets the optional default DRM license server URI.MediaItem.Builder
setDrmMultiSession(boolean multiSession)
Sets whether the DRM configuration is multi session enabled.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.MediaItem.Builder
setDrmSessionForClearPeriods(boolean sessionForClearPeriods)
Sets whether a DRM session should be used for clear tracks of typeC.TRACK_TYPE_VIDEO
andC.TRACK_TYPE_AUDIO
.MediaItem.Builder
setDrmSessionForClearTypes(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.Builder
setDrmUuid(UUID uuid)
Sets theUUID
of the protection scheme.MediaItem.Builder
setLiveMaxOffsetMs(long liveMaxOffsetMs)
Sets the optional maximum offset from the live edge for live streams, in milliseconds.MediaItem.Builder
setLiveMaxPlaybackSpeed(float maxPlaybackSpeed)
Sets the optional maximum playback speed for live stream speed adjustment.MediaItem.Builder
setLiveMinOffsetMs(long liveMinOffsetMs)
Sets the optional minimum offset from the live edge for live streams, in milliseconds.MediaItem.Builder
setLiveMinPlaybackSpeed(float minPlaybackSpeed)
Sets the optional minimum playback speed for live stream speed adjustment.MediaItem.Builder
setLiveTargetOffsetMs(long liveTargetOffsetMs)
Sets the optional target offset from the live edge for live streams, in milliseconds.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
setStreamKeys(List<StreamKey> streamKeys)
Sets the optional stream keys by which the manifest is filtered (only used for adaptive streams).MediaItem.Builder
setSubtitles(List<MediaItem.Subtitle> subtitles)
Sets the optional subtitles.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.
-
-
-
Method Detail
-
setMediaId
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
public MediaItem.Builder setUri(@Nullable String uri)
Sets the optional URI.If
uri
is null or unset noMediaItem.PlaybackProperties
object is created duringbuild()
and any otherBuilder
methods that would populateMediaItem.playbackProperties
are ignored.
-
setUri
public MediaItem.Builder setUri(@Nullable Uri uri)
Sets the optional URI.If
uri
is null or unset noMediaItem.PlaybackProperties
object is created duringbuild()
and any otherBuilder
methods that would populateMediaItem.playbackProperties
are ignored.
-
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-nulluri
, the MIME type is used to create aMediaItem.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, orC.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. 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.uuid
needs to be specified as well.If
setUri(java.lang.String)
is passed a non-nulluri
, the DRM license server URI is used to create aMediaItem.PlaybackProperties
object. Otherwise it will be ignored.
-
setDrmLicenseUri
public MediaItem.Builder setDrmLicenseUri(@Nullable String licenseUri)
Sets the optional default DRM license server URI. If this URI is set, theMediaItem.DrmConfiguration.uuid
needs to be specified as well.If
setUri(java.lang.String)
is passed a non-nulluri
, the DRM license server URI is used to create aMediaItem.PlaybackProperties
object. Otherwise it will be ignored.
-
setDrmLicenseRequestHeaders
public MediaItem.Builder setDrmLicenseRequestHeaders(@Nullable Map<String,String> licenseRequestHeaders)
Sets the optional request headers attached to the DRM license request.null
or an emptyMap
can be used for a reset.If no valid DRM configuration is specified, the DRM license request headers are ignored.
-
setDrmUuid
public MediaItem.Builder setDrmUuid(@Nullable UUID uuid)
Sets theUUID
of the protection scheme. If a DRM system UUID is set, theMediaItem.DrmConfiguration.licenseUri
needs to be set as well.If
setUri(java.lang.String)
is passed a non-nulluri
, the DRM system UUID is used to create aMediaItem.PlaybackProperties
object. Otherwise it will be ignored.
-
setDrmMultiSession
public MediaItem.Builder setDrmMultiSession(boolean multiSession)
Sets whether the DRM configuration is multi session enabled.If
setUri(java.lang.String)
is passed a non-nulluri
, the DRM multi session flag is used to create aMediaItem.PlaybackProperties
object. Otherwise it will be 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-nulluri
, the DRM force default license flag is used to create aMediaItem.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.
-
setDrmSessionForClearPeriods
public MediaItem.Builder setDrmSessionForClearPeriods(boolean sessionForClearPeriods)
Sets whether a DRM session should be used for clear tracks of typeC.TRACK_TYPE_VIDEO
andC.TRACK_TYPE_AUDIO
.This method overrides what has been set by previously calling
setDrmSessionForClearTypes(List)
.
-
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_VIDEO
andC.TRACK_TYPE_AUDIO
thesetDrmSessionForClearPeriods(boolean)
can be used.This method overrides what has been set by previously calling
setDrmSessionForClearPeriods(boolean)
.null
or an emptyList
can be used for a reset.
-
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.
-
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).null
or an emptyList
can be used for a reset.If
setUri(java.lang.String)
is passed a non-nulluri
, the stream keys are used to create aMediaItem.PlaybackProperties
object. Otherwise they will be ignored.
-
setCustomCacheKey
public MediaItem.Builder setCustomCacheKey(@Nullable String customCacheKey)
Sets the optional custom cache key (only used for progressive streams).If
setUri(java.lang.String)
is passed a non-nulluri
, the custom cache key is used to create aMediaItem.PlaybackProperties
object. Otherwise it will be ignored.
-
setSubtitles
public MediaItem.Builder setSubtitles(@Nullable List<MediaItem.Subtitle> subtitles)
Sets the optional subtitles.null
or an emptyList
can be used for a reset.If
setUri(java.lang.String)
is passed a non-nulluri
, the subtitles are used to create aMediaItem.PlaybackProperties
object. Otherwise they will be ignored.
-
setAdTagUri
public MediaItem.Builder setAdTagUri(@Nullable String adTagUri)
Sets the optional ad tagUri
.If
setUri(java.lang.String)
is passed a non-nulluri
, the ad tag URI is used to create aMediaItem.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 tagUri
.If
setUri(java.lang.String)
is passed a non-nulluri
, the ad tag URI is used to create aMediaItem.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 tagUri
and ads identifier.If
setUri(java.lang.String)
is passed a non-nulluri
, the ad tag URI is used to create aMediaItem.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 (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_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, orC.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, orC.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, orC.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, orC.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 thecom.google.android.exoplayer2.Timeline
of the source ascom.google.android.exoplayer2.Timeline.Window#tag
.If
setUri(java.lang.String)
is passed a non-nulluri
, the tag is used to create aMediaItem.PlaybackProperties
object. Otherwise it will be ignored.
-
setMediaMetadata
public MediaItem.Builder setMediaMetadata(MediaMetadata mediaMetadata)
Sets the media metadata.
-
-