Assign error codes to FileDataSourceExceptions

PiperOrigin-RevId: 377481210
This commit is contained in:
aquilescanta 2021-06-04 11:47:42 +01:00 committed by bachinger
parent 536f7c8dbe
commit 29eeff9ff7
2 changed files with 13 additions and 2 deletions

View file

@ -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) {

View file

@ -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);
}