MediaStoreOutputOptions.Builder


public final class MediaStoreOutputOptions.Builder


The builder of the MediaStoreOutputOptions object.

Summary

Public constructors

Builder(
    @NonNull ContentResolver contentResolver,
    @NonNull Uri collectionUri
)

Creates a builder of the MediaStoreOutputOptions with media store options.

Public methods

@NonNull MediaStoreOutputOptions

Builds the MediaStoreOutputOptions instance.

@NonNull MediaStoreOutputOptions.Builder

Sets the content values to be included in the created video row.

@NonNull B
setDurationLimitMillis(@IntRange(from = 0) long durationLimitMillis)

Sets the limit for the video duration in milliseconds.

@NonNull B
setFileSizeLimit(@IntRange(from = 0) long fileSizeLimitBytes)

Sets the limit for the file length in bytes.

@NonNull B

Sets a Location object representing a geographic location where the video was recorded.

Public constructors

Builder

Added in 1.1.0
public Builder(
    @NonNull ContentResolver contentResolver,
    @NonNull Uri collectionUri
)

Creates a builder of the MediaStoreOutputOptions with media store options.

The ContentResolver can be obtained by app context and is used to access to MediaStore.

MediaStore class provides APIs to obtain the collection URI. A collection URI corresponds to a storage volume on the device shared storage. A common collection URI used to access the primary external storage is EXTERNAL_CONTENT_URI. getContentUri can also be used to query different storage volumes. For more information, read Access media files from shared storage developer guide.

When recording a video, a corresponding video row will be created in the input collection, and the content values set by setContentValues will also be written to this row.

Parameters
@NonNull ContentResolver contentResolver

the ContentResolver instance.

@NonNull Uri collectionUri

the URI of the collection to insert into.

Public methods

build

Added in 1.1.0
public @NonNull MediaStoreOutputOptions build()

Builds the MediaStoreOutputOptions instance.

setContentValues

Added in 1.1.0
public @NonNull MediaStoreOutputOptions.Builder setContentValues(@NonNull ContentValues contentValues)

Sets the content values to be included in the created video row.

The content values is a set of key/value paris used to store the metadata of a video item. The keys are defined in MediaStore.MediaColumns and MediaStore.Video.VideoColumns. When recording a video, a corresponding video row will be created in the input collection, and this content values will also be written to this row. If a key is not defined in the MediaStore, the corresponding value will be ignored.

If not set, defaults to EMPTY_CONTENT_VALUES.

Parameters
@NonNull ContentValues contentValues

the content values to be inserted.

setDurationLimitMillis

Added in 1.3.0
public @NonNullsetDurationLimitMillis(@IntRange(from = 0) long durationLimitMillis)

Sets the limit for the video duration in milliseconds.

When used to generate recording with Recorder, if the specified duration limit is reached while the recording is being recorded, the recording will be finalized with ERROR_DURATION_LIMIT_REACHED.

If not set or set with zero, the duration will be unlimited. If set with a negative value, an IllegalArgumentException will be thrown.

Parameters
@IntRange(from = 0) long durationLimitMillis

the video duration limit in milliseconds.

Returns
@NonNull B

this Builder.

Throws
java.lang.IllegalArgumentException

if the specified duration limit is negative.

setFileSizeLimit

Added in 1.1.0
public @NonNullsetFileSizeLimit(@IntRange(from = 0) long fileSizeLimitBytes)

Sets the limit for the file length in bytes.

When used with Recorder to generate recording, if the specified file size limit is reached while the recording is being recorded, the recording will be finalized with ERROR_FILE_SIZE_LIMIT_REACHED.

If not set or set with zero, the file size will be unlimited. If set with a negative value, an IllegalArgumentException will be thrown.

Parameters
@IntRange(from = 0) long fileSizeLimitBytes

the file size limit in bytes.

Returns
@NonNull B

this Builder.

Throws
java.lang.IllegalArgumentException

if the specified file size limit is negative.

setLocation

Added in 1.2.0
public @NonNullsetLocation(@Nullable Location location)

Sets a Location object representing a geographic location where the video was recorded.

When use with Recorder, the geographic location is stored in udta box if the output format is MP4, and is ignored for other formats. The geographic location is stored according to ISO-6709 standard.

If null, no location information will be saved with the video. Default value is null.

Throws
java.lang.IllegalArgumentException

if the latitude of the location is not in the range [-90, 90] or the longitude of the location is not in the range [-180, 180].