google / google/ExoPlayer

[question] Is there a Listener that is notified when all downloads have been removed?

Open
#10,784 0 comments 0 reactions 1 assignee Claimed by @marcbaechinger View on GitHub
needs triage question
Dominant language
Java
Stars
21.9k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

When making a call [to](https://github.com/google/ExoPlayer/blob/r2.18.1/library/core/src/main/java/com/google/android/exoplayer2/offline/DownloadService.java#L479):
```java
DownloadService.sendRemoveAllDownloads
```
which is delegated [to](https://github.com/google/ExoPlayer/blob/r2.18.1/library/core/src/main/java/com/google/android/exoplayer2/offline/DownloadManager.java#L506):
```java
DownloadManager.removeAllDownloads
```
which is delegated [to](https://github.com/google/ExoPlayer/blob/r2.18.1/library/core/src/main/java/com/google/android/exoplayer2/offline/DownloadManager.java#L917):
```java
DownloadManager.InternalHandler.removeAllDownloads
```

This appears to be an asynchronous task,
and each download is cancelled independently in its own thread.

Is there any way to wait until all downloaded data is fully removed,
before executing a callback?

pseudo code:
```javascript
Promise.all(downloads.map(cancel))
.then(callback)
```

- - - -

Because of async and threading, I don't suppose the following would work.
But I'll pose it as an idea.
Hopefully it'll inspire somebody else to think of a better suggestion..

```java
DownloadService.sendRemoveAllDownloads(...);
// => myDownloadManager.removeAllDownloads();

if (myDownloadManager.isIdle())
callback();
else
myDownloadManager.addListener(new DownloadManager.Listener() {
@Override
public void onIdle(DownloadManager dm) {
myDownloadManager.removeListener(this);
callback();
}
});
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.