# MediaItem.SubtitleConfiguration.Builder

Artifact: [androidx.media3:media3-common](https://developer.android.com/jetpack/androidx/releases/media3) [View Source](https://cs.android.com/search?q=file:androidx/media3/common/MediaItem.java+class:androidx.media3.common.MediaItem.SubtitleConfiguration.Builder)

*** ** * ** ***


```
public final class MediaItem.SubtitleConfiguration.Builder
```

<br />

*** ** * ** ***

Builder for `https://developer.android.com/reference/androidx/media3/common/MediaItem.SubtitleConfiguration` instances.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/media3/common/MediaItem.SubtitleConfiguration.Builder#Builder(android.net.Uri)(https://developer.android.com/reference/android/net/Uri.html uri)` Constructs an instance. |

| ### Public methods |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/MediaItem.SubtitleConfiguration` | `https://developer.android.com/reference/androidx/media3/common/MediaItem.SubtitleConfiguration.Builder#build()()` Creates a `https://developer.android.com/reference/androidx/media3/common/MediaItem.SubtitleConfiguration` from the values of this builder. |
| `https://developer.android.com/reference/androidx/media3/common/MediaItem.SubtitleConfiguration.Builder` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developer.android.com/reference/androidx/media3/common/MediaItem.SubtitleConfiguration.Builder#setId(java.lang.String)(@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/String.html id)` Sets the optional ID for this subtitle track. |
| `https://developer.android.com/reference/androidx/media3/common/MediaItem.SubtitleConfiguration.Builder` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developer.android.com/reference/androidx/media3/common/MediaItem.SubtitleConfiguration.Builder#setLabel(java.lang.String)(@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/String.html label)` Sets the optional label for this subtitle track. |
| `https://developer.android.com/reference/androidx/media3/common/MediaItem.SubtitleConfiguration.Builder` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developer.android.com/reference/androidx/media3/common/MediaItem.SubtitleConfiguration.Builder#setLanguage(java.lang.String)(@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/String.html language)` Sets the optional language of the subtitle file. |
| `https://developer.android.com/reference/androidx/media3/common/MediaItem.SubtitleConfiguration.Builder` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developer.android.com/reference/androidx/media3/common/MediaItem.SubtitleConfiguration.Builder#setMimeType(java.lang.String)(@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/String.html mimeType)` Sets the MIME type. |
| `https://developer.android.com/reference/androidx/media3/common/MediaItem.SubtitleConfiguration.Builder` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developer.android.com/reference/androidx/media3/common/MediaItem.SubtitleConfiguration.Builder#setRoleFlags(int)(@https://developer.android.com/reference/androidx/media3/common/C.RoleFlags int roleFlags)` Sets the role flags. |
| `https://developer.android.com/reference/androidx/media3/common/MediaItem.SubtitleConfiguration.Builder` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developer.android.com/reference/androidx/media3/common/MediaItem.SubtitleConfiguration.Builder#setSelectionFlags(int)(@https://developer.android.com/reference/androidx/media3/common/C.SelectionFlags int selectionFlags)` Sets the flags used for track selection. |
| `https://developer.android.com/reference/androidx/media3/common/MediaItem.SubtitleConfiguration.Builder` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html @https://developer.android.com/reference/androidx/media3/common/util/UnstableApi https://developer.android.com/reference/androidx/media3/common/MediaItem.SubtitleConfiguration.Builder#setTimeOffsetUs(long)(long timeOffsetUs)` Sets the offset that is added to the timestamps of the cues in this subtitle track, in microseconds. |
| `https://developer.android.com/reference/androidx/media3/common/MediaItem.SubtitleConfiguration.Builder` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developer.android.com/reference/androidx/media3/common/MediaItem.SubtitleConfiguration.Builder#setUri(android.net.Uri)(https://developer.android.com/reference/android/net/Uri.html uri)` Sets the `https://developer.android.com/reference/android/net/Uri.html` to the subtitle file. |

## Public constructors

### Builder

```
public Builder(Uri uri)
```

Constructs an instance.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/net/Uri.html uri` | The `https://developer.android.com/reference/android/net/Uri.html` to the subtitle file. |

## Public methods

### build

```
public MediaItem.SubtitleConfiguration build()
```

Creates a `https://developer.android.com/reference/androidx/media3/common/MediaItem.SubtitleConfiguration` from the values of this builder.

### setId

```
@CanIgnoreReturnValue
public MediaItem.SubtitleConfiguration.Builder setId(@Nullable String id)
```

Sets the optional ID for this subtitle track.

### setLabel

```
@CanIgnoreReturnValue
public MediaItem.SubtitleConfiguration.Builder setLabel(@Nullable String label)
```

Sets the optional label for this subtitle track.

### setLanguage

```
@CanIgnoreReturnValue
public MediaItem.SubtitleConfiguration.Builder setLanguage(@Nullable String language)
```

Sets the optional language of the subtitle file.

### setMimeType

```
@CanIgnoreReturnValue
public MediaItem.SubtitleConfiguration.Builder setMimeType(@Nullable String mimeType)
```

Sets the MIME type.

### setRoleFlags

```
@CanIgnoreReturnValue
public MediaItem.SubtitleConfiguration.Builder setRoleFlags(@C.RoleFlags int roleFlags)
```

Sets the role flags. These are used for track selection.

### setSelectionFlags

```
@CanIgnoreReturnValue
public MediaItem.SubtitleConfiguration.Builder setSelectionFlags(@C.SelectionFlags int selectionFlags)
```

Sets the flags used for track selection.

### setTimeOffsetUs

```
@CanIgnoreReturnValue
@UnstableApi
public MediaItem.SubtitleConfiguration.Builder setTimeOffsetUs(long timeOffsetUs)
```

Sets the offset that is added to the timestamps of the cues in this subtitle track, in microseconds.

A positive value shifts the cues to be displayed later relative to the media, a negative value shifts them to be displayed earlier.

ExoPlayer specific notes:

- The offset can be changed during playback by passing an updated `https://developer.android.com/reference/androidx/media3/common/MediaItem` to `Player.replaceMediaItem(int, MediaItem)`. If only the time offsets of the `https://developer.android.com/reference/androidx/media3/common/MediaItem.SubtitleConfiguration` instances are changed, playback continues uninterrupted and the new offsets apply to cues that have not been read by the renderer yet. To also apply the new offset to the cues currently on screen, disable and re-enable the text track, for example with `
  TrackSelectionParameters.Builder.setTrackTypeDisabled(C.TRACK_TYPE_TEXT, boolean)`.
- The offset only takes effect if the subtitles are parsed during extraction (the default behavior of `DefaultMediaSourceFactory`), and is ignored by the deprecated legacy subtitle decoding path.

The default value is `0`.

### setUri

```
@CanIgnoreReturnValue
public MediaItem.SubtitleConfiguration.Builder setUri(Uri uri)
```

Sets the `https://developer.android.com/reference/android/net/Uri.html` to the subtitle file.