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
500b1faf
authored
Dec 03, 2018
by
eguven
Committed by
Oliver Woodman
Dec 04, 2018
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Add Downloader.getTotalBytes() method
PiperOrigin-RevId: 223787832
parent
9f1e32f1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
38 additions
and
5 deletions
library/core/src/main/java/com/google/android/exoplayer2/offline/Downloader.java
library/core/src/main/java/com/google/android/exoplayer2/offline/ProgressiveDownloader.java
library/core/src/main/java/com/google/android/exoplayer2/offline/SegmentDownloader.java
library/core/src/test/java/com/google/android/exoplayer2/offline/DownloadManagerTest.java
library/core/src/main/java/com/google/android/exoplayer2/offline/Downloader.java
View file @
500b1faf
...
@@ -38,6 +38,9 @@ public interface Downloader {
...
@@ -38,6 +38,9 @@ public interface Downloader {
/** Returns the total number of downloaded bytes. */
/** Returns the total number of downloaded bytes. */
long
getDownloadedBytes
();
long
getDownloadedBytes
();
/** Returns the total size of the media, or {@link C#LENGTH_UNSET} if unknown. */
long
getTotalBytes
();
/**
/**
* Returns the estimated download percentage, or {@link C#PERCENTAGE_UNSET} if no estimate is
* Returns the estimated download percentage, or {@link C#PERCENTAGE_UNSET} if no estimate is
* available.
* available.
...
...
library/core/src/main/java/com/google/android/exoplayer2/offline/ProgressiveDownloader.java
View file @
500b1faf
...
@@ -87,6 +87,11 @@ public final class ProgressiveDownloader implements Downloader {
...
@@ -87,6 +87,11 @@ public final class ProgressiveDownloader implements Downloader {
}
}
@Override
@Override
public
long
getTotalBytes
()
{
return
cachingCounters
.
contentLength
;
}
@Override
public
float
getDownloadPercentage
()
{
public
float
getDownloadPercentage
()
{
long
contentLength
=
cachingCounters
.
contentLength
;
long
contentLength
=
cachingCounters
.
contentLength
;
return
contentLength
==
C
.
LENGTH_UNSET
return
contentLength
==
C
.
LENGTH_UNSET
...
...
library/core/src/main/java/com/google/android/exoplayer2/offline/SegmentDownloader.java
View file @
500b1faf
...
@@ -72,6 +72,7 @@ public abstract class SegmentDownloader<M extends FilterableManifest<M>> impleme
...
@@ -72,6 +72,7 @@ public abstract class SegmentDownloader<M extends FilterableManifest<M>> impleme
private
volatile
int
totalSegments
;
private
volatile
int
totalSegments
;
private
volatile
int
downloadedSegments
;
private
volatile
int
downloadedSegments
;
private
volatile
long
downloadedBytes
;
private
volatile
long
downloadedBytes
;
private
volatile
long
totalBytes
;
/**
/**
* @param manifestUri The {@link Uri} of the manifest to be downloaded.
* @param manifestUri The {@link Uri} of the manifest to be downloaded.
...
@@ -88,6 +89,7 @@ public abstract class SegmentDownloader<M extends FilterableManifest<M>> impleme
...
@@ -88,6 +89,7 @@ public abstract class SegmentDownloader<M extends FilterableManifest<M>> impleme
this
.
offlineDataSource
=
constructorHelper
.
createOfflineCacheDataSource
();
this
.
offlineDataSource
=
constructorHelper
.
createOfflineCacheDataSource
();
this
.
priorityTaskManager
=
constructorHelper
.
getPriorityTaskManager
();
this
.
priorityTaskManager
=
constructorHelper
.
getPriorityTaskManager
();
totalSegments
=
C
.
LENGTH_UNSET
;
totalSegments
=
C
.
LENGTH_UNSET
;
totalBytes
=
C
.
LENGTH_UNSET
;
isCanceled
=
new
AtomicBoolean
();
isCanceled
=
new
AtomicBoolean
();
}
}
...
@@ -143,8 +145,17 @@ public abstract class SegmentDownloader<M extends FilterableManifest<M>> impleme
...
@@ -143,8 +145,17 @@ public abstract class SegmentDownloader<M extends FilterableManifest<M>> impleme
}
}
@Override
@Override
public
long
getTotalBytes
()
{
return
totalBytes
;
}
@Override
public
final
float
getDownloadPercentage
()
{
public
final
float
getDownloadPercentage
()
{
// Take local snapshot of the volatile fields
// Take local snapshot of the volatile fields
long
totalBytes
=
this
.
totalBytes
;
if
(
totalBytes
!=
C
.
LENGTH_UNSET
)
{
return
totalBytes
==
0
?
100
f
:
(
downloadedBytes
*
100
f
)
/
totalBytes
;
}
int
totalSegments
=
this
.
totalSegments
;
int
totalSegments
=
this
.
totalSegments
;
int
downloadedSegments
=
this
.
downloadedSegments
;
int
downloadedSegments
=
this
.
downloadedSegments
;
if
(
totalSegments
==
C
.
LENGTH_UNSET
||
downloadedSegments
==
C
.
LENGTH_UNSET
)
{
if
(
totalSegments
==
C
.
LENGTH_UNSET
||
downloadedSegments
==
C
.
LENGTH_UNSET
)
{
...
@@ -211,16 +222,25 @@ public abstract class SegmentDownloader<M extends FilterableManifest<M>> impleme
...
@@ -211,16 +222,25 @@ public abstract class SegmentDownloader<M extends FilterableManifest<M>> impleme
totalSegments
=
segments
.
size
();
totalSegments
=
segments
.
size
();
downloadedSegments
=
0
;
downloadedSegments
=
0
;
downloadedBytes
=
0
;
downloadedBytes
=
0
;
long
totalBytes
=
0
;
for
(
int
i
=
segments
.
size
()
-
1
;
i
>=
0
;
i
--)
{
for
(
int
i
=
segments
.
size
()
-
1
;
i
>=
0
;
i
--)
{
Segment
segment
=
segments
.
get
(
i
);
Segment
segment
=
segments
.
get
(
i
);
CacheUtil
.
getCached
(
segment
.
dataSpec
,
cache
,
cachingCounters
);
CacheUtil
.
getCached
(
segment
.
dataSpec
,
cache
,
cachingCounters
);
downloadedBytes
+=
cachingCounters
.
alreadyCachedBytes
;
downloadedBytes
+=
cachingCounters
.
alreadyCachedBytes
;
if
(
cachingCounters
.
alreadyCachedBytes
==
cachingCounters
.
contentLength
)
{
if
(
cachingCounters
.
contentLength
!=
C
.
LENGTH_UNSET
)
{
// The segment is fully downloaded.
if
(
cachingCounters
.
alreadyCachedBytes
==
cachingCounters
.
contentLength
)
{
downloadedSegments
++;
// The segment is fully downloaded.
segments
.
remove
(
i
);
downloadedSegments
++;
segments
.
remove
(
i
);
}
if
(
totalBytes
!=
C
.
LENGTH_UNSET
)
{
totalBytes
+=
cachingCounters
.
contentLength
;
}
}
else
{
totalBytes
=
C
.
LENGTH_UNSET
;
}
}
}
}
this
.
totalBytes
=
totalBytes
;
return
segments
;
return
segments
;
}
}
...
...
library/core/src/test/java/com/google/android/exoplayer2/offline/DownloadManagerTest.java
View file @
500b1faf
...
@@ -624,8 +624,13 @@ public class DownloadManagerTest {
...
@@ -624,8 +624,13 @@ public class DownloadManagerTest {
}
}
@Override
@Override
public
long
getTotalBytes
()
{
return
C
.
LENGTH_UNSET
;
}
@Override
public
float
getDownloadPercentage
()
{
public
float
getDownloadPercentage
()
{
return
Float
.
NaN
;
return
C
.
PERCENTAGE_UNSET
;
}
}
}
}
}
}
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