Class DefaultDownloadIndex
- java.lang.Object
-
- com.google.android.exoplayer2.offline.DefaultDownloadIndex
-
- All Implemented Interfaces:
DownloadIndex,WritableDownloadIndex
public final class DefaultDownloadIndex extends Object implements WritableDownloadIndex
ADownloadIndexthat uses SQLite to persistDownloads.
-
-
Constructor Summary
Constructors Constructor Description DefaultDownloadIndex(DatabaseProvider databaseProvider)Creates an instance that stores theDownloadsin an SQLite database provided by aDatabaseProvider.DefaultDownloadIndex(DatabaseProvider databaseProvider, String name)Creates an instance that stores theDownloadsin an SQLite database provided by aDatabaseProvider.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description DownloadgetDownload(String id)Returns theDownloadwith the givenid, or null.DownloadCursorgetDownloads(int... states)voidputDownload(Download download)Adds or replaces aDownload.voidremoveDownload(String id)Removes the download with the given ID.voidsetDownloadingStatesToQueued()Sets allDownload.STATE_DOWNLOADINGstates toDownload.STATE_QUEUED.voidsetStatesToRemoving()Sets all states toDownload.STATE_REMOVING.voidsetStopReason(int stopReason)Sets the stop reason of the downloads in a terminal state (Download.STATE_COMPLETED,Download.STATE_FAILED).voidsetStopReason(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 theDownloadsin 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 theDownloadsin 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:DownloadIndexReturns theDownloadwith the givenid, or null.This method may be slow and shouldn't normally be called on the main thread.
- Specified by:
getDownloadin interfaceDownloadIndex- Parameters:
id- ID of aDownload.- Returns:
- The
Downloadwith 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:DownloadIndexReturns aDownloadCursortoDownloads with the givenstates.This method may be slow and shouldn't normally be called on the main thread.
- Specified by:
getDownloadsin interfaceDownloadIndex- Parameters:
states- Returns only theDownloads with this states. If empty, returns all.- Returns:
- A cursor to
Downloads with the givenstates. - Throws:
DatabaseIOException
-
putDownload
public void putDownload(Download download) throws DatabaseIOException
Description copied from interface:WritableDownloadIndexAdds or replaces aDownload.This method may be slow and shouldn't normally be called on the main thread.
- Specified by:
putDownloadin interfaceWritableDownloadIndex- Parameters:
download- TheDownloadto be added.- Throws:
DatabaseIOException
-
removeDownload
public void removeDownload(String id) throws DatabaseIOException
Description copied from interface:WritableDownloadIndexRemoves 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:
removeDownloadin interfaceWritableDownloadIndex- Parameters:
id- The ID of the download to remove.- Throws:
DatabaseIOException
-
setDownloadingStatesToQueued
public void setDownloadingStatesToQueued() throws DatabaseIOExceptionDescription copied from interface:WritableDownloadIndexSets allDownload.STATE_DOWNLOADINGstates toDownload.STATE_QUEUED.This method may be slow and shouldn't normally be called on the main thread.
- Specified by:
setDownloadingStatesToQueuedin interfaceWritableDownloadIndex- Throws:
DatabaseIOException
-
setStatesToRemoving
public void setStatesToRemoving() throws DatabaseIOExceptionDescription copied from interface:WritableDownloadIndexSets all states toDownload.STATE_REMOVING.This method may be slow and shouldn't normally be called on the main thread.
- Specified by:
setStatesToRemovingin interfaceWritableDownloadIndex- Throws:
DatabaseIOException
-
setStopReason
public void setStopReason(int stopReason) throws DatabaseIOExceptionDescription copied from interface:WritableDownloadIndexSets 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:
setStopReasonin interfaceWritableDownloadIndex- Parameters:
stopReason- The stop reason.- Throws:
DatabaseIOException
-
setStopReason
public void setStopReason(String id, int stopReason) throws DatabaseIOException
Description copied from interface:WritableDownloadIndexSets 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:
setStopReasonin interfaceWritableDownloadIndex- Parameters:
id- The ID of the download to update.stopReason- The stop reason.- Throws:
DatabaseIOException
-
-