diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 68ce72a815..f00b7b1793 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -26,6 +26,11 @@ average video frame processing offset. * Add playlist API ([#6161](https://github.com/google/ExoPlayer/issues/6161)). + * Attach an identifier and extra information to load error events passed + to `LoadErrorHandlingPolicy`. `LoadErrorHandlingPolicy` implementations + must migrate to overriding the non-deprecated methods of the interface + in preparation for deprecated methods' removal in a future ExoPlayer + version ([#7309](https://github.com/google/ExoPlayer/issues/7309)). * Add `play` and `pause` methods to `Player`. * Add `Player.getCurrentLiveOffset` to conveniently return the live offset. 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 435f4bf578..a5e30b5ccc 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 @@ -65,8 +65,8 @@ public class DefaultLoadErrorHandlingPolicy implements LoadErrorHandlingPolicy { * code HTTP 404 or 410. The duration of the blacklisting is {@link #DEFAULT_TRACK_BLACKLIST_MS}. */ @Override - public long getBlacklistDurationMsFor( - int dataType, long loadDurationMs, IOException exception, int errorCount) { + public long getBlacklistDurationMsFor(LoadErrorInfo loadErrorInfo) { + IOException exception = loadErrorInfo.exception; if (exception instanceof InvalidResponseCodeException) { int responseCode = ((InvalidResponseCodeException) exception).responseCode; return responseCode == 404 // HTTP 404 Not Found. @@ -84,13 +84,13 @@ public class DefaultLoadErrorHandlingPolicy implements LoadErrorHandlingPolicy { * {@code Math.min((errorCount - 1) * 1000, 5000)}. */ @Override - public long getRetryDelayMsFor( - int dataType, long loadDurationMs, IOException exception, int errorCount) { + public long getRetryDelayMsFor(LoadErrorInfo loadErrorInfo) { + IOException exception = loadErrorInfo.exception; return exception instanceof ParserException || exception instanceof FileNotFoundException || exception instanceof UnexpectedLoaderException ? C.TIME_UNSET - : Math.min((errorCount - 1) * 1000, 5000); + : Math.min((loadErrorInfo.errorCount - 1) * 1000, 5000); } /** diff --git a/library/core/src/main/java/com/google/android/exoplayer2/upstream/LoadErrorHandlingPolicy.java b/library/core/src/main/java/com/google/android/exoplayer2/upstream/LoadErrorHandlingPolicy.java index 61e3b8309a..9705437419 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/upstream/LoadErrorHandlingPolicy.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/upstream/LoadErrorHandlingPolicy.java @@ -65,21 +65,12 @@ public interface LoadErrorHandlingPolicy { } } - /** - * Returns the number of milliseconds for which a resource associated to a provided load error - * should be blacklisted, or {@link C#TIME_UNSET} if the resource should not be blacklisted. - * - * @param dataType One of the {@link C C.DATA_TYPE_*} constants indicating the type of data to - * load. - * @param loadDurationMs The duration in milliseconds of the load from the start of the first load - * attempt up to the point at which the error occurred. - * @param exception The load error. - * @param errorCount The number of errors this load has encountered, including this one. - * @return The blacklist duration in milliseconds, or {@link C#TIME_UNSET} if the resource should - * not be blacklisted. - */ - long getBlacklistDurationMsFor( - int dataType, long loadDurationMs, IOException exception, int errorCount); + /** @deprecated Implement {@link #getBlacklistDurationMsFor(LoadErrorInfo)} instead. */ + @Deprecated + default long getBlacklistDurationMsFor( + int dataType, long loadDurationMs, IOException exception, int errorCount) { + throw new UnsupportedOperationException(); + } /** * Returns the number of milliseconds for which a resource associated to a provided load error @@ -89,6 +80,7 @@ public interface LoadErrorHandlingPolicy { * @return The blacklist duration in milliseconds, or {@link C#TIME_UNSET} if the resource should * not be blacklisted. */ + @SuppressWarnings("deprecation") default long getBlacklistDurationMsFor(LoadErrorInfo loadErrorInfo) { return getBlacklistDurationMsFor( loadErrorInfo.mediaLoadData.dataType, @@ -97,25 +89,13 @@ public interface LoadErrorHandlingPolicy { loadErrorInfo.errorCount); } - /** - * Returns the number of milliseconds to wait before attempting the load again, or {@link - * C#TIME_UNSET} if the error is fatal and should not be retried. - * - *
{@link Loader} clients may ignore the retry delay returned by this method in order to wait - * for a specific event before retrying. However, the load is retried if and only if this method - * does not return {@link C#TIME_UNSET}. - * - * @param dataType One of the {@link C C.DATA_TYPE_*} constants indicating the type of data to - * load. - * @param loadDurationMs The duration in milliseconds of the load from the start of the first load - * attempt up to the point at which the error occurred. - * @param exception The load error. - * @param errorCount The number of errors this load has encountered, including this one. - * @return The number of milliseconds to wait before attempting the load again, or {@link - * C#TIME_UNSET} if the error is fatal and should not be retried. - */ - long getRetryDelayMsFor(int dataType, long loadDurationMs, IOException exception, int errorCount); - + /** @deprecated Implement {@link #getRetryDelayMsFor(LoadErrorInfo)} instead. */ + @Deprecated + default long getRetryDelayMsFor( + int dataType, long loadDurationMs, IOException exception, int errorCount) { + throw new UnsupportedOperationException(); + } + /** * Returns the number of milliseconds to wait before attempting the load again, or {@link * C#TIME_UNSET} if the error is fatal and should not be retried. @@ -128,6 +108,7 @@ public interface LoadErrorHandlingPolicy { * @return The number of milliseconds to wait before attempting the load again, or {@link * C#TIME_UNSET} if the error is fatal and should not be retried. */ + @SuppressWarnings("deprecation") default long getRetryDelayMsFor(LoadErrorInfo loadErrorInfo) { return getRetryDelayMsFor( loadErrorInfo.mediaLoadData.dataType,