Add a retry count to stop infinite downloads

Signed-off-by: James Wells <james@jameswells.net>
This commit is contained in:
James Wells 2021-04-25 23:08:12 -04:00
parent 2e4dde099d
commit d084270c4b
No known key found for this signature in database
GPG Key ID: 7A9AB99C0B899FB7
2 changed files with 14 additions and 0 deletions

View File

@ -194,6 +194,12 @@ public class Downloader
revision++;
i--;
}
else if (downloadFile.isFailed() && !downloadFile.shouldRetry()) {
// Don't continue to attempt to download forever
backgroundDownloadList.remove(i);
revision++;
i--;
}
else
{
currentDownloading = downloadFile;

View File

@ -45,6 +45,7 @@ class DownloadFile(
private val mediaStoreService: MediaStoreService
private var downloadTask: CancellableTask? = null
var isFailed = false
private var retryCount = 5
private val desiredBitRate: Int = Util.getMaxBitRate(context)
@ -127,6 +128,10 @@ class DownloadFile(
return save
}
fun shouldRetry(): Boolean {
return (retryCount > 0)
}
fun delete() {
cancelDownload()
Util.delete(partialFile)
@ -288,6 +293,9 @@ class DownloadFile(
Util.delete(saveFile)
if (!isCancelled) {
isFailed = true
if (retryCount > 0) {
--retryCount
}
Timber.w(x, "Failed to download '%s'.", song)
}
} finally {