# MediaStoreOutputOptions.Builder

Artifact: [androidx.camera:camera-video](https://developer.android.com/jetpack/androidx/releases/camera) [View Source](https://cs.android.com/search?q=file:androidx/camera/video/MediaStoreOutputOptions.java+class:androidx.camera.video.MediaStoreOutputOptions.Builder) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/camera#1.1.0)

*** ** * ** ***


```
public final class MediaStoreOutputOptions.Builder
```

<br />

*** ** * ** ***

The builder of the `https://developer.android.com/reference/androidx/camera/video/MediaStoreOutputOptions` object.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/camera/video/MediaStoreOutputOptions.Builder#Builder(android.content.ContentResolver,android.net.Uri)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/ContentResolver.html contentResolver, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/net/Uri.html collectionUri )` Creates a builder of the `https://developer.android.com/reference/androidx/camera/video/MediaStoreOutputOptions` with media store options. |

| ### Public methods |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/video/MediaStoreOutputOptions` | `https://developer.android.com/reference/androidx/camera/video/MediaStoreOutputOptions.Builder#build()()` Builds the `https://developer.android.com/reference/androidx/camera/video/MediaStoreOutputOptions` instance. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/video/MediaStoreOutputOptions.Builder` | `https://developer.android.com/reference/androidx/camera/video/MediaStoreOutputOptions.Builder#setContentValues(android.content.ContentValues)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/ContentValues.html contentValues)` Sets the content values to be included in the created video row. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html B` | `https://developer.android.com/reference/androidx/camera/video/MediaStoreOutputOptions.Builder#setDurationLimitMillis(long)(@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) long durationLimitMillis)` Sets the limit for the video duration in milliseconds. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html B` | `https://developer.android.com/reference/androidx/camera/video/MediaStoreOutputOptions.Builder#setFileSizeLimit(long)(@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) long fileSizeLimitBytes)` Sets the limit for the file length in bytes. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html B` | `https://developer.android.com/reference/androidx/camera/video/MediaStoreOutputOptions.Builder#setLocation(android.location.Location)(@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/location/Location.html location)` Sets a `https://developer.android.com/reference/android/location/Location.html` object representing a geographic location where the video was recorded. |

## Public constructors

### Builder

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/camera#1.1.0)

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

Creates a builder of the `https://developer.android.com/reference/androidx/camera/video/MediaStoreOutputOptions` with media store options.

The ContentResolver can be obtained by app `https://developer.android.com/reference/android/content/Context.html#getContentResolver()` and is used to access to MediaStore.

`https://developer.android.com/reference/android/provider/MediaStore.html` 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 `https://developer.android.com/reference/android/provider/MediaStore.Video.Media.html#EXTERNAL_CONTENT_URI`. `https://developer.android.com/reference/android/provider/MediaStore.Video.Media.html#getContentUri(java.lang.String)` can also be used to query different storage volumes. For more information, read [Access media files from shared storage](https://developer.android.com/training/data-storage/shared/media) developer guide.

When recording a video, a corresponding video row will be created in the input collection, and the content values set by `https://developer.android.com/reference/androidx/camera/video/MediaStoreOutputOptions.Builder#setContentValues(android.content.ContentValues)` will also be written to this row.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/ContentResolver.html contentResolver` | the ContentResolver instance. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/net/Uri.html collectionUri` | the URI of the collection to insert into. |

## Public methods

### build

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/camera#1.1.0)

```
public @NonNull MediaStoreOutputOptions build()
```

Builds the `https://developer.android.com/reference/androidx/camera/video/MediaStoreOutputOptions` instance.

### setContentValues

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/camera#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 `https://developer.android.com/reference/android/provider/MediaStore.MediaColumns.html` and `https://developer.android.com/reference/android/provider/MediaStore.Video.VideoColumns.html`. 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 `https://developer.android.com/reference/androidx/camera/video/MediaStoreOutputOptions#EMPTY_CONTENT_VALUES()`.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/ContentValues.html contentValues` | the content values to be inserted. |

### setDurationLimitMillis

Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/camera#1.3.0)

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

Sets the limit for the video duration in milliseconds.

When used to generate recording with `https://developer.android.com/reference/androidx/camera/video/Recorder`, if the specified duration limit is reached while the recording is being recorded, the recording will be finalized with `https://developer.android.com/reference/androidx/camera/video/VideoRecordEvent.Finalize#ERROR_DURATION_LIMIT_REACHED()`.

If not set or set with zero, the duration will be `https://developer.android.com/reference/androidx/camera/video/OutputOptions#DURATION_UNLIMITED()`. If set with a negative value, an `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` will be thrown.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) long durationLimitMillis` | the video duration limit in milliseconds. |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html B` | this Builder. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if the specified duration limit is negative. |

### setFileSizeLimit

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/camera#1.1.0)

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

Sets the limit for the file length in bytes.

When used with `https://developer.android.com/reference/androidx/camera/video/Recorder` to generate recording, if the specified file size limit is reached while the recording is being recorded, the recording will be finalized with `https://developer.android.com/reference/androidx/camera/video/VideoRecordEvent.Finalize#ERROR_FILE_SIZE_LIMIT_REACHED()`.

If not set or set with zero, the file size will be `https://developer.android.com/reference/androidx/camera/video/OutputOptions#FILE_SIZE_UNLIMITED()`. If set with a negative value, an `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` will be thrown.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) long fileSizeLimitBytes` | the file size limit in bytes. |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html B` | this Builder. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if the specified file size limit is negative. |

### setLocation

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/camera#1.2.0)

```
public @NonNull B setLocation(@Nullable Location location)
```

Sets a `https://developer.android.com/reference/android/location/Location.html` object representing a geographic location where the video was recorded.

When used with `https://developer.android.com/reference/androidx/camera/video/Recorder`, only the latitude and longitude from the `https://developer.android.com/reference/android/location/Location.html` are stored in the udta box if the output format is MP4, and are ignored for other formats. Other location data (such as altitude) is not stored. The geographic location is stored according to the ISO-6709 standard.

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

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/location/Location.html location` | the location object, or `null` if no location should be saved. |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html B` | this Builder. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | 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]`. |