mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
fix ProgressiveDownloader infinite loop doe to priority
This commit is contained in:
parent
6288182113
commit
dec01c8355
1 changed files with 18 additions and 13 deletions
|
|
@ -88,19 +88,7 @@ public final class ProgressiveDownloader implements Downloader {
|
||||||
public void download(@Nullable ProgressListener progressListener)
|
public void download(@Nullable ProgressListener progressListener)
|
||||||
throws IOException, InterruptedException {
|
throws IOException, InterruptedException {
|
||||||
this.progressListener = progressListener;
|
this.progressListener = progressListener;
|
||||||
downloadRunnable =
|
downloadRunnable = createDownloadTask();
|
||||||
new RunnableFutureTask<Void, IOException>() {
|
|
||||||
@Override
|
|
||||||
protected Void doWork() throws IOException {
|
|
||||||
cacheWriter.cache();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void cancelWork() {
|
|
||||||
cacheWriter.cancel();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if (priorityTaskManager != null) {
|
if (priorityTaskManager != null) {
|
||||||
priorityTaskManager.add(C.PRIORITY_DOWNLOAD);
|
priorityTaskManager.add(C.PRIORITY_DOWNLOAD);
|
||||||
|
|
@ -119,6 +107,8 @@ public final class ProgressiveDownloader implements Downloader {
|
||||||
Throwable cause = Assertions.checkNotNull(e.getCause());
|
Throwable cause = Assertions.checkNotNull(e.getCause());
|
||||||
if (cause instanceof PriorityTooLowException) {
|
if (cause instanceof PriorityTooLowException) {
|
||||||
// The next loop iteration will block until the task is able to proceed.
|
// The next loop iteration will block until the task is able to proceed.
|
||||||
|
// recreate downloadRunnable in order to prevent error state caching
|
||||||
|
downloadRunnable = createDownloadTask();
|
||||||
} else if (cause instanceof IOException) {
|
} else if (cause instanceof IOException) {
|
||||||
throw (IOException) cause;
|
throw (IOException) cause;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -161,4 +151,19 @@ public final class ProgressiveDownloader implements Downloader {
|
||||||
: ((bytesCached * 100f) / contentLength);
|
: ((bytesCached * 100f) / contentLength);
|
||||||
progressListener.onProgress(contentLength, bytesCached, percentDownloaded);
|
progressListener.onProgress(contentLength, bytesCached, percentDownloaded);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private RunnableFutureTask<Void, IOException> createDownloadTask() {
|
||||||
|
return new RunnableFutureTask<Void, IOException>() {
|
||||||
|
@Override
|
||||||
|
protected Void doWork() throws IOException {
|
||||||
|
cacheWriter.cache();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void cancelWork() {
|
||||||
|
cacheWriter.cancel();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue