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
ea0efa74
authored
May 01, 2019
by
olly
Committed by
Oliver Woodman
May 02, 2019
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Periodically persist progress to index whilst downloading
PiperOrigin-RevId: 246173972
parent
eed5d957
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
9 deletions
library/core/src/main/java/com/google/android/exoplayer2/offline/DownloadManager.java
library/core/src/main/java/com/google/android/exoplayer2/offline/DownloadService.java
library/core/src/main/java/com/google/android/exoplayer2/offline/DownloadManager.java
View file @
ea0efa74
...
...
@@ -134,7 +134,8 @@ public final class DownloadManager {
private
static
final
int
MSG_REMOVE_DOWNLOAD
=
7
;
private
static
final
int
MSG_TASK_STOPPED
=
8
;
private
static
final
int
MSG_CONTENT_LENGTH_CHANGED
=
9
;
private
static
final
int
MSG_RELEASE
=
10
;
private
static
final
int
MSG_UPDATE_PROGRESS
=
10
;
private
static
final
int
MSG_RELEASE
=
11
;
private
static
final
String
TAG
=
"DownloadManager"
;
...
...
@@ -569,6 +570,8 @@ public final class DownloadManager {
private
static
final
class
InternalHandler
extends
Handler
{
private
static
final
int
UPDATE_PROGRESS_INTERVAL_MS
=
5000
;
public
boolean
released
;
private
final
HandlerThread
thread
;
...
...
@@ -650,11 +653,13 @@ public final class DownloadManager {
case
MSG_CONTENT_LENGTH_CHANGED:
task
=
(
Task
)
message
.
obj
;
onContentLengthChanged
(
task
);
processedExternalMessage
=
false
;
// This message is posted internally.
break
;
return
;
// No need to post back to mainHandler.
case
MSG_UPDATE_PROGRESS:
updateProgress
();
return
;
// No need to post back to mainHandler.
case
MSG_RELEASE:
release
();
return
;
//
Don't post back to mainHandler on release
.
return
;
//
No need to post back to mainHandler
.
default
:
throw
new
IllegalStateException
();
}
...
...
@@ -868,7 +873,9 @@ public final class DownloadManager {
minRetryCount
,
/* internalHandler= */
this
);
activeTasks
.
put
(
download
.
request
.
id
,
activeTask
);
activeDownloadTaskCount
++;
if
(
activeDownloadTaskCount
++
==
0
)
{
sendEmptyMessageDelayed
(
MSG_UPDATE_PROGRESS
,
UPDATE_PROGRESS_INTERVAL_MS
);
}
activeTask
.
start
();
return
activeTask
;
}
...
...
@@ -933,8 +940,8 @@ public final class DownloadManager {
activeTasks
.
remove
(
downloadId
);
boolean
isRemove
=
task
.
isRemove
;
if
(!
isRemove
)
{
activeDownloadTaskCount
--
;
if
(!
isRemove
&&
--
activeDownloadTaskCount
==
0
)
{
removeMessages
(
MSG_UPDATE_PROGRESS
)
;
}
if
(
task
.
isCanceled
)
{
...
...
@@ -1013,6 +1020,22 @@ public final class DownloadManager {
}
}
// Progress updates.
private
void
updateProgress
()
{
for
(
int
i
=
0
;
i
<
downloads
.
size
();
i
++)
{
Download
download
=
downloads
.
get
(
i
);
if
(
download
.
state
==
STATE_DOWNLOADING
)
{
try
{
downloadIndex
.
putDownload
(
download
);
}
catch
(
IOException
e
)
{
Log
.
e
(
TAG
,
"Failed to update index."
,
e
);
}
}
}
sendEmptyMessageDelayed
(
MSG_UPDATE_PROGRESS
,
UPDATE_PROGRESS_INTERVAL_MS
);
}
// Helper methods.
private
boolean
canDownloadsRun
()
{
...
...
library/core/src/main/java/com/google/android/exoplayer2/offline/DownloadService.java
View file @
ea0efa74
...
...
@@ -683,7 +683,7 @@ public abstract class DownloadService extends Service {
// Do nothing.
}
private
void
notifyDownloadChange
(
Download
download
)
{
private
void
notifyDownloadChange
d
(
Download
download
)
{
onDownloadChanged
(
download
);
if
(
foregroundNotificationUpdater
!=
null
)
{
if
(
download
.
state
==
Download
.
STATE_DOWNLOADING
...
...
@@ -834,7 +834,7 @@ public abstract class DownloadService extends Service {
@Override
public
void
onDownloadChanged
(
DownloadManager
downloadManager
,
Download
download
)
{
if
(
downloadService
!=
null
)
{
downloadService
.
notifyDownloadChange
(
download
);
downloadService
.
notifyDownloadChange
d
(
download
);
}
}
...
...
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