Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
SDK
/
exoplayer
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
795e3be4
authored
Jun 19, 2017
by
Karol Wrótniak
Committed by
Oliver Woodman
Jun 30, 2017
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
null AssetFileDescriptors support added in `ContentDataSource`
parent
66c461e6
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
2 deletions
library/core/src/androidTest/java/com/google/android/exoplayer2/upstream/AndroidDataSourceConstants.java
library/core/src/androidTest/java/com/google/android/exoplayer2/upstream/ContentDataSourceTest.java
library/core/src/androidTest/java/com/google/android/exoplayer2/upstream/TestDataProvider.java
library/core/src/main/java/com/google/android/exoplayer2/upstream/ContentDataSource.java
library/core/src/androidTest/java/com/google/android/exoplayer2/upstream/AndroidDataSourceConstants.java
View file @
795e3be4
package
com
.
google
.
android
.
exoplayer2
.
upstream
;
package
com
.
google
.
android
.
exoplayer2
.
upstream
;
import
android.content.ContentResolver
;
import
android.net.Uri
;
final
class
AndroidDataSourceConstants
{
final
class
AndroidDataSourceConstants
{
static
final
long
SAMPLE_MP4_BYTES
=
101597
;
static
final
long
SAMPLE_MP4_BYTES
=
101597
;
static
final
String
SAMPLE_MP4_PATH
=
"/mp4/sample.mp4"
;
static
final
String
SAMPLE_MP4_PATH
=
"/mp4/sample.mp4"
;
static
final
String
TEST_DATA_PROVIDER_AUTHORITY
=
"exoplayer"
;
static
final
Uri
NULL_DESCRIPTOR_URI
=
new
Uri
.
Builder
()
.
scheme
(
ContentResolver
.
SCHEME_CONTENT
)
.
authority
(
TEST_DATA_PROVIDER_AUTHORITY
)
.
build
();
private
AndroidDataSourceConstants
()
{}
private
AndroidDataSourceConstants
()
{}
}
}
library/core/src/androidTest/java/com/google/android/exoplayer2/upstream/ContentDataSourceTest.java
View file @
795e3be4
package
com
.
google
.
android
.
exoplayer2
.
upstream
;
package
com
.
google
.
android
.
exoplayer2
.
upstream
;
import
android.content.ContentResolver
;
import
android.content.Context
;
import
android.content.Context
;
import
android.net.Uri
;
import
android.net.Uri
;
import
android.test.InstrumentationTestCase
;
import
android.test.InstrumentationTestCase
;
import
static
com
.
google
.
android
.
exoplayer2
.
upstream
.
AndroidDataSourceConstants
.
NULL_DESCRIPTOR_URI
;
import
static
com
.
google
.
android
.
exoplayer2
.
upstream
.
AndroidDataSourceConstants
.
SAMPLE_MP4_BYTES
;
import
static
com
.
google
.
android
.
exoplayer2
.
upstream
.
AndroidDataSourceConstants
.
SAMPLE_MP4_BYTES
;
import
static
com
.
google
.
android
.
exoplayer2
.
upstream
.
AndroidDataSourceConstants
.
SAMPLE_MP4_PATH
;
import
static
com
.
google
.
android
.
exoplayer2
.
upstream
.
AndroidDataSourceConstants
.
SAMPLE_MP4_PATH
;
import
static
com
.
google
.
android
.
exoplayer2
.
upstream
.
AndroidDataSourceConstants
.
TEST_DATA_PROVIDER_AUTHORITY
;
public
class
ContentDataSourceTest
extends
InstrumentationTestCase
{
public
class
ContentDataSourceTest
extends
InstrumentationTestCase
{
public
void
testContentDataSource
()
throws
Exception
{
public
void
test
Valid
ContentDataSource
()
throws
Exception
{
Context
context
=
getInstrumentation
().
getContext
();
Context
context
=
getInstrumentation
().
getContext
();
ContentDataSource
dataSource
=
new
ContentDataSource
(
context
);
ContentDataSource
dataSource
=
new
ContentDataSource
(
context
);
Uri
contentUri
=
Uri
.
parse
(
"content://exoplayer"
+
SAMPLE_MP4_PATH
);
Uri
contentUri
=
new
Uri
.
Builder
()
.
scheme
(
ContentResolver
.
SCHEME_CONTENT
)
.
authority
(
TEST_DATA_PROVIDER_AUTHORITY
)
.
path
(
SAMPLE_MP4_PATH
).
build
();
DataSpec
dataSpec
=
new
DataSpec
(
contentUri
);
DataSpec
dataSpec
=
new
DataSpec
(
contentUri
);
long
sourceLengthBytes
=
dataSource
.
open
(
dataSpec
);
long
sourceLengthBytes
=
dataSource
.
open
(
dataSpec
);
assertEquals
(
SAMPLE_MP4_BYTES
,
sourceLengthBytes
);
assertEquals
(
SAMPLE_MP4_BYTES
,
sourceLengthBytes
);
}
}
public
void
testNullContentDataSource
()
throws
Exception
{
Context
context
=
getInstrumentation
().
getContext
();
ContentDataSource
dataSource
=
new
ContentDataSource
(
context
);
DataSpec
dataSpec
=
new
DataSpec
(
NULL_DESCRIPTOR_URI
);
try
{
dataSource
.
open
(
dataSpec
);
fail
(
"Expected exception not thrown."
);
}
catch
(
ContentDataSource
.
ContentDataSourceException
e
)
{
// Expected.
}
}
}
}
library/core/src/androidTest/java/com/google/android/exoplayer2/upstream/TestDataProvider.java
View file @
795e3be4
...
@@ -29,6 +29,10 @@ public class TestDataProvider extends ContentProvider {
...
@@ -29,6 +29,10 @@ public class TestDataProvider extends ContentProvider {
@Nullable
@Nullable
@Override
@Override
public
AssetFileDescriptor
openAssetFile
(
@NonNull
final
Uri
uri
,
@NonNull
final
String
mode
)
throws
FileNotFoundException
{
public
AssetFileDescriptor
openAssetFile
(
@NonNull
final
Uri
uri
,
@NonNull
final
String
mode
)
throws
FileNotFoundException
{
if
(
uri
.
equals
(
AndroidDataSourceConstants
.
NULL_DESCRIPTOR_URI
))
{
return
null
;
}
try
{
try
{
Context
context
=
getContext
();
Context
context
=
getContext
();
assertNotNull
(
context
);
assertNotNull
(
context
);
...
...
library/core/src/main/java/com/google/android/exoplayer2/upstream/ContentDataSource.java
View file @
795e3be4
...
@@ -22,6 +22,7 @@ import android.net.Uri;
...
@@ -22,6 +22,7 @@ import android.net.Uri;
import
com.google.android.exoplayer2.C
;
import
com.google.android.exoplayer2.C
;
import
java.io.EOFException
;
import
java.io.EOFException
;
import
java.io.FileInputStream
;
import
java.io.FileInputStream
;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStream
;
...
@@ -71,6 +72,9 @@ public final class ContentDataSource implements DataSource {
...
@@ -71,6 +72,9 @@ public final class ContentDataSource implements DataSource {
try
{
try
{
uri
=
dataSpec
.
uri
;
uri
=
dataSpec
.
uri
;
assetFileDescriptor
=
resolver
.
openAssetFileDescriptor
(
uri
,
"r"
);
assetFileDescriptor
=
resolver
.
openAssetFileDescriptor
(
uri
,
"r"
);
if
(
assetFileDescriptor
==
null
)
{
throw
new
FileNotFoundException
(
"Could not open file descriptor for: "
+
uri
);
}
inputStream
=
new
FileInputStream
(
assetFileDescriptor
.
getFileDescriptor
());
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
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment