# Download

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/Download.java+class:androidx.media3.exoplayer.offline.Download)

*** ** * ** ***


```
@UnstableApi
public final class Download
```

<br />

*** ** * ** ***

Represents state of a download.

## Summary

| ### Nested types |
|---|
| `@https://developer.android.com/reference/java/lang/annotation/Documented.html @https://developer.android.com/reference/java/lang/annotation/Retention.html(value = https://developer.android.com/reference/java/lang/annotation/RetentionPolicy.html#SOURCE) @https://developer.android.com/reference/java/lang/annotation/Target.html(value = ) @https://developer.android.com/reference/androidx/annotation/IntDef(value = ) public annotation https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download.FailureReason` Failure reasons. |
| `@https://developer.android.com/reference/java/lang/annotation/Documented.html @https://developer.android.com/reference/java/lang/annotation/Retention.html(value = https://developer.android.com/reference/java/lang/annotation/RetentionPolicy.html#SOURCE) @https://developer.android.com/reference/java/lang/annotation/Target.html(value = ) @https://developer.android.com/reference/androidx/annotation/IntDef(value = ) public annotation https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download.State` Download states. |

| ### Constants |
|---|---|
| `static final int` | `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download#FAILURE_REASON_NONE() = 0` The download isn't failed. |
| `static final int` | `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download#FAILURE_REASON_UNKNOWN() = 1` The download is failed because of unknown reason. |
| `static final int` | `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download#STATE_COMPLETED() = 3` The download completed. |
| `static final int` | `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download#STATE_DOWNLOADING() = 2` The download is currently started. |
| `static final int` | `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download#STATE_FAILED() = 4` The download failed. |
| `static final int` | `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download#STATE_QUEUED() = 0` The download is waiting to be started. |
| `static final int` | `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download#STATE_REMOVING() = 5` The download is being removed. |
| `static final int` | `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download#STATE_RESTARTING() = 7` The download will restart after all downloaded data is removed. |
| `static final int` | `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download#STATE_STOPPED() = 1` The download is stopped for a specified `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download#stopReason()`. |
| `static final int` | `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download#STOP_REASON_NONE() = 0` The download isn't stopped. |

| ### Public fields |
|---|---|
| `final long` | `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download#contentLength()` The total size of the content in bytes, or `https://developer.android.com/reference/androidx/media3/common/C#LENGTH_UNSET()` if unknown. |
| `final int` | `@https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download.FailureReason https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download#failureReason()` If `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download#state()` is `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download#STATE_FAILED()` then this is the cause, otherwise `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download#FAILURE_REASON_NONE()`. |
| `final https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadRequest` | `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download#request()` The download request. |
| `final long` | `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download#startTimeMs()` The first time when download entry is created. |
| `final int` | `@https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download.State https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download#state()` The state of the download. |
| `final int` | `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download#stopReason()` The reason the download is stopped, or `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download#STOP_REASON_NONE()`. |
| `final long` | `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download#updateTimeMs()` The last update time. |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download#Download(androidx.media3.exoplayer.offline.DownloadRequest,int,long,long,long,int,int)( https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadRequest request, @https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download.State int state, long startTimeMs, long updateTimeMs, long contentLength, int stopReason, @https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download.FailureReason int failureReason )` |
| `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download#Download(androidx.media3.exoplayer.offline.DownloadRequest,int,long,long,long,int,int,androidx.media3.exoplayer.offline.DownloadProgress)( https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadRequest request, @https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download.State int state, long startTimeMs, long updateTimeMs, long contentLength, int stopReason, @https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download.FailureReason int failureReason, https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadProgress progress )` |

| ### Public methods |
|---|---|
| `long` | `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download#getBytesDownloaded()()` Returns the total number of downloaded bytes. |
| `float` | `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download#getPercentDownloaded()()` Returns the estimated download percentage, or `https://developer.android.com/reference/androidx/media3/common/C#PERCENTAGE_UNSET()` if no estimate is available. |
| `boolean` | `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download#isTerminalState()()` Returns whether the download is completed or failed. |

## Constants

### FAILURE_REASON_NONE

```
public static final int FAILURE_REASON_NONE = 0
```

The download isn't failed.

### FAILURE_REASON_UNKNOWN

```
public static final int FAILURE_REASON_UNKNOWN = 1
```

The download is failed because of unknown reason.

### STATE_COMPLETED

```
public static final int STATE_COMPLETED = 3
```

The download completed.

### STATE_DOWNLOADING

```
public static final int STATE_DOWNLOADING = 2
```

The download is currently started.

### STATE_FAILED

```
public static final int STATE_FAILED = 4
```

The download failed.

### STATE_QUEUED

```
public static final int STATE_QUEUED = 0
```

The download is waiting to be started. A download may be queued because the `
DownloadManager`

- Is `DownloadManager#getDownloadsPaused() paused`
- Has `DownloadManager#getRequirements() Requirements` that are not met
- Has already started `DownloadManager#getMaxParallelDownloads()
  maxParallelDownloads`

### STATE_REMOVING

```
public static final int STATE_REMOVING = 5
```

The download is being removed.

### STATE_RESTARTING

```
public static final int STATE_RESTARTING = 7
```

The download will restart after all downloaded data is removed.

### STATE_STOPPED

```
public static final int STATE_STOPPED = 1
```

The download is stopped for a specified `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download#stopReason()`.

### STOP_REASON_NONE

```
public static final int STOP_REASON_NONE = 0
```

The download isn't stopped.

## Public fields

### contentLength

```
public final long contentLength
```

The total size of the content in bytes, or `https://developer.android.com/reference/androidx/media3/common/C#LENGTH_UNSET()` if unknown.

### failureReason

```
@Download.FailureReason
public final int failureReason
```

If `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download#state()` is `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download#STATE_FAILED()` then this is the cause, otherwise `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download#FAILURE_REASON_NONE()`.

### request

```
public final DownloadRequest request
```

The download request.

### startTimeMs

```
public final long startTimeMs
```

The first time when download entry is created.

### state

```
@Download.State
public final int state
```

The state of the download.

### stopReason

```
public final int stopReason
```

The reason the download is stopped, or `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download#STOP_REASON_NONE()`.

### updateTimeMs

```
public final long updateTimeMs
```

The last update time.

## Public constructors

### Download

```
public Download(
    DownloadRequest request,
    @Download.State int state,
    long startTimeMs,
    long updateTimeMs,
    long contentLength,
    int stopReason,
    @Download.FailureReason int failureReason
)
```

### Download

```
public Download(
    DownloadRequest request,
    @Download.State int state,
    long startTimeMs,
    long updateTimeMs,
    long contentLength,
    int stopReason,
    @Download.FailureReason int failureReason,
    DownloadProgress progress
)
```

## Public methods

### getBytesDownloaded

```
public long getBytesDownloaded()
```

Returns the total number of downloaded bytes.

### getPercentDownloaded

```
public float getPercentDownloaded()
```

Returns the estimated download percentage, or `https://developer.android.com/reference/androidx/media3/common/C#PERCENTAGE_UNSET()` if no estimate is available.

### isTerminalState

```
public boolean isTerminalState()
```

Returns whether the download is completed or failed. These are terminal states.