# WritableDownloadIndex

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

*** ** * ** ***


```
@WorkerThread
@UnstableApi
public interface WritableDownloadIndex extends DownloadIndex
```

<br />

Known direct subclasses [DefaultDownloadIndex](https://developer.android.com/reference/androidx/media3/exoplayer/offline/DefaultDownloadIndex)

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

*** ** * ** ***

A writable index of `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download`.

## Summary

| ### Public methods |
|---|---|
| `abstract void` | `https://developer.android.com/reference/androidx/media3/exoplayer/offline/WritableDownloadIndex#putDownload(androidx.media3.exoplayer.offline.Download)(https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download download)` Adds or replaces a `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download`. |
| `abstract void` | `https://developer.android.com/reference/androidx/media3/exoplayer/offline/WritableDownloadIndex#removeDownload(java.lang.String)(https://developer.android.com/reference/java/lang/String.html id)` Removes the download with the given ID. |
| `abstract void` | `https://developer.android.com/reference/androidx/media3/exoplayer/offline/WritableDownloadIndex#setDownloadingStatesToQueued()()` Sets all `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download#STATE_DOWNLOADING()` states to `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download#STATE_QUEUED()`. |
| `abstract void` | `https://developer.android.com/reference/androidx/media3/exoplayer/offline/WritableDownloadIndex#setStatesToRemoving()()` Sets all states to `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download#STATE_REMOVING()`. |
| `abstract void` | `https://developer.android.com/reference/androidx/media3/exoplayer/offline/WritableDownloadIndex#setStopReason(int)(int stopReason)` Sets the stop reason of the downloads in a terminal state (`https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download#STATE_COMPLETED()`, `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download#STATE_FAILED()`). |
| `abstract void` | `https://developer.android.com/reference/androidx/media3/exoplayer/offline/WritableDownloadIndex#setStopReason(java.lang.String,int)(https://developer.android.com/reference/java/lang/String.html id, int stopReason)` Sets the stop reason of the download with the given ID in a terminal state (`https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download#STATE_COMPLETED()`, `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download#STATE_FAILED()`). |

| ### Inherited methods |
|---|
| From [androidx.media3.exoplayer.offline.DownloadIndex](https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadIndex) |---|---| | `abstract @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download` | `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadIndex#getDownload(java.lang.String)(https://developer.android.com/reference/java/lang/String.html id)` Returns the `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download` with the given `id`, or null. | | `abstract https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadCursor` | `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadIndex#getDownloads(int...)(@https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download.State int[] states)` Returns a `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadCursor` to `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download`s with the given `states`. | |

## Public methods

### putDownload

```
abstract void putDownload(Download download)
```

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

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

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download download` | The `https://developer.android.com/reference/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. |

### removeDownload

```
abstract void removeDownload(String id)
```

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 |
|---|---|
| `https://developer.android.com/reference/java/lang/String.html id` | The ID of the download to remove. |

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

### setDownloadingStatesToQueued

```
abstract void setDownloadingStatesToQueued()
```

Sets all `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download#STATE_DOWNLOADING()` states to `https://developer.android.com/reference/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. |

### setStatesToRemoving

```
abstract void setStatesToRemoving()
```

Sets all states to `https://developer.android.com/reference/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. |

### setStopReason

```
abstract void setStopReason(int stopReason)
```

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

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

| Parameters |
|---|---|
| `int stopReason` | The stop reason. |

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

### setStopReason

```
abstract void setStopReason(String id, int stopReason)
```

Sets the stop reason of the download with the given ID in a terminal state (`https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download#STATE_COMPLETED()`, `https://developer.android.com/reference/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 |
|---|---|
| `https://developer.android.com/reference/java/lang/String.html id` | The ID of the download to update. |
| `int stopReason` | The stop reason. |

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