Commit 50da6d87 by Karol Wrótniak
parent 8caad492
package com.google.android.exoplayer2.upstream;
final class AndroidDataSourceConstants {
static final long SAMPLE_MP4_BYTES = 101597;
static final String SAMPLE_MP4_PATH = "/mp4/sample.mp4";
private AndroidDataSourceConstants() {}
}
...@@ -4,10 +4,10 @@ import android.content.Context; ...@@ -4,10 +4,10 @@ import android.content.Context;
import android.net.Uri; import android.net.Uri;
import android.test.InstrumentationTestCase; import android.test.InstrumentationTestCase;
public class AndroidDataSourceTest extends InstrumentationTestCase { import static com.google.android.exoplayer2.upstream.AndroidDataSourceConstants.SAMPLE_MP4_BYTES;
import static com.google.android.exoplayer2.upstream.AndroidDataSourceConstants.SAMPLE_MP4_PATH;
private static final long SAMPLE_MP4_BYTES = 101597; public class AssetDataSourceTest extends InstrumentationTestCase {
private static final String SAMPLE_MP4_PATH = "/mp4/sample.mp4";
public void testAssetDataSource() throws Exception { public void testAssetDataSource() throws Exception {
final Context context = getInstrumentation().getContext(); final Context context = getInstrumentation().getContext();
...@@ -18,14 +18,4 @@ public class AndroidDataSourceTest extends InstrumentationTestCase { ...@@ -18,14 +18,4 @@ public class AndroidDataSourceTest extends InstrumentationTestCase {
assertEquals(SAMPLE_MP4_BYTES, sourceLengthBytes); assertEquals(SAMPLE_MP4_BYTES, sourceLengthBytes);
} }
public void testContentDataSource() throws Exception {
Context context = getInstrumentation().getContext();
ContentDataSource dataSource = new ContentDataSource(context);
Uri contentUri = Uri.parse("content://exoplayer" + SAMPLE_MP4_PATH);
DataSpec dataSpec = new DataSpec(contentUri);
long sourceLengthBytes = dataSource.open(dataSpec);
assertEquals(SAMPLE_MP4_BYTES, sourceLengthBytes);
}
} }
package com.google.android.exoplayer2.upstream;
import android.content.Context;
import android.net.Uri;
import android.test.InstrumentationTestCase;
import static com.google.android.exoplayer2.upstream.AndroidDataSourceConstants.SAMPLE_MP4_BYTES;
import static com.google.android.exoplayer2.upstream.AndroidDataSourceConstants.SAMPLE_MP4_PATH;
public class ContentDataSourceTest extends InstrumentationTestCase {
public void testContentDataSource() throws Exception {
Context context = getInstrumentation().getContext();
ContentDataSource dataSource = new ContentDataSource(context);
Uri contentUri = Uri.parse("content://exoplayer" + SAMPLE_MP4_PATH);
DataSpec dataSpec = new DataSpec(contentUri);
long sourceLengthBytes = dataSource.open(dataSpec);
assertEquals(SAMPLE_MP4_BYTES, sourceLengthBytes);
}
}
...@@ -71,7 +71,7 @@ public final class ContentDataSource implements DataSource { ...@@ -71,7 +71,7 @@ public final class ContentDataSource implements DataSource {
try { try {
uri = dataSpec.uri; uri = dataSpec.uri;
assetFileDescriptor = resolver.openAssetFileDescriptor(uri, "r"); assetFileDescriptor = resolver.openAssetFileDescriptor(uri, "r");
inputStream = assetFileDescriptor.createInputStream(); inputStream = new FileInputStream(assetFileDescriptor.getFileDescriptor());
long skipped = inputStream.skip(dataSpec.position); long skipped = inputStream.skip(dataSpec.position);
if (skipped < dataSpec.position) { if (skipped < dataSpec.position) {
// We expect the skip to be satisfied in full. If it isn't then we're probably trying to // We expect the skip to be satisfied in full. If it isn't then we're probably trying to
...@@ -81,12 +81,16 @@ public final class ContentDataSource implements DataSource { ...@@ -81,12 +81,16 @@ public final class ContentDataSource implements DataSource {
if (dataSpec.length != C.LENGTH_UNSET) { if (dataSpec.length != C.LENGTH_UNSET) {
bytesRemaining = dataSpec.length; bytesRemaining = dataSpec.length;
} else { } else {
bytesRemaining = inputStream.available(); bytesRemaining = assetFileDescriptor.getLength();
if (bytesRemaining == 0) { if (bytesRemaining == AssetFileDescriptor.UNKNOWN_LENGTH) {
// FileInputStream.available() returns 0 if the remaining length cannot be determined, or // The asset must extend to the end of the file.
// if it's greater than Integer.MAX_VALUE. We don't know the true length in either case, bytesRemaining = inputStream.available();
// so treat as unbounded. if (bytesRemaining == 0) {
bytesRemaining = C.LENGTH_UNSET; // FileInputStream.available() returns 0 if the remaining length cannot be determined, or
// if it's greater than Integer.MAX_VALUE. We don't know the true length in either case,
// so treat as unbounded.
bytesRemaining = C.LENGTH_UNSET;
}
} }
} }
} catch (IOException e) { } catch (IOException e) {
......
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