From 0df62a4f209d4c30ac9b058a89c2b2bdefaa381f Mon Sep 17 00:00:00 2001 From: aquilescanta Date: Tue, 27 Jul 2021 18:37:33 +0100 Subject: [PATCH] Add ERROR_CODE_FAILED_RUNTIME_CHECK for failed checks PiperOrigin-RevId: 387143625 --- .../exoplayer2/ext/cronet/CronetDataSource.java | 2 +- .../exoplayer2/ext/okhttp/OkHttpDataSource.java | 2 +- .../google/android/exoplayer2/PlaybackException.java | 10 ++++++++++ .../android/exoplayer2/ExoPlayerImplInternal.java | 8 +++++++- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/extensions/cronet/src/main/java/com/google/android/exoplayer2/ext/cronet/CronetDataSource.java b/extensions/cronet/src/main/java/com/google/android/exoplayer2/ext/cronet/CronetDataSource.java index 1da6dd5f9e..1cfd79e059 100644 --- a/extensions/cronet/src/main/java/com/google/android/exoplayer2/ext/cronet/CronetDataSource.java +++ b/extensions/cronet/src/main/java/com/google/android/exoplayer2/ext/cronet/CronetDataSource.java @@ -937,7 +937,7 @@ public class CronetDataSource extends BaseDataSource implements HttpDataSource { throw new OpenException( "HTTP request with non-empty body must set Content-Type", dataSpec, - PlaybackException.ERROR_CODE_IO_BAD_HTTP_REQUEST, + PlaybackException.ERROR_CODE_FAILED_RUNTIME_CHECK, Status.IDLE); } diff --git a/extensions/okhttp/src/main/java/com/google/android/exoplayer2/ext/okhttp/OkHttpDataSource.java b/extensions/okhttp/src/main/java/com/google/android/exoplayer2/ext/okhttp/OkHttpDataSource.java index 706667320d..e5d7af4980 100644 --- a/extensions/okhttp/src/main/java/com/google/android/exoplayer2/ext/okhttp/OkHttpDataSource.java +++ b/extensions/okhttp/src/main/java/com/google/android/exoplayer2/ext/okhttp/OkHttpDataSource.java @@ -405,7 +405,7 @@ public class OkHttpDataSource extends BaseDataSource implements HttpDataSource { throw new HttpDataSourceException( "Malformed URL", dataSpec, - PlaybackException.ERROR_CODE_IO_BAD_HTTP_REQUEST, + PlaybackException.ERROR_CODE_FAILED_RUNTIME_CHECK, HttpDataSourceException.TYPE_OPEN); } diff --git a/library/common/src/main/java/com/google/android/exoplayer2/PlaybackException.java b/library/common/src/main/java/com/google/android/exoplayer2/PlaybackException.java index 60e73c656b..1a3369aa5a 100644 --- a/library/common/src/main/java/com/google/android/exoplayer2/PlaybackException.java +++ b/library/common/src/main/java/com/google/android/exoplayer2/PlaybackException.java @@ -46,6 +46,7 @@ public class PlaybackException extends Exception implements Bundleable { ERROR_CODE_REMOTE_ERROR, ERROR_CODE_BEHIND_LIVE_WINDOW, ERROR_CODE_TIMEOUT, + ERROR_CODE_FAILED_RUNTIME_CHECK, ERROR_CODE_IO_UNSPECIFIED, ERROR_CODE_IO_NETWORK_UNAVAILABLE, ERROR_CODE_IO_NETWORK_CONNECTION_FAILED, @@ -94,6 +95,13 @@ public class PlaybackException extends Exception implements Bundleable { public static final int ERROR_CODE_BEHIND_LIVE_WINDOW = 1002; /** Caused by a generic timeout. */ public static final int ERROR_CODE_TIMEOUT = 1003; + /** + * Caused by a failed runtime check. + * + *

This can happen when the application fails to comply with the player's API requirements (for + * example, by passing invalid arguments), or when the player reaches an invalid state. + */ + public static final int ERROR_CODE_FAILED_RUNTIME_CHECK = 1004; // Input/Output errors (2xxx). @@ -217,6 +225,8 @@ public class PlaybackException extends Exception implements Bundleable { return "ERROR_CODE_BEHIND_LIVE_WINDOW"; case ERROR_CODE_TIMEOUT: return "ERROR_CODE_TIMEOUT"; + case ERROR_CODE_FAILED_RUNTIME_CHECK: + return "ERROR_CODE_FAILED_RUNTIME_CHECK"; case ERROR_CODE_IO_UNSPECIFIED: return "ERROR_CODE_IO_UNSPECIFIED"; case ERROR_CODE_IO_NETWORK_UNAVAILABLE: diff --git a/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java b/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java index 27e6fd6b0e..a497f20b09 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java @@ -599,7 +599,13 @@ import java.util.concurrent.atomic.AtomicBoolean; } catch (IOException e) { handleIoException(e, PlaybackException.ERROR_CODE_IO_UNSPECIFIED); } catch (RuntimeException e) { - ExoPlaybackException error = ExoPlaybackException.createForUnexpected(e); + @ErrorCode int errorCode; + if (e instanceof IllegalStateException || e instanceof IllegalArgumentException) { + errorCode = PlaybackException.ERROR_CODE_FAILED_RUNTIME_CHECK; + } else { + errorCode = PlaybackException.ERROR_CODE_UNSPECIFIED; + } + ExoPlaybackException error = ExoPlaybackException.createForUnexpected(e, errorCode); Log.e(TAG, "Playback error", error); stopInternal(/* forceResetRenderers= */ true, /* acknowledgeStop= */ false); playbackInfo = playbackInfo.copyWithPlaybackError(error);