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
28ea31cd
authored
Mar 28, 2019
by
tonihei
Committed by
Toni
Mar 29, 2019
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Use Closeable interface for DownloadStateCursor to simplify closing.
PiperOrigin-RevId: 240775823
parent
e8cf67c0
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
20 deletions
demos/main/src/main/java/com/google/android/exoplayer2/demo/DownloadTracker.java
library/core/src/main/java/com/google/android/exoplayer2/offline/DownloadManager.java
library/core/src/main/java/com/google/android/exoplayer2/offline/DownloadStateCursor.java
demos/main/src/main/java/com/google/android/exoplayer2/demo/DownloadTracker.java
View file @
28ea31cd
...
...
@@ -140,13 +140,11 @@ public class DownloadTracker implements DownloadManager.Listener {
// Internal methods
private
void
loadDownloads
()
{
try
{
DownloadStateCursor
loadedDownloadStates
=
downloadIndex
.
getDownloadStates
();
try
(
DownloadStateCursor
loadedDownloadStates
=
downloadIndex
.
getDownloadStates
())
{
while
(
loadedDownloadStates
.
moveToNext
())
{
DownloadState
downloadState
=
loadedDownloadStates
.
getDownloadState
();
downloadStates
.
put
(
downloadState
.
uri
,
downloadState
);
}
loadedDownloadStates
.
close
();
}
catch
(
IOException
e
)
{
Log
.
w
(
TAG
,
"Failed to query download states"
,
e
);
}
...
...
library/core/src/main/java/com/google/android/exoplayer2/offline/DownloadManager.java
View file @
28ea31cd
...
...
@@ -601,15 +601,13 @@ public final class DownloadManager {
fileIOHandler
.
post
(
()
->
{
DownloadState
[]
loadedStates
;
DownloadStateCursor
cursor
=
null
;
try
{
cursor
=
downloadIndex
.
getDownloadStates
(
STATE_QUEUED
,
STATE_STOPPED
,
STATE_DOWNLOADING
,
STATE_REMOVING
,
STATE_RESTARTING
);
try
(
DownloadStateCursor
cursor
=
downloadIndex
.
getDownloadStates
(
STATE_QUEUED
,
STATE_STOPPED
,
STATE_DOWNLOADING
,
STATE_REMOVING
,
STATE_RESTARTING
))
{
loadedStates
=
new
DownloadState
[
cursor
.
getCount
()];
for
(
int
i
=
0
,
length
=
loadedStates
.
length
;
i
<
length
;
i
++)
{
cursor
.
moveToNext
();
...
...
@@ -619,10 +617,6 @@ public final class DownloadManager {
}
catch
(
Throwable
e
)
{
Log
.
e
(
TAG
,
"Download state loading failed."
,
e
);
loadedStates
=
new
DownloadState
[
0
];
}
finally
{
if
(
cursor
!=
null
)
{
cursor
.
close
();
}
}
final
DownloadState
[]
states
=
loadedStates
;
handler
.
post
(
...
...
library/core/src/main/java/com/google/android/exoplayer2/offline/DownloadStateCursor.java
View file @
28ea31cd
...
...
@@ -15,8 +15,10 @@
*/
package
com
.
google
.
android
.
exoplayer2
.
offline
;
import
java.io.Closeable
;
/** Provides random read-write access to the result set returned by a database query. */
public
interface
DownloadStateCursor
{
public
interface
DownloadStateCursor
extends
Closeable
{
/** Returns the DownloadState at the current position. */
DownloadState
getDownloadState
();
...
...
@@ -119,9 +121,9 @@ public interface DownloadStateCursor {
return
getPosition
()
==
getCount
();
}
/** Closes the Cursor, releasing all of its resources and making it completely invalid. */
void
close
();
/** Returns whether the cursor is closed */
boolean
isClosed
();
@Override
void
close
();
}
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