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
5ea7424e
authored
May 01, 2015
by
Oliver Woodman
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Tidy up AssetDataSource.
parent
053e5b9f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
13 deletions
library/src/main/java/com/google/android/exoplayer/upstream/AssetDataSource.java
library/src/main/java/com/google/android/exoplayer/upstream/AssetDataSource.java
View file @
5ea7424e
...
@@ -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
;
...
@@ -52,7 +50,7 @@ public final class AssetDataSource implements DataSource {
...
@@ -52,7 +50,7 @@ public final class AssetDataSource implements DataSource {
* Constructs a new {@link DataSource} that retrieves data from a local asset.
* Constructs a new {@link DataSource} that retrieves data from a local asset.
*/
*/
public
AssetDataSource
(
AssetManager
assetManager
)
{
public
AssetDataSource
(
AssetManager
assetManager
)
{
this
(
assetManager
,
null
);
this
(
assetManager
,
null
);
}
}
/**
/**
...
@@ -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
);
}
}
...
@@ -114,12 +114,11 @@ public final class AssetDataSource implements DataSource {
...
@@ -114,12 +114,11 @@ public final class AssetDataSource implements DataSource {
public
void
close
()
throws
AssetDataSourceException
{
public
void
close
()
throws
AssetDataSourceException
{
if
(
assetInputStream
!=
null
)
{
if
(
assetInputStream
!=
null
)
{
try
{
try
{
assetInputStream
.
close
();
assetInputStream
.
close
();
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
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
)
{
...
...
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