MediaItem.Builder


public final class MediaItem.Builder


A builder for MediaItem instances.

Summary

Public constructors

Creates a builder.

Public methods

MediaItem

Returns a new MediaItem instance with the current builder values.

MediaItem.Builder

This method is deprecated.

Use setAdsConfiguration, parse the adTagUri with parse and pass the result to Builder instead.

MediaItem.Builder

This method is deprecated.

Use setAdsConfiguration and pass the adTagUri to Builder instead.

MediaItem.Builder

This method is deprecated.

Use setAdsConfiguration, pass the adTagUri to Builder and the adsId to setAdsId instead.

MediaItem.Builder

Sets the optional AdsConfiguration.

MediaItem.Builder

This method is deprecated.

Use setClippingConfiguration and setEndPositionMs instead.

MediaItem.Builder

This method is deprecated.

Use setClippingConfiguration and setRelativeToDefaultPosition instead.

MediaItem.Builder

This method is deprecated.

Use setClippingConfiguration and setRelativeToLiveWindow instead.

MediaItem.Builder

This method is deprecated.

Use setClippingConfiguration and setStartPositionMs instead.

MediaItem.Builder

This method is deprecated.

Use setClippingConfiguration and setStartsAtKeyFrame instead.

MediaItem.Builder

Sets the ClippingConfiguration, defaults to UNSET.

MediaItem.Builder

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

MediaItem.Builder

Sets the optional DRM configuration.

MediaItem.Builder

This method is deprecated.

Use setDrmConfiguration and setForceDefaultLicenseUri instead.

MediaItem.Builder

This method is deprecated.

Use setDrmConfiguration and setKeySetId instead.

MediaItem.Builder

This method is deprecated.

Use setDrmConfiguration and setLicenseRequestHeaders instead.

MediaItem.Builder

This method is deprecated.

Use setDrmConfiguration and setLicenseUri instead.

MediaItem.Builder

This method is deprecated.

Use setDrmConfiguration and setLicenseUri instead.

MediaItem.Builder

This method is deprecated.

Use setDrmConfiguration and setMultiSession instead.

MediaItem.Builder

This method is deprecated.

Use setDrmConfiguration and setPlayClearContentWithoutKey instead.

MediaItem.Builder

This method is deprecated.

Use setDrmConfiguration and setForceSessionsForAudioAndVideoTracks instead.

MediaItem.Builder

This method is deprecated.

Use setDrmConfiguration and setForcedSessionTrackTypes instead.

MediaItem.Builder

This method is deprecated.

Use setDrmConfiguration and pass the uuid to Builder instead.

MediaItem.Builder

Sets the image duration in video output, in milliseconds.

MediaItem.Builder

Sets the LiveConfiguration.

MediaItem.Builder

This method is deprecated.

Use setLiveConfiguration and setMaxOffsetMs.

MediaItem.Builder

This method is deprecated.

Use setLiveConfiguration and setMaxPlaybackSpeed.

MediaItem.Builder

This method is deprecated.

Use setLiveConfiguration and setMinOffsetMs.

MediaItem.Builder

This method is deprecated.

Use setLiveConfiguration and setMinPlaybackSpeed.

MediaItem.Builder

This method is deprecated.

Use setLiveConfiguration and setTargetOffsetMs.

MediaItem.Builder

Sets the optional media ID which identifies the media item.

MediaItem.Builder

Sets the media metadata.

MediaItem.Builder

Sets the optional MIME type.

MediaItem.Builder

Sets the request metadata.

MediaItem.Builder

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

MediaItem.Builder

Sets the optional subtitles.

MediaItem.Builder

This method is deprecated.

Use setSubtitleConfigurations instead.

MediaItem.Builder

Sets the optional tag for custom attributes.

MediaItem.Builder

Sets the optional URI.

MediaItem.Builder

Sets the optional URI.

Public constructors

Builder

public Builder()

Creates a builder.

Public methods

build

public MediaItem build()

Returns a new MediaItem instance with the current builder values.

setAdTagUri

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

setAdTagUri

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

setAdTagUri

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

setAdsConfiguration

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

Sets the optional AdsConfiguration.

This method should only be called if setUri is passed a non-null value.

setClipEndPositionMs

@CanIgnoreReturnValue
@UnstableApi
public MediaItem.Builder setClipEndPositionMs(long endPositionMs)

setClipRelativeToDefaultPosition

@CanIgnoreReturnValue
@UnstableApi
public MediaItem.Builder setClipRelativeToDefaultPosition(boolean relativeToDefaultPosition)

setClipRelativeToLiveWindow

@CanIgnoreReturnValue
@UnstableApi
public MediaItem.Builder setClipRelativeToLiveWindow(boolean relativeToLiveWindow)

setClipStartPositionMs

@CanIgnoreReturnValue
@UnstableApi
public MediaItem.Builder setClipStartPositionMs(@IntRange(from = 0) long startPositionMs)

setClipStartsAtKeyFrame

@CanIgnoreReturnValue
@UnstableApi
public MediaItem.Builder setClipStartsAtKeyFrame(boolean startsAtKeyFrame)

setClippingConfiguration

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

Sets the ClippingConfiguration, defaults to UNSET.

setCustomCacheKey

@CanIgnoreReturnValue
@UnstableApi
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 is passed a non-null value.

setDrmConfiguration

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

Sets the optional DRM configuration.

setDrmForceDefaultLicenseUri

@CanIgnoreReturnValue
@UnstableApi
public MediaItem.Builder setDrmForceDefaultLicenseUri(boolean forceDefaultLicenseUri)

setDrmKeySetId

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

setDrmLicenseRequestHeaders

@CanIgnoreReturnValue
@UnstableApi
public MediaItem.Builder setDrmLicenseRequestHeaders(
    @Nullable Map<StringString> licenseRequestHeaders
)

setDrmLicenseUri

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

setDrmLicenseUri

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

setDrmMultiSession

@CanIgnoreReturnValue
@UnstableApi
public MediaItem.Builder setDrmMultiSession(boolean multiSession)

setDrmPlayClearContentWithoutKey

@CanIgnoreReturnValue
@UnstableApi
public MediaItem.Builder setDrmPlayClearContentWithoutKey(boolean playClearContentWithoutKey)

setDrmSessionForClearPeriods

@CanIgnoreReturnValue
@UnstableApi
public MediaItem.Builder setDrmSessionForClearPeriods(boolean sessionForClearPeriods)

setDrmSessionForClearTypes

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

setDrmUuid

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

setImageDurationMs

@CanIgnoreReturnValue
@UnstableApi
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 TIME_UNSET.

setLiveConfiguration

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

Sets the LiveConfiguration. Defaults to UNSET.

setLiveMaxOffsetMs

@CanIgnoreReturnValue
@UnstableApi
public MediaItem.Builder setLiveMaxOffsetMs(long liveMaxOffsetMs)

setLiveMaxPlaybackSpeed

@CanIgnoreReturnValue
@UnstableApi
public MediaItem.Builder setLiveMaxPlaybackSpeed(float maxPlaybackSpeed)

setLiveMinOffsetMs

@CanIgnoreReturnValue
@UnstableApi
public MediaItem.Builder setLiveMinOffsetMs(long liveMinOffsetMs)

setLiveMinPlaybackSpeed

@CanIgnoreReturnValue
@UnstableApi
public MediaItem.Builder setLiveMinPlaybackSpeed(float minPlaybackSpeed)

setLiveTargetOffsetMs

@CanIgnoreReturnValue
@UnstableApi
public MediaItem.Builder setLiveTargetOffsetMs(long liveTargetOffsetMs)

setMediaId

@CanIgnoreReturnValue
public MediaItem.Builder setMediaId(String mediaId)

Sets the optional media ID which identifies the media item.

By default DEFAULT_MEDIA_ID is used.

setMediaMetadata

@CanIgnoreReturnValue
public MediaItem.Builder setMediaMetadata(MediaMetadata mediaMetadata)

Sets the media metadata.

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 is passed a non-null value.

Parameters
@Nullable String mimeType

The MIME type.

setRequestMetadata

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

Sets the request metadata.

setStreamKeys

@CanIgnoreReturnValue
@UnstableApi
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 is passed a non-null uri, the stream keys are used to create a LocalConfiguration object. Otherwise they will be ignored.

setSubtitleConfigurations

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

Sets the optional subtitles.

This method should only be called if setUri is passed a non-null value.

setSubtitles

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

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 androidx.media3.common.Timeline of the source as androidx.media3.common.Timeline.Window#tag.

This method should only be called if setUri is passed a non-null value.

setUri

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

Sets the optional URI.

If uri is null or unset then no LocalConfiguration object is created during build and no other Builder methods that would populate 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 LocalConfiguration object is created during build and no other Builder methods that would populate localConfiguration should be called.