From 083350b7dbae4569a1c2a5838715b968929c3510 Mon Sep 17 00:00:00 2001 From: aquilescanta Date: Mon, 24 Sep 2018 09:15:41 -0700 Subject: [PATCH] Do not retry failed loads whose error is FileNotFoundException ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=214277073 --- RELEASENOTES.md | 1 + .../upstream/DefaultLoadErrorHandlingPolicy.java | 8 +++++--- .../upstream/DefaultLoadErrorHandlingPolicyTest.java | 9 ++++----- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 55ad062859..032596a425 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -2,6 +2,7 @@ ### dev-v2 (not yet released) ### +* Do not retry failed loads whose error is `FileNotFoundException`. * Allow setting log level for ExoPlayer logcat output ([#4665](https://github.com/google/ExoPlayer/issues/4665)). * Fix an issue where audio and video would desynchronize when playing diff --git a/library/core/src/main/java/com/google/android/exoplayer2/upstream/DefaultLoadErrorHandlingPolicy.java b/library/core/src/main/java/com/google/android/exoplayer2/upstream/DefaultLoadErrorHandlingPolicy.java index 4eec495cab..8d8f156951 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/upstream/DefaultLoadErrorHandlingPolicy.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/upstream/DefaultLoadErrorHandlingPolicy.java @@ -18,6 +18,7 @@ package com.google.android.exoplayer2.upstream; import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.ParserException; import com.google.android.exoplayer2.upstream.HttpDataSource.InvalidResponseCodeException; +import java.io.FileNotFoundException; import java.io.IOException; /** Default implementation of {@link LoadErrorHandlingPolicy}. */ @@ -76,13 +77,14 @@ public final class DefaultLoadErrorHandlingPolicy implements LoadErrorHandlingPo } /** - * Retries for any exception that is not a subclass of {@link ParserException}. The retry delay is - * calculated as {@code Math.min((errorCount - 1) * 1000, 5000)}. + * Retries for any exception that is not a subclass of {@link ParserException} or {@link + * FileNotFoundException}. The retry delay is calculated as {@code Math.min((errorCount - 1) * + * 1000, 5000)}. */ @Override public long getRetryDelayMsFor( int dataType, long loadDurationMs, IOException exception, int errorCount) { - return exception instanceof ParserException + return exception instanceof ParserException || exception instanceof FileNotFoundException ? C.TIME_UNSET : Math.min((errorCount - 1) * 1000, 5000); } diff --git a/library/core/src/test/java/com/google/android/exoplayer2/upstream/DefaultLoadErrorHandlingPolicyTest.java b/library/core/src/test/java/com/google/android/exoplayer2/upstream/DefaultLoadErrorHandlingPolicyTest.java index e1700e3b20..0c2b938a64 100644 --- a/library/core/src/test/java/com/google/android/exoplayer2/upstream/DefaultLoadErrorHandlingPolicyTest.java +++ b/library/core/src/test/java/com/google/android/exoplayer2/upstream/DefaultLoadErrorHandlingPolicyTest.java @@ -21,7 +21,6 @@ import android.net.Uri; import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.ParserException; import com.google.android.exoplayer2.upstream.HttpDataSource.InvalidResponseCodeException; -import java.io.FileNotFoundException; import java.io.IOException; import java.util.Collections; import org.junit.Test; @@ -57,7 +56,7 @@ public final class DefaultLoadErrorHandlingPolicyTest { @Test public void getBlacklistDurationMsFor_dontBlacklistUnexpectedExceptions() { - FileNotFoundException exception = new FileNotFoundException(); + IOException exception = new IOException(); assertThat(getDefaultPolicyBlacklistOutputFor(exception)).isEqualTo(C.TIME_UNSET); } @@ -69,9 +68,9 @@ public final class DefaultLoadErrorHandlingPolicyTest { @Test public void getRetryDelayMsFor_successiveRetryDelays() { - assertThat(getDefaultPolicyRetryDelayOutputFor(new FileNotFoundException(), 3)).isEqualTo(2000); - assertThat(getDefaultPolicyRetryDelayOutputFor(new FileNotFoundException(), 5)).isEqualTo(4000); - assertThat(getDefaultPolicyRetryDelayOutputFor(new FileNotFoundException(), 9)).isEqualTo(5000); + assertThat(getDefaultPolicyRetryDelayOutputFor(new IOException(), 3)).isEqualTo(2000); + assertThat(getDefaultPolicyRetryDelayOutputFor(new IOException(), 5)).isEqualTo(4000); + assertThat(getDefaultPolicyRetryDelayOutputFor(new IOException(), 9)).isEqualTo(5000); } private static long getDefaultPolicyBlacklistOutputFor(IOException exception) {