Commit 5ea7424e by Oliver Woodman

Tidy up AssetDataSource.

parent 053e5b9f
...@@ -15,15 +15,13 @@ ...@@ -15,15 +15,13 @@
*/ */
package com.google.android.exoplayer.upstream; package com.google.android.exoplayer.upstream;
import java.io.EOFException; import com.google.android.exoplayer.C;
import java.io.IOException;
import java.io.InputStream;
import android.content.res.AssetManager; import android.content.res.AssetManager;
import android.util.Log;
import com.google.android.exoplayer.C; import java.io.EOFException;
import com.google.android.exoplayer.upstream.FileDataSource.FileDataSourceException; import java.io.IOException;
import java.io.InputStream;
/** /**
* A local asset {@link DataSource}. * A local asset {@link DataSource}.
...@@ -41,10 +39,10 @@ public final class AssetDataSource implements DataSource { ...@@ -41,10 +39,10 @@ public final class AssetDataSource implements DataSource {
} }
private final AssetManager assetManager;
private final TransferListener listener; private final TransferListener listener;
private InputStream assetInputStream; private InputStream assetInputStream;
private AssetManager assetManager;
private long bytesRemaining; private long bytesRemaining;
private boolean opened; private boolean opened;
...@@ -69,7 +67,8 @@ public final class AssetDataSource implements DataSource { ...@@ -69,7 +67,8 @@ public final class AssetDataSource implements DataSource {
public long open(DataSpec dataSpec) throws AssetDataSourceException { public long open(DataSpec dataSpec) throws AssetDataSourceException {
try { try {
// Lose the '/' prefix in the path or else AssetManager won't find our file // Lose the '/' prefix in the path or else AssetManager won't find our file
assetInputStream = assetManager.open(dataSpec.uri.getPath().substring(1), AssetManager.ACCESS_RANDOM); assetInputStream = assetManager.open(dataSpec.uri.getPath().substring(1),
AssetManager.ACCESS_RANDOM);
assetInputStream.skip(dataSpec.position); assetInputStream.skip(dataSpec.position);
bytesRemaining = dataSpec.length == C.LENGTH_UNBOUNDED ? assetInputStream.available() bytesRemaining = dataSpec.length == C.LENGTH_UNBOUNDED ? assetInputStream.available()
: dataSpec.length; : dataSpec.length;
...@@ -94,7 +93,8 @@ public final class AssetDataSource implements DataSource { ...@@ -94,7 +93,8 @@ public final class AssetDataSource implements DataSource {
} else { } else {
int bytesRead = 0; int bytesRead = 0;
try { try {
bytesRead = assetInputStream.read(buffer, offset, (int) Math.min(bytesRemaining, readLength)); bytesRead = assetInputStream.read(buffer, offset,
(int) Math.min(bytesRemaining, readLength));
} catch (IOException e) { } catch (IOException e) {
throw new AssetDataSourceException(e); throw new AssetDataSourceException(e);
} }
...@@ -119,7 +119,6 @@ public final class AssetDataSource implements DataSource { ...@@ -119,7 +119,6 @@ public final class AssetDataSource implements DataSource {
throw new AssetDataSourceException(e); throw new AssetDataSourceException(e);
} finally { } finally {
assetInputStream = null; assetInputStream = null;
if (opened) { if (opened) {
opened = false; opened = false;
if (listener != null) { if (listener != null) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment