From ef7dd697b15e8b6b76992ba1516f831f3af1ad30 Mon Sep 17 00:00:00 2001 From: olly Date: Wed, 24 Aug 2016 08:05:38 -0700 Subject: [PATCH] Fix ContentDataSource handling of AssetFileDescriptor Also tweak how the null checks happen in a few DataSource implementations (should be no-op changes, but allow you to look at close() and be happy it does the right thing without having to loop at the open() implementations). Issue: #1759 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=131172427 --- .../exoplayer2/upstream/AssetDataSource.java | 22 +++++++++---------- .../upstream/ContentDataSource.java | 20 ++++++++++++----- .../exoplayer2/upstream/FileDataSource.java | 22 +++++++++---------- 3 files changed, 37 insertions(+), 27 deletions(-) diff --git a/library/src/main/java/com/google/android/exoplayer2/upstream/AssetDataSource.java b/library/src/main/java/com/google/android/exoplayer2/upstream/AssetDataSource.java index ff7ea42d4d7..1a685ca1af0 100644 --- a/library/src/main/java/com/google/android/exoplayer2/upstream/AssetDataSource.java +++ b/library/src/main/java/com/google/android/exoplayer2/upstream/AssetDataSource.java @@ -137,18 +137,18 @@ public Uri getUri() { @Override public void close() throws AssetDataSourceException { uri = null; - if (inputStream != null) { - try { + try { + if (inputStream != null) { inputStream.close(); - } catch (IOException e) { - throw new AssetDataSourceException(e); - } finally { - inputStream = null; - if (opened) { - opened = false; - if (listener != null) { - listener.onTransferEnd(this); - } + } + } catch (IOException e) { + throw new AssetDataSourceException(e); + } finally { + inputStream = null; + if (opened) { + opened = false; + if (listener != null) { + listener.onTransferEnd(this); } } } diff --git a/library/src/main/java/com/google/android/exoplayer2/upstream/ContentDataSource.java b/library/src/main/java/com/google/android/exoplayer2/upstream/ContentDataSource.java index 838a7970dc3..2a0ad014897 100644 --- a/library/src/main/java/com/google/android/exoplayer2/upstream/ContentDataSource.java +++ b/library/src/main/java/com/google/android/exoplayer2/upstream/ContentDataSource.java @@ -45,6 +45,7 @@ public ContentDataSourceException(IOException cause) { private final TransferListener listener; private Uri uri; + private AssetFileDescriptor assetFileDescriptor; private InputStream inputStream; private long bytesRemaining; private boolean opened; @@ -69,8 +70,8 @@ public ContentDataSource(Context context, TransferListener