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
50da6d87
authored
Jun 19, 2017
by
Karol Wrótniak
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Comments from
https://github.com/google/ExoPlayer/pull/2963#discussion_r122669328
applied
parent
8caad492
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
43 additions
and
20 deletions
library/core/src/androidTest/java/com/google/android/exoplayer2/upstream/AndroidDataSourceConstants.java
library/core/src/androidTest/java/com/google/android/exoplayer2/upstream/AndroidDataSourceTest.java → library/core/src/androidTest/java/com/google/android/exoplayer2/upstream/AssetDataSourceTest.java
library/core/src/androidTest/java/com/google/android/exoplayer2/upstream/ContentDataSourceTest.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
0 → 100644
View file @
50da6d87
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
()
{}
}
library/core/src/androidTest/java/com/google/android/exoplayer2/upstream/A
ndroid
DataSourceTest.java
→
library/core/src/androidTest/java/com/google/android/exoplayer2/upstream/A
sset
DataSourceTest.java
View file @
50da6d87
...
...
@@ -4,10 +4,10 @@ import android.content.Context;
import
android.net.Uri
;
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
;
private
static
final
String
SAMPLE_MP4_PATH
=
"/mp4/sample.mp4"
;
public
class
AssetDataSourceTest
extends
InstrumentationTestCase
{
public
void
testAssetDataSource
()
throws
Exception
{
final
Context
context
=
getInstrumentation
().
getContext
();
...
...
@@ -18,14 +18,4 @@ public class AndroidDataSourceTest extends InstrumentationTestCase {
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
);
}
}
library/core/src/androidTest/java/com/google/android/exoplayer2/upstream/ContentDataSourceTest.java
0 → 100644
View file @
50da6d87
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
);
}
}
library/core/src/main/java/com/google/android/exoplayer2/upstream/ContentDataSource.java
View file @
50da6d87
...
...
@@ -71,7 +71,7 @@ public final class ContentDataSource implements DataSource {
try
{
uri
=
dataSpec
.
uri
;
assetFileDescriptor
=
resolver
.
openAssetFileDescriptor
(
uri
,
"r"
);
inputStream
=
assetFileDescriptor
.
createInputStream
(
);
inputStream
=
new
FileInputStream
(
assetFileDescriptor
.
getFileDescriptor
()
);
long
skipped
=
inputStream
.
skip
(
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
...
...
@@ -81,12 +81,16 @@ public final class ContentDataSource implements DataSource {
if
(
dataSpec
.
length
!=
C
.
LENGTH_UNSET
)
{
bytesRemaining
=
dataSpec
.
length
;
}
else
{
bytesRemaining
=
inputStream
.
available
();
if
(
bytesRemaining
==
0
)
{
// 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
;
bytesRemaining
=
assetFileDescriptor
.
getLength
();
if
(
bytesRemaining
==
AssetFileDescriptor
.
UNKNOWN_LENGTH
)
{
// The asset must extend to the end of the file.
bytesRemaining
=
inputStream
.
available
();
if
(
bytesRemaining
==
0
)
{
// 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
)
{
...
...
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