Add a retry count to stop infinite downloads
Signed-off-by: James Wells <james@jameswells.net>
This commit is contained in:
parent
2e4dde099d
commit
d084270c4b
|
@ -194,6 +194,12 @@ public class Downloader
|
||||||
revision++;
|
revision++;
|
||||||
i--;
|
i--;
|
||||||
}
|
}
|
||||||
|
else if (downloadFile.isFailed() && !downloadFile.shouldRetry()) {
|
||||||
|
// Don't continue to attempt to download forever
|
||||||
|
backgroundDownloadList.remove(i);
|
||||||
|
revision++;
|
||||||
|
i--;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
currentDownloading = downloadFile;
|
currentDownloading = downloadFile;
|
||||||
|
|
|
@ -45,6 +45,7 @@ class DownloadFile(
|
||||||
private val mediaStoreService: MediaStoreService
|
private val mediaStoreService: MediaStoreService
|
||||||
private var downloadTask: CancellableTask? = null
|
private var downloadTask: CancellableTask? = null
|
||||||
var isFailed = false
|
var isFailed = false
|
||||||
|
private var retryCount = 5
|
||||||
|
|
||||||
private val desiredBitRate: Int = Util.getMaxBitRate(context)
|
private val desiredBitRate: Int = Util.getMaxBitRate(context)
|
||||||
|
|
||||||
|
@ -127,6 +128,10 @@ class DownloadFile(
|
||||||
return save
|
return save
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun shouldRetry(): Boolean {
|
||||||
|
return (retryCount > 0)
|
||||||
|
}
|
||||||
|
|
||||||
fun delete() {
|
fun delete() {
|
||||||
cancelDownload()
|
cancelDownload()
|
||||||
Util.delete(partialFile)
|
Util.delete(partialFile)
|
||||||
|
@ -288,6 +293,9 @@ class DownloadFile(
|
||||||
Util.delete(saveFile)
|
Util.delete(saveFile)
|
||||||
if (!isCancelled) {
|
if (!isCancelled) {
|
||||||
isFailed = true
|
isFailed = true
|
||||||
|
if (retryCount > 0) {
|
||||||
|
--retryCount
|
||||||
|
}
|
||||||
Timber.w(x, "Failed to download '%s'.", song)
|
Timber.w(x, "Failed to download '%s'.", song)
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
|
Loading…
Reference in New Issue