# DownloadRequest.Builder

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

*** ** * ** ***


```
public class DownloadRequest.Builder
```

<br />

*** ** * ** ***

A builder for download requests.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadRequest.Builder#Builder(java.lang.String,android.net.Uri)(https://developer.android.com/reference/java/lang/String.html id, https://developer.android.com/reference/android/net/Uri.html uri)` Creates a new instance with the specified id and uri. |

| ### Public methods |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadRequest` | `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadRequest.Builder#build()()` |
| `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadRequest.Builder` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadRequest.Builder#setByteRange(long,long)(long offset, long length)` Sets the byte range to be downloaded. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadRequest.Builder` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadRequest.Builder#setCustomCacheKey(java.lang.String)(@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/String.html customCacheKey)` Sets the `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadRequest#customCacheKey()`. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadRequest.Builder` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadRequest.Builder#setData(byte[])(@https://developer.android.com/reference/androidx/annotation/Nullable byte[] data)` Sets the `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadRequest#data()`. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadRequest.Builder` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadRequest.Builder#setKeySetId(byte[])(@https://developer.android.com/reference/androidx/annotation/Nullable byte[] keySetId)` Sets the `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadRequest#keySetId()`. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadRequest.Builder` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadRequest.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 `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadRequest#mimeType()`. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadRequest.Builder` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadRequest.Builder#setStreamKeys(java.util.List<androidx.media3.common.StreamKey>)(@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/media3/common/StreamKey> streamKeys)` Sets the `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadRequest#streamKeys()`. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadRequest.Builder` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadRequest.Builder#setTimeRange(long,long)(long startPositionUs, long durationUs)` Sets the time range to be downloaded. |

## Public constructors

### Builder

```
public Builder(String id, Uri uri)
```

Creates a new instance with the specified id and uri.

## Public methods

### build

```
public DownloadRequest build()
```

### setByteRange

```
@CanIgnoreReturnValue
public DownloadRequest.Builder setByteRange(long offset, long length)
```

Sets the byte range to be downloaded.

This will be ignored for DASH, HLS and SmoothStreaming downloads.

| Parameters |
|---|---|
| `long offset` | The offset that the download should start from. |
| `long length` | The length from the `offset` to be downloaded, or @link C#LENGTH_UNSET} if the media should be downloaded to the end. |

### setCustomCacheKey

```
@CanIgnoreReturnValue
public DownloadRequest.Builder setCustomCacheKey(@Nullable String customCacheKey)
```

Sets the `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadRequest#customCacheKey()`.

### setData

```
@CanIgnoreReturnValue
public DownloadRequest.Builder setData(@Nullable byte[] data)
```

Sets the `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadRequest#data()`.

### setKeySetId

```
@CanIgnoreReturnValue
public DownloadRequest.Builder setKeySetId(@Nullable byte[] keySetId)
```

Sets the `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadRequest#keySetId()`.

### setMimeType

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

Sets the `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadRequest#mimeType()`.

### setStreamKeys

```
@CanIgnoreReturnValue
public DownloadRequest.Builder setStreamKeys(@Nullable List<StreamKey> streamKeys)
```

Sets the `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadRequest#streamKeys()`.

### setTimeRange

```
@CanIgnoreReturnValue
public DownloadRequest.Builder setTimeRange(long startPositionUs, long durationUs)
```

Sets the time range to be downloaded.

This will be ignored progressive downloads.

| Parameters |
|---|---|
| `long startPositionUs` | The start position in microseconds that the download should start from. |
| `long durationUs` | The duration in microseconds from the `startPositionUs` to be downloaded, or `https://developer.android.com/reference/androidx/media3/common/C#TIME_UNSET()` if the media should be downloaded to the end. |