# DefaultDownloadIndex

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

*** ** * ** ***

<br />

```
@UnstableApi
class DefaultDownloadIndex : WritableDownloadIndex
```

<br />

*** ** * ** ***

A `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/offline/DownloadIndex` that uses SQLite to persist `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/offline/Download`.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/offline/DefaultDownloadIndex#DefaultDownloadIndex(androidx.media3.database.DatabaseProvider)(databaseProvider: https://developer.android.com/reference/kotlin/androidx/media3/database/DatabaseProvider!)` Creates an instance that stores the `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/offline/Download` in an SQLite database provided by a `https://developer.android.com/reference/kotlin/androidx/media3/database/DatabaseProvider`. |
| `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/offline/DefaultDownloadIndex#DefaultDownloadIndex(androidx.media3.database.DatabaseProvider,java.lang.String)(databaseProvider: https://developer.android.com/reference/kotlin/androidx/media3/database/DatabaseProvider!, name: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!)` Creates an instance that stores the `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/offline/Download` in an SQLite database provided by a `https://developer.android.com/reference/kotlin/androidx/media3/database/DatabaseProvider`. |

| ### Public functions |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/offline/Download?` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/offline/DefaultDownloadIndex#getDownload(java.lang.String)(id: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!)` Returns the `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/offline/Download` with the given `id`, or null. |
| `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/offline/DownloadCursor!` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/offline/DefaultDownloadIndex#getDownloads(int...)(@https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/offline/Download.State states: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html>!)` Returns a `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/offline/DownloadCursor` to `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/offline/Download`s with the given `states`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/offline/DefaultDownloadIndex#putDownload(androidx.media3.exoplayer.offline.Download)(download: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/offline/Download!)` Adds or replaces a `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/offline/Download`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/offline/DefaultDownloadIndex#removeDownload(java.lang.String)(id: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!)` Removes the download with the given ID. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/offline/DefaultDownloadIndex#setDownloadingStatesToQueued()()` Sets all `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/offline/Download#STATE_DOWNLOADING()` states to `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/offline/Download#STATE_QUEUED()`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/offline/DefaultDownloadIndex#setStatesToRemoving()()` Sets all states to `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/offline/Download#STATE_REMOVING()`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/offline/DefaultDownloadIndex#setStopReason(int)(stopReason: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Sets the stop reason of the downloads in a terminal state (`https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/offline/Download#STATE_COMPLETED()`, `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/offline/Download#STATE_FAILED()`). |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/offline/DefaultDownloadIndex#setStopReason(java.lang.String,int)(id: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!, stopReason: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Sets the stop reason of the download with the given ID in a terminal state (`https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/offline/Download#STATE_COMPLETED()`, `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/offline/Download#STATE_FAILED()`). |

## Public constructors

### DefaultDownloadIndex

```
DefaultDownloadIndex(databaseProvider: DatabaseProvider!)
```

Creates an instance that stores the `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/offline/Download` in an SQLite database provided by a `https://developer.android.com/reference/kotlin/androidx/media3/database/DatabaseProvider`.

Equivalent to calling `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/offline/DefaultDownloadIndex#DefaultDownloadIndex(androidx.media3.database.DatabaseProvider,java.lang.String)` with ` name=""`.

Applications that only have one download index may use this constructor. Applications that have multiple download indices should call `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/offline/DefaultDownloadIndex#DefaultDownloadIndex(androidx.media3.database.DatabaseProvider,java.lang.String)` to specify a unique name for each index.

| Parameters |
|---|---|
| `databaseProvider: https://developer.android.com/reference/kotlin/androidx/media3/database/DatabaseProvider!` | Provides the SQLite database in which downloads are persisted. |

### DefaultDownloadIndex

```
DefaultDownloadIndex(databaseProvider: DatabaseProvider!, name: String!)
```

Creates an instance that stores the `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/offline/Download` in an SQLite database provided by a `https://developer.android.com/reference/kotlin/androidx/media3/database/DatabaseProvider`.

| Parameters |
|---|---|
| `databaseProvider: https://developer.android.com/reference/kotlin/androidx/media3/database/DatabaseProvider!` | Provides the SQLite database in which downloads are persisted. |
| `name: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | The name of the index. This name is incorporated into the names of the SQLite tables in which downloads are persisted. |

## Public functions

### getDownload

```
fun getDownload(id: String!): Download?
```

Returns the `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/offline/Download` with the given `id`, or null.

This method may be slow and shouldn't normally be called on the main thread.

| Parameters |
|---|---|
| `id: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | ID of a `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/offline/Download`. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/offline/Download?` | The `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/offline/Download` with the given `id`, or null if a download state with this id doesn't exist. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` | If an error occurs reading the state. |
| `https://developer.android.com/reference/kotlin/androidx/media3/database/DatabaseIOException` |   |

### getDownloads

```
fun getDownloads(@Download.State states: IntArray<Int>!): DownloadCursor!
```

Returns a `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/offline/DownloadCursor` to `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/offline/Download`s with the given `states`.

This method may be slow and shouldn't normally be called on the main thread.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/offline/Download.State states: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html>!` | Returns only the `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/offline/Download`s with this states. If empty, returns all. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/offline/DownloadCursor!` | A cursor to `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/offline/Download`s with the given `states`. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` | If an error occurs reading the state. |
| `https://developer.android.com/reference/kotlin/androidx/media3/database/DatabaseIOException` |   |

### putDownload

```
fun putDownload(download: Download!): Unit
```

Adds or replaces a `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/offline/Download`.

This method may be slow and shouldn't normally be called on the main thread.

| Parameters |
|---|---|
| `download: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/offline/Download!` | The `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/offline/Download` to be added. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` | If an error occurs setting the state. |
| `https://developer.android.com/reference/kotlin/androidx/media3/database/DatabaseIOException` |   |

### removeDownload

```
fun removeDownload(id: String!): Unit
```

Removes the download with the given ID. Does nothing if a download with the given ID does not exist.

This method may be slow and shouldn't normally be called on the main thread.

| Parameters |
|---|---|
| `id: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | The ID of the download to remove. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` | If an error occurs removing the state. |
| `https://developer.android.com/reference/kotlin/androidx/media3/database/DatabaseIOException` |   |

### setDownloadingStatesToQueued

```
fun setDownloadingStatesToQueued(): Unit
```

Sets all `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/offline/Download#STATE_DOWNLOADING()` states to `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/offline/Download#STATE_QUEUED()`.

This method may be slow and shouldn't normally be called on the main thread.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` | If an error occurs updating the state. |
| `https://developer.android.com/reference/kotlin/androidx/media3/database/DatabaseIOException` |   |

### setStatesToRemoving

```
fun setStatesToRemoving(): Unit
```

Sets all states to `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/offline/Download#STATE_REMOVING()`.

This method may be slow and shouldn't normally be called on the main thread.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` | If an error occurs updating the state. |
| `https://developer.android.com/reference/kotlin/androidx/media3/database/DatabaseIOException` |   |

### setStopReason

```
fun setStopReason(stopReason: Int): Unit
```

Sets the stop reason of the downloads in a terminal state (`https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/offline/Download#STATE_COMPLETED()`, `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/offline/Download#STATE_FAILED()`).

This method may be slow and shouldn't normally be called on the main thread.

| Parameters |
|---|---|
| `stopReason: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The stop reason. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` | If an error occurs updating the state. |
| `https://developer.android.com/reference/kotlin/androidx/media3/database/DatabaseIOException` |   |

### setStopReason

```
fun setStopReason(id: String!, stopReason: Int): Unit
```

Sets the stop reason of the download with the given ID in a terminal state (`https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/offline/Download#STATE_COMPLETED()`, `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/offline/Download#STATE_FAILED()`). Does nothing if a download with the given ID does not exist, or if it's not in a terminal state.

This method may be slow and shouldn't normally be called on the main thread.

| Parameters |
|---|---|
| `id: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | The ID of the download to update. |
| `stopReason: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The stop reason. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` | If an error occurs updating the state. |
| `https://developer.android.com/reference/kotlin/androidx/media3/database/DatabaseIOException` |   |