Class DefaultDownloadIndex
- java.lang.Object
-
- com.google.android.exoplayer2.offline.DefaultDownloadIndex
-
- All Implemented Interfaces:
DownloadIndex
,WritableDownloadIndex
public final class DefaultDownloadIndex extends Object implements WritableDownloadIndex
ADownloadIndex
that uses SQLite to persistDownloads
.
-
-
Constructor Summary
Constructors Constructor Description DefaultDownloadIndex(DatabaseProvider databaseProvider)
Creates an instance that stores theDownloads
in an SQLite database provided by aDatabaseProvider
.DefaultDownloadIndex(DatabaseProvider databaseProvider, String name)
Creates an instance that stores theDownloads
in an SQLite database provided by aDatabaseProvider
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Download
getDownload(String id)
Returns theDownload
with the givenid
, or null.DownloadCursor
getDownloads(int... states)
void
putDownload(Download download)
Adds or replaces aDownload
.void
removeDownload(String id)
Removes the download with the given ID.void
setDownloadingStatesToQueued()
Sets allDownload.STATE_DOWNLOADING
states toDownload.STATE_QUEUED
.void
setStatesToRemoving()
Sets all states toDownload.STATE_REMOVING
.void
setStopReason(int stopReason)
Sets the stop reason of the downloads in a terminal state (Download.STATE_COMPLETED
,Download.STATE_FAILED
).void
setStopReason(String id, int stopReason)
Sets the stop reason of the download with the given ID in a terminal state (Download.STATE_COMPLETED
,Download.STATE_FAILED
).
-
-
-
Constructor Detail
-
DefaultDownloadIndex
public DefaultDownloadIndex(DatabaseProvider databaseProvider)
Creates an instance that stores theDownloads
in an SQLite database provided by aDatabaseProvider
.Equivalent to calling
DefaultDownloadIndex(DatabaseProvider, String)
withname=""
.Applications that only have one download index may use this constructor. Applications that have multiple download indices should call
DefaultDownloadIndex(DatabaseProvider, String)
to specify a unique name for each index.- Parameters:
databaseProvider
- Provides the SQLite database in which downloads are persisted.
-
DefaultDownloadIndex
public DefaultDownloadIndex(DatabaseProvider databaseProvider, String name)
Creates an instance that stores theDownloads
in an SQLite database provided by aDatabaseProvider
.- Parameters:
databaseProvider
- Provides the SQLite database in which downloads are persisted.name
- The name of the index. This name is incorporated into the names of the SQLite tables in which downloads are persisted.
-
-
Method Detail
-
getDownload
@Nullable public Download getDownload(String id) throws DatabaseIOException
Description copied from interface:DownloadIndex
Returns theDownload
with the givenid
, or null.This method may be slow and shouldn't normally be called on the main thread.
- Specified by:
getDownload
in interfaceDownloadIndex
- Parameters:
id
- ID of aDownload
.- Returns:
- The
Download
with the givenid
, or null if a download state with this id doesn't exist. - Throws:
DatabaseIOException
-
getDownloads
public DownloadCursor getDownloads(@State int... states) throws DatabaseIOException
Description copied from interface:DownloadIndex
Returns aDownloadCursor
toDownload
s with the givenstates
.This method may be slow and shouldn't normally be called on the main thread.
- Specified by:
getDownloads
in interfaceDownloadIndex
- Parameters:
states
- Returns only theDownload
s with this states. If empty, returns all.- Returns:
- A cursor to
Download
s with the givenstates
. - Throws:
DatabaseIOException
-
putDownload
public void putDownload(Download download) throws DatabaseIOException
Description copied from interface:WritableDownloadIndex
Adds or replaces aDownload
.This method may be slow and shouldn't normally be called on the main thread.
- Specified by:
putDownload
in interfaceWritableDownloadIndex
- Parameters:
download
- TheDownload
to be added.- Throws:
DatabaseIOException
-
removeDownload
public void removeDownload(String id) throws DatabaseIOException
Description copied from interface:WritableDownloadIndex
Removes the download with the given ID. Does nothing if a download with the given ID does not exist.This method may be slow and shouldn't normally be called on the main thread.
- Specified by:
removeDownload
in interfaceWritableDownloadIndex
- Parameters:
id
- The ID of the download to remove.- Throws:
DatabaseIOException
-
setDownloadingStatesToQueued
public void setDownloadingStatesToQueued() throws DatabaseIOException
Description copied from interface:WritableDownloadIndex
Sets allDownload.STATE_DOWNLOADING
states toDownload.STATE_QUEUED
.This method may be slow and shouldn't normally be called on the main thread.
- Specified by:
setDownloadingStatesToQueued
in interfaceWritableDownloadIndex
- Throws:
DatabaseIOException
-
setStatesToRemoving
public void setStatesToRemoving() throws DatabaseIOException
Description copied from interface:WritableDownloadIndex
Sets all states toDownload.STATE_REMOVING
.This method may be slow and shouldn't normally be called on the main thread.
- Specified by:
setStatesToRemoving
in interfaceWritableDownloadIndex
- Throws:
DatabaseIOException
-
setStopReason
public void setStopReason(int stopReason) throws DatabaseIOException
Description copied from interface:WritableDownloadIndex
Sets the stop reason of the downloads in a terminal state (Download.STATE_COMPLETED
,Download.STATE_FAILED
).This method may be slow and shouldn't normally be called on the main thread.
- Specified by:
setStopReason
in interfaceWritableDownloadIndex
- Parameters:
stopReason
- The stop reason.- Throws:
DatabaseIOException
-
setStopReason
public void setStopReason(String id, int stopReason) throws DatabaseIOException
Description copied from interface:WritableDownloadIndex
Sets the stop reason of the download with the given ID in a terminal state (Download.STATE_COMPLETED
,Download.STATE_FAILED
). Does nothing if a download with the given ID does not exist, or if it's not in a terminal state.This method may be slow and shouldn't normally be called on the main thread.
- Specified by:
setStopReason
in interfaceWritableDownloadIndex
- Parameters:
id
- The ID of the download to update.stopReason
- The stop reason.- Throws:
DatabaseIOException
-
-