public final class

MediaItem.Builder

extends java.lang.Object

 java.lang.Object

↳androidx.media3.common.MediaItem.Builder

Overview

A builder for MediaItem instances.

Summary

Constructors
publicBuilder()

Creates a builder.

Methods
public MediaItembuild()

Returns a new MediaItem instance with the current builder values.

public MediaItem.BuildersetAdsConfiguration(MediaItem.AdsConfiguration adsConfiguration)

Sets the optional MediaItem.AdsConfiguration.

public MediaItem.BuildersetAdTagUri(java.lang.String adTagUri)

public MediaItem.BuildersetAdTagUri(Uri adTagUri)

public MediaItem.BuildersetAdTagUri(Uri adTagUri, java.lang.Object adsId)

public MediaItem.BuildersetClipEndPositionMs(long endPositionMs)

public MediaItem.BuildersetClippingConfiguration(MediaItem.ClippingConfiguration clippingConfiguration)

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

public MediaItem.BuildersetClipRelativeToDefaultPosition(boolean relativeToDefaultPosition)

public MediaItem.BuildersetClipRelativeToLiveWindow(boolean relativeToLiveWindow)

public MediaItem.BuildersetClipStartPositionMs(long startPositionMs)

public MediaItem.BuildersetClipStartsAtKeyFrame(boolean startsAtKeyFrame)

public MediaItem.BuildersetCustomCacheKey(java.lang.String customCacheKey)

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

public MediaItem.BuildersetDrmConfiguration(MediaItem.DrmConfiguration drmConfiguration)

Sets the optional DRM configuration.

public MediaItem.BuildersetDrmForceDefaultLicenseUri(boolean forceDefaultLicenseUri)

public MediaItem.BuildersetDrmKeySetId(byte[] keySetId[])

public MediaItem.BuildersetDrmLicenseRequestHeaders(java.util.Map<java.lang.String, java.lang.String> licenseRequestHeaders)

public MediaItem.BuildersetDrmLicenseUri(Uri licenseUri)

public MediaItem.BuildersetDrmMultiSession(boolean multiSession)

public MediaItem.BuildersetDrmPlayClearContentWithoutKey(boolean playClearContentWithoutKey)

public MediaItem.BuildersetDrmSessionForClearPeriods(boolean sessionForClearPeriods)

public MediaItem.BuildersetDrmSessionForClearTypes(java.util.List<java.lang.Integer> sessionForClearTypes)

public MediaItem.BuildersetDrmUuid(java.util.UUID uuid)

public MediaItem.BuildersetImageDurationMs(long imageDurationMs)

Sets the image duration in video output, in milliseconds.

public MediaItem.BuildersetLiveConfiguration(MediaItem.LiveConfiguration liveConfiguration)

Sets the MediaItem.LiveConfiguration.

public MediaItem.BuildersetLiveMaxOffsetMs(long liveMaxOffsetMs)

public MediaItem.BuildersetLiveMaxPlaybackSpeed(float maxPlaybackSpeed)

public MediaItem.BuildersetLiveMinOffsetMs(long liveMinOffsetMs)

public MediaItem.BuildersetLiveMinPlaybackSpeed(float minPlaybackSpeed)

public MediaItem.BuildersetLiveTargetOffsetMs(long liveTargetOffsetMs)

public MediaItem.BuildersetMediaId(java.lang.String mediaId)

Sets the optional media ID which identifies the media item.

public MediaItem.BuildersetMediaMetadata(MediaMetadata mediaMetadata)

Sets the media metadata.

public MediaItem.BuildersetMimeType(java.lang.String mimeType)

Sets the optional MIME type.

public MediaItem.BuildersetRequestMetadata(MediaItem.RequestMetadata requestMetadata)

Sets the request metadata.

public MediaItem.BuildersetStreamKeys(java.util.List<StreamKey> streamKeys)

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

public MediaItem.BuildersetSubtitleConfigurations(java.util.List<MediaItem.SubtitleConfiguration> subtitleConfigurations)

Sets the optional subtitles.

public MediaItem.BuildersetSubtitles(java.util.List<MediaItem.Subtitle> subtitles)

public MediaItem.BuildersetTag(java.lang.Object tag)

Sets the optional tag for custom attributes.

public MediaItem.BuildersetUri(java.lang.String uri)

Sets the optional URI.

public MediaItem.BuildersetUri(Uri uri)

Sets the optional URI.

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public Builder()

Creates a builder.

Methods

public MediaItem.Builder setMediaId(java.lang.String mediaId)

Sets the optional media ID which identifies the media item.

By default MediaItem.DEFAULT_MEDIA_ID is used.

public MediaItem.Builder setUri(java.lang.String uri)

Sets the optional URI.

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

public MediaItem.Builder setUri(Uri uri)

Sets the optional URI.

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

public MediaItem.Builder setMimeType(java.lang.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 MediaItem.Builder.setUri(String) is passed a non-null value.

Parameters:

mimeType: The MIME type.

public MediaItem.Builder setClippingConfiguration(MediaItem.ClippingConfiguration clippingConfiguration)

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

public MediaItem.Builder setClipStartPositionMs(long startPositionMs)

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

public MediaItem.Builder setClipEndPositionMs(long endPositionMs)

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

public MediaItem.Builder setClipRelativeToLiveWindow(boolean relativeToLiveWindow)

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

public MediaItem.Builder setClipRelativeToDefaultPosition(boolean relativeToDefaultPosition)

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

public MediaItem.Builder setClipStartsAtKeyFrame(boolean startsAtKeyFrame)

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

public MediaItem.Builder setDrmConfiguration(MediaItem.DrmConfiguration drmConfiguration)

Sets the optional DRM configuration.

public MediaItem.Builder setDrmLicenseUri(Uri licenseUri)

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

public MediaItem.Builder setDrmLicenseRequestHeaders(java.util.Map<java.lang.String, java.lang.String> licenseRequestHeaders)

Deprecated: Use MediaItem.Builder 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.

public MediaItem.Builder setDrmUuid(java.util.UUID uuid)

Deprecated: Use MediaItem.Builder and pass the uuid to MediaItem.DrmConfiguration.Builder.Builder(UUID) instead.

public MediaItem.Builder setDrmMultiSession(boolean multiSession)

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

public MediaItem.Builder setDrmForceDefaultLicenseUri(boolean forceDefaultLicenseUri)

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

public MediaItem.Builder setDrmPlayClearContentWithoutKey(boolean playClearContentWithoutKey)

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

public MediaItem.Builder setDrmSessionForClearPeriods(boolean sessionForClearPeriods)

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

public MediaItem.Builder setDrmSessionForClearTypes(java.util.List<java.lang.Integer> sessionForClearTypes)

Deprecated: Use MediaItem.Builder 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.

public MediaItem.Builder setDrmKeySetId(byte[] keySetId[])

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

public MediaItem.Builder setStreamKeys(java.util.List<StreamKey> streamKeys)

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

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

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

public MediaItem.Builder setCustomCacheKey(java.lang.String customCacheKey)

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

This method should only be called if MediaItem.Builder.setUri(String) is passed a non-null value.

public MediaItem.Builder setSubtitles(java.util.List<MediaItem.Subtitle> subtitles)

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

public MediaItem.Builder setSubtitleConfigurations(java.util.List<MediaItem.SubtitleConfiguration> subtitleConfigurations)

Sets the optional subtitles.

This method should only be called if MediaItem.Builder.setUri(String) is passed a non-null value.

public MediaItem.Builder setAdsConfiguration(MediaItem.AdsConfiguration adsConfiguration)

Sets the optional MediaItem.AdsConfiguration.

This method should only be called if MediaItem.Builder.setUri(String) is passed a non-null value.

public MediaItem.Builder setAdTagUri(java.lang.String adTagUri)

Deprecated: Use MediaItem.Builder, parse the adTagUri with and pass the result to MediaItem.AdsConfiguration.Builder.Builder(Uri) instead.

public MediaItem.Builder setAdTagUri(Uri adTagUri)

Deprecated: Use MediaItem.Builder and pass the adTagUri to MediaItem.AdsConfiguration.Builder.Builder(Uri) instead.

public MediaItem.Builder setAdTagUri(Uri adTagUri, java.lang.Object adsId)

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

public MediaItem.Builder setLiveConfiguration(MediaItem.LiveConfiguration liveConfiguration)

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

public MediaItem.Builder setLiveTargetOffsetMs(long liveTargetOffsetMs)

Deprecated: Use MediaItem.Builder and MediaItem.LiveConfiguration.Builder.setTargetOffsetMs(long).

public MediaItem.Builder setLiveMinOffsetMs(long liveMinOffsetMs)

Deprecated: Use MediaItem.Builder and MediaItem.LiveConfiguration.Builder.setMinOffsetMs(long).

public MediaItem.Builder setLiveMaxOffsetMs(long liveMaxOffsetMs)

Deprecated: Use MediaItem.Builder and MediaItem.LiveConfiguration.Builder.setMaxOffsetMs(long).

public MediaItem.Builder setLiveMinPlaybackSpeed(float minPlaybackSpeed)

Deprecated: Use MediaItem.Builder and MediaItem.LiveConfiguration.Builder.setMinPlaybackSpeed(float).

public MediaItem.Builder setLiveMaxPlaybackSpeed(float maxPlaybackSpeed)

Deprecated: Use MediaItem.Builder and MediaItem.LiveConfiguration.Builder.setMaxPlaybackSpeed(float).

public MediaItem.Builder setTag(java.lang.Object tag)

Sets the optional tag for custom attributes. The tag for the media source which will be published in the androidx.media3.common.Timeline of the source as androidx.media3.common.Timeline.Window#tag.

This method should only be called if MediaItem.Builder.setUri(String) is passed a non-null value.

public MediaItem.Builder setImageDurationMs(long imageDurationMs)

Sets the image duration in video output, in milliseconds.

Must be set if the URI is set and resolves to an image. Ignored otherwise.

Motion photos will be rendered as images if this parameter is set, and as videos otherwise.

Default value is C.TIME_UNSET.

public MediaItem.Builder setMediaMetadata(MediaMetadata mediaMetadata)

Sets the media metadata.

public MediaItem.Builder setRequestMetadata(MediaItem.RequestMetadata requestMetadata)

Sets the request metadata.

public MediaItem build()

Returns a new MediaItem instance with the current builder values.