From dec01c83553273870960d403003931a7ccb179de Mon Sep 17 00:00:00 2001 From: "a.mochalov" Date: Tue, 30 Aug 2022 13:50:33 +0300 Subject: [PATCH] fix ProgressiveDownloader infinite loop doe to priority --- .../offline/ProgressiveDownloader.java | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/library/core/src/main/java/com/google/android/exoplayer2/offline/ProgressiveDownloader.java b/library/core/src/main/java/com/google/android/exoplayer2/offline/ProgressiveDownloader.java index 7af11dbbb4a..d6cf5ab7bf3 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/offline/ProgressiveDownloader.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/offline/ProgressiveDownloader.java @@ -88,19 +88,7 @@ public ProgressiveDownloader( public void download(@Nullable ProgressListener progressListener) throws IOException, InterruptedException { this.progressListener = progressListener; - downloadRunnable = - new RunnableFutureTask() { - @Override - protected Void doWork() throws IOException { - cacheWriter.cache(); - return null; - } - - @Override - protected void cancelWork() { - cacheWriter.cancel(); - } - }; + downloadRunnable = createDownloadTask(); if (priorityTaskManager != null) { priorityTaskManager.add(C.PRIORITY_DOWNLOAD); @@ -119,6 +107,8 @@ protected void cancelWork() { Throwable cause = Assertions.checkNotNull(e.getCause()); if (cause instanceof PriorityTooLowException) { // 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) { throw (IOException) cause; } else { @@ -161,4 +151,19 @@ private void onProgress(long contentLength, long bytesCached, long newBytesCache : ((bytesCached * 100f) / contentLength); progressListener.onProgress(contentLength, bytesCached, percentDownloaded); } + + private RunnableFutureTask createDownloadTask() { + return new RunnableFutureTask() { + @Override + protected Void doWork() throws IOException { + cacheWriter.cache(); + return null; + } + + @Override + protected void cancelWork() { + cacheWriter.cancel(); + } + }; + } }