# Download

# 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)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download "View this page in Java")

<br />

```
@UnstableApi
class Download
```

<br />

*** ** * ** ***

Represents state of a download.

## Summary

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

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

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 ### Public constructors                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Download](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/offline/Download#Download(androidx.media3.exoplayer.offline.DownloadRequest,int,long,long,long,int,int))`(` ` request: `[DownloadRequest](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/offline/DownloadRequest)`!,` ` @`[Download.State](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/offline/Download.State)` state: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`,` ` startTimeMs: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)`,` ` updateTimeMs: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)`,` ` contentLength: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)`,` ` stopReason: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`,` ` @`[Download.FailureReason](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/offline/Download.FailureReason)` failureReason: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) `)`                                                                                                                                                                                             |
| [Download](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/offline/Download#Download(androidx.media3.exoplayer.offline.DownloadRequest,int,long,long,long,int,int,androidx.media3.exoplayer.offline.DownloadProgress))`(` ` request: `[DownloadRequest](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/offline/DownloadRequest)`!,` ` @`[Download.State](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/offline/Download.State)` state: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`,` ` startTimeMs: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)`,` ` updateTimeMs: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)`,` ` contentLength: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)`,` ` stopReason: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`,` ` @`[Download.FailureReason](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/offline/Download.FailureReason)` failureReason: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`,` ` progress: `[DownloadProgress](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/offline/DownloadProgress)`!` `)` |

|                                ### Public functions                                 |
|-------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)       | [getBytesDownloaded](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/offline/Download#getBytesDownloaded())`()` Returns the total number of downloaded bytes.                                                                                                                                               |
| [Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)     | [getPercentDownloaded](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/offline/Download#getPercentDownloaded())`()` Returns the estimated download percentage, or[PERCENTAGE_UNSET](https://developer.android.com/reference/kotlin/androidx/media3/common/C#PERCENTAGE_UNSET())if no estimate is available. |
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | [isTerminalState](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/offline/Download#isTerminalState())`()` Returns whether the download is completed or failed.                                                                                                                                              |

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

## Constants

### FAILURE_REASON_NONE

```
const val FAILURE_REASON_NONE = 0: Int
```

The download isn't failed.  

### FAILURE_REASON_UNKNOWN

```
const val FAILURE_REASON_UNKNOWN = 1: Int
```

The download is failed because of unknown reason.  

### STATE_COMPLETED

```
const val STATE_COMPLETED = 3: Int
```

The download completed.  

### STATE_DOWNLOADING

```
const val STATE_DOWNLOADING = 2: Int
```

The download is currently started.  

### STATE_FAILED

```
const val STATE_FAILED = 4: Int
```

The download failed.  

### STATE_QUEUED

```
const val STATE_QUEUED = 0: Int
```

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

```
const val STATE_REMOVING = 5: Int
```

The download is being removed.  

### STATE_RESTARTING

```
const val STATE_RESTARTING = 7: Int
```

The download will restart after all downloaded data is removed.  

### STATE_STOPPED

```
const val STATE_STOPPED = 1: Int
```

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

### STOP_REASON_NONE

```
const val STOP_REASON_NONE = 0: Int
```

The download isn't stopped.  

## Public constructors

### Download

```
Download(
    request: DownloadRequest!,
    @Download.State state: Int,
    startTimeMs: Long,
    updateTimeMs: Long,
    contentLength: Long,
    stopReason: Int,
    @Download.FailureReason failureReason: Int
)
```  

### Download

```
Download(
    request: DownloadRequest!,
    @Download.State state: Int,
    startTimeMs: Long,
    updateTimeMs: Long,
    contentLength: Long,
    stopReason: Int,
    @Download.FailureReason failureReason: Int,
    progress: DownloadProgress!
)
```  

## Public functions

### getBytesDownloaded

```
fun getBytesDownloaded(): Long
```

Returns the total number of downloaded bytes.  

### getPercentDownloaded

```
fun getPercentDownloaded(): Float
```

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

### isTerminalState

```
fun isTerminalState(): Boolean
```

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

## Public properties

### contentLength

```
val contentLength: Long
```

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

### failureReason

```
@Download.FailureReason
val failureReason: Int
```

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

### request

```
val request: DownloadRequest!
```

The download request.  

### startTimeMs

```
val startTimeMs: Long
```

The first time when download entry is created.  

### state

```
@Download.State
val state: Int
```

The state of the download.  

### stopReason

```
val stopReason: Int
```

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

### updateTimeMs

```
val updateTimeMs: Long
```

The last update time.