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
f8592054
authored
Oct 27, 2014
by
Oliver Woodman
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Let FileDataSource report to a TransferListener.
parent
b8415dba
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
2 deletions
library/src/main/java/com/google/android/exoplayer/upstream/FileDataSource.java
library/src/main/java/com/google/android/exoplayer/upstream/FileDataSource.java
View file @
f8592054
...
@@ -36,8 +36,27 @@ public final class FileDataSource implements DataSource {
...
@@ -36,8 +36,27 @@ public final class FileDataSource implements DataSource {
}
}
private
final
TransferListener
listener
;
private
RandomAccessFile
file
;
private
RandomAccessFile
file
;
private
long
bytesRemaining
;
private
long
bytesRemaining
;
private
boolean
opened
;
/**
* Constructs a new {@link DataSource} that retrieves data from a file.
*/
public
FileDataSource
()
{
this
(
null
);
}
/**
* Constructs a new {@link DataSource} that retrieves data from a file.
*
* @param listener An optional listener. Specify {@code null} for no listener.
*/
public
FileDataSource
(
TransferListener
listener
)
{
this
.
listener
=
listener
;
}
@Override
@Override
public
long
open
(
DataSpec
dataSpec
)
throws
FileDataSourceException
{
public
long
open
(
DataSpec
dataSpec
)
throws
FileDataSourceException
{
...
@@ -46,10 +65,16 @@ public final class FileDataSource implements DataSource {
...
@@ -46,10 +65,16 @@ public final class FileDataSource implements DataSource {
file
.
seek
(
dataSpec
.
position
);
file
.
seek
(
dataSpec
.
position
);
bytesRemaining
=
dataSpec
.
length
==
C
.
LENGTH_UNBOUNDED
?
file
.
length
()
-
dataSpec
.
position
bytesRemaining
=
dataSpec
.
length
==
C
.
LENGTH_UNBOUNDED
?
file
.
length
()
-
dataSpec
.
position
:
dataSpec
.
length
;
:
dataSpec
.
length
;
return
bytesRemaining
;
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
throw
new
FileDataSourceException
(
e
);
throw
new
FileDataSourceException
(
e
);
}
}
opened
=
true
;
if
(
listener
!=
null
)
{
listener
.
onTransferStart
();
}
return
bytesRemaining
;
}
}
@Override
@Override
...
@@ -63,7 +88,14 @@ public final class FileDataSource implements DataSource {
...
@@ -63,7 +88,14 @@ public final class FileDataSource implements DataSource {
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
throw
new
FileDataSourceException
(
e
);
throw
new
FileDataSourceException
(
e
);
}
}
if
(
bytesRead
>
0
)
{
bytesRemaining
-=
bytesRead
;
bytesRemaining
-=
bytesRead
;
if
(
listener
!=
null
)
{
listener
.
onBytesTransferred
(
bytesRead
);
}
}
return
bytesRead
;
return
bytesRead
;
}
}
}
}
...
@@ -75,8 +107,16 @@ public final class FileDataSource implements DataSource {
...
@@ -75,8 +107,16 @@ public final class FileDataSource implements DataSource {
file
.
close
();
file
.
close
();
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
throw
new
FileDataSourceException
(
e
);
throw
new
FileDataSourceException
(
e
);
}
}
finally
{
file
=
null
;
file
=
null
;
if
(
opened
)
{
opened
=
false
;
if
(
listener
!=
null
)
{
listener
.
onTransferEnd
();
}
}
}
}
}
}
}
...
...
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