mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Comments from https://github.com/google/ExoPlayer/pull/2963#discussion_r122669328 applied
This commit is contained in:
parent
8caad492d4
commit
50da6d870c
5 changed files with 61 additions and 38 deletions
|
|
@ -0,0 +1,8 @@
|
||||||
|
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() {}
|
||||||
|
}
|
||||||
|
|
@ -1,31 +0,0 @@
|
||||||
package com.google.android.exoplayer2.upstream;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.net.Uri;
|
|
||||||
import android.test.InstrumentationTestCase;
|
|
||||||
|
|
||||||
public class AndroidDataSourceTest extends InstrumentationTestCase {
|
|
||||||
|
|
||||||
private static final long SAMPLE_MP4_BYTES = 101597;
|
|
||||||
private static final String SAMPLE_MP4_PATH = "/mp4/sample.mp4";
|
|
||||||
|
|
||||||
public void testAssetDataSource() throws Exception {
|
|
||||||
final Context context = getInstrumentation().getContext();
|
|
||||||
AssetDataSource dataSource = new AssetDataSource(context);
|
|
||||||
Uri assetUri = Uri.parse("file:///android_asset" + SAMPLE_MP4_PATH);
|
|
||||||
DataSpec dataSpec = new DataSpec(assetUri);
|
|
||||||
long sourceLengthBytes = dataSource.open(dataSpec);
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -0,0 +1,21 @@
|
||||||
|
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 AssetDataSourceTest extends InstrumentationTestCase {
|
||||||
|
|
||||||
|
public void testAssetDataSource() throws Exception {
|
||||||
|
final Context context = getInstrumentation().getContext();
|
||||||
|
AssetDataSource dataSource = new AssetDataSource(context);
|
||||||
|
Uri assetUri = Uri.parse("file:///android_asset" + SAMPLE_MP4_PATH);
|
||||||
|
DataSpec dataSpec = new DataSpec(assetUri);
|
||||||
|
long sourceLengthBytes = dataSource.open(dataSpec);
|
||||||
|
|
||||||
|
assertEquals(SAMPLE_MP4_BYTES, sourceLengthBytes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,21 @@
|
||||||
|
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 {
|
||||||
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 {
|
||||||
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) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue