From 29eeff9ff7fd42710b892db91f782dede1f3560a Mon Sep 17 00:00:00 2001 From: aquilescanta Date: Fri, 4 Jun 2021 11:47:42 +0100 Subject: [PATCH] Assign error codes to FileDataSourceExceptions PiperOrigin-RevId: 377481210 --- .../android/exoplayer2/ExoPlayerImplInternal.java | 11 +++++++++++ .../android/exoplayer2/upstream/FileDataSource.java | 4 ++-- 2 files changed, 13 insertions(+), 2 deletions(-) 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 0cdfcdf72f..efad26f53c 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 @@ -46,6 +46,7 @@ import com.google.android.exoplayer2.trackselection.ExoTrackSelection; import com.google.android.exoplayer2.trackselection.TrackSelector; import com.google.android.exoplayer2.trackselection.TrackSelectorResult; import com.google.android.exoplayer2.upstream.BandwidthMeter; +import com.google.android.exoplayer2.upstream.FileDataSource; import com.google.android.exoplayer2.upstream.HttpDataSource; import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.Clock; @@ -55,6 +56,7 @@ import com.google.android.exoplayer2.util.TraceUtil; import com.google.android.exoplayer2.util.Util; import com.google.common.base.Supplier; import com.google.common.collect.ImmutableList; +import java.io.FileNotFoundException; import java.io.IOException; import java.util.ArrayList; import java.util.Collections; @@ -572,6 +574,15 @@ import java.util.concurrent.atomic.AtomicBoolean; stopInternal(/* forceResetRenderers= */ true, /* acknowledgeStop= */ false); playbackInfo = playbackInfo.copyWithPlaybackError(e); } + } catch (FileDataSource.FileDataSourceException e) { + @Nullable Throwable cause = e.getCause(); + int errorCode = PlaybackException.ERROR_CODE_IO_UNSPECIFIED; + if (cause instanceof FileNotFoundException) { + errorCode = PlaybackException.ERROR_CODE_IO_FILE_NOT_FOUND; + } else if (cause instanceof SecurityException) { + errorCode = PlaybackException.ERROR_CODE_IO_NO_PERMISSION; + } + handleIoException(e, errorCode); } catch (ParserException e) { int errorCode = PlaybackException.ERROR_CODE_UNSPECIFIED; if (e.dataType == C.DATA_TYPE_MEDIA) { diff --git a/library/core/src/main/java/com/google/android/exoplayer2/upstream/FileDataSource.java b/library/core/src/main/java/com/google/android/exoplayer2/upstream/FileDataSource.java index 47debf2767..282ea02dc4 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/upstream/FileDataSource.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/upstream/FileDataSource.java @@ -33,7 +33,7 @@ public final class FileDataSource extends BaseDataSource { /** Thrown when a {@link FileDataSource} encounters an error reading a file. */ public static class FileDataSourceException extends IOException { - public FileDataSourceException(IOException cause) { + public FileDataSourceException(Exception cause) { super(cause); } @@ -94,7 +94,7 @@ public final class FileDataSource extends BaseDataSource { } } catch (FileDataSourceException e) { throw e; - } catch (IOException e) { + } catch (Exception e) { throw new FileDataSourceException(e); }