From 66c1aedeb37928bea144b8011abdffcc3ebbe964 Mon Sep 17 00:00:00 2001 From: aquilescanta Date: Tue, 18 May 2021 16:34:40 +0100 Subject: [PATCH] Assign ERROR_CODE_BEHIND_LIVE_WINDOW to BehindLiveWindowExceptions PiperOrigin-RevId: 374425179 --- .../exoplayer2/ExoPlaybackException.java | 13 +++++++++- .../exoplayer2/ExoPlayerImplInternal.java | 25 ++++++++++++------- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/library/common/src/main/java/com/google/android/exoplayer2/ExoPlaybackException.java b/library/common/src/main/java/com/google/android/exoplayer2/ExoPlaybackException.java index eddc4d6b12..024e876663 100644 --- a/library/common/src/main/java/com/google/android/exoplayer2/ExoPlaybackException.java +++ b/library/common/src/main/java/com/google/android/exoplayer2/ExoPlaybackException.java @@ -114,7 +114,18 @@ public final class ExoPlaybackException extends PlaybackException { * @return The created instance. */ public static ExoPlaybackException createForSource(IOException cause) { - return new ExoPlaybackException(TYPE_SOURCE, cause, ERROR_CODE_UNSPECIFIED); + return createForSource(cause, ERROR_CODE_UNSPECIFIED); + } + + /** + * Creates an instance of type {@link #TYPE_SOURCE}. + * + * @param cause The cause of the failure. + * @param errorCode See {@link #errorCode}. + * @return The created instance. + */ + public static ExoPlaybackException createForSource(IOException cause, int errorCode) { + return new ExoPlaybackException(TYPE_SOURCE, cause, errorCode); } /** 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 2d56499bd1..9f055fcf3a 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 @@ -35,6 +35,7 @@ import com.google.android.exoplayer2.Player.PlaybackSuppressionReason; import com.google.android.exoplayer2.Player.RepeatMode; import com.google.android.exoplayer2.analytics.AnalyticsCollector; import com.google.android.exoplayer2.metadata.Metadata; +import com.google.android.exoplayer2.source.BehindLiveWindowException; import com.google.android.exoplayer2.source.MediaPeriod; import com.google.android.exoplayer2.source.MediaSource.MediaPeriodId; import com.google.android.exoplayer2.source.SampleStream; @@ -570,16 +571,10 @@ import java.util.concurrent.atomic.AtomicBoolean; stopInternal(/* forceResetRenderers= */ true, /* acknowledgeStop= */ false); playbackInfo = playbackInfo.copyWithPlaybackError(e); } + } catch (BehindLiveWindowException e) { + handleIoException(e, PlaybackException.ERROR_CODE_BEHIND_LIVE_WINDOW); } catch (IOException e) { - ExoPlaybackException error = ExoPlaybackException.createForSource(e); - @Nullable MediaPeriodHolder playingPeriod = queue.getPlayingPeriod(); - if (playingPeriod != null) { - // We ensure that all IOException throwing methods are only executed for the playing period. - error = error.copyWithMediaPeriodId(playingPeriod.info.id); - } - Log.e(TAG, "Playback error", error); - stopInternal(/* forceResetRenderers= */ false, /* acknowledgeStop= */ false); - playbackInfo = playbackInfo.copyWithPlaybackError(error); + handleIoException(e, PlaybackException.ERROR_CODE_UNSPECIFIED); } catch (RuntimeException e) { ExoPlaybackException error = ExoPlaybackException.createForUnexpected(e); Log.e(TAG, "Playback error", error); @@ -592,6 +587,18 @@ import java.util.concurrent.atomic.AtomicBoolean; // Private methods. + private void handleIoException(IOException e, @PlaybackException.ErrorCode int errorCode) { + ExoPlaybackException error = ExoPlaybackException.createForSource(e, errorCode); + @Nullable MediaPeriodHolder playingPeriod = queue.getPlayingPeriod(); + if (playingPeriod != null) { + // We ensure that all IOException throwing methods are only executed for the playing period. + error = error.copyWithMediaPeriodId(playingPeriod.info.id); + } + Log.e(TAG, "Playback error", error); + stopInternal(/* forceResetRenderers= */ false, /* acknowledgeStop= */ false); + playbackInfo = playbackInfo.copyWithPlaybackError(error); + } + /** * Blocks the current thread until a condition becomes true or the specified amount of time has * elapsed.