Back to Exoplayer

DownloadManager (ExoPlayer library)

docs/doc/reference/com/google/android/exoplayer2/offline/DownloadManager.html

latest18.6 KB
Original Source

Package com.google.android.exoplayer2.offline

Class DownloadManager


[@Deprecated](https://developer.android.com/reference/java/lang/Deprecated.html "class or interface in java.lang")public final classDownloadManagerextends[Object](https://developer.android.com/reference/java/lang/Object.html "class or interface in java.lang")

Deprecated. com.google.android.exoplayer2 is deprecated. Please migrate to androidx.media3 (which contains the same ExoPlayer code). See the migration guide for more details, including a script to help with the migration.

Manages downloads.

Normally a download manager should be accessed via a DownloadService. When a download manager is used directly instead, downloads will be initially paused and so must be resumed by calling resumeDownloads().

A download manager instance must be accessed only from the thread that created it, unless that thread does not have a Looper. In that case, it must be accessed only from the application's main thread. Registered listeners will be called on the same thread. In all cases the Looper of the thread from which the manager must be accessed can be queried using getApplicationLooper().

Nested Class Summary

Nested Classes | Modifier and Type | Class | Description | | --- | --- | --- | | static interface | DownloadManager.Listener | Deprecated.

Listener for DownloadManager events. |

Field Summary

Fields | Modifier and Type | Field | Description | | --- | --- | --- | | static int | DEFAULT_MAX_PARALLEL_DOWNLOADS | Deprecated.

The default maximum number of parallel downloads. | | static int | DEFAULT_MIN_RETRY_COUNT | Deprecated.

The default minimum number of times a download must be retried before failing. | | static Requirements | DEFAULT_REQUIREMENTS | Deprecated.

The default requirement is that the device has network connectivity. |

Constructor Summary

Constructors | Constructor | Description | | --- | --- | | DownloadManager​(Context context, DatabaseProvider databaseProvider, Cache cache, DataSource.Factory upstreamFactory, Executor executor) | Deprecated.

Constructs a DownloadManager. | | DownloadManager​(Context context, WritableDownloadIndex downloadIndex, DownloaderFactory downloaderFactory) | Deprecated.

Constructs a DownloadManager. |

Method Summary

All Methods Instance Methods Concrete Methods Deprecated Methods | Modifier and Type | Method | Description | | --- | --- | --- | | void | addDownload​(DownloadRequest request) | Deprecated.

Adds a download defined by the given request. | | void | addDownload​(DownloadRequest request, int stopReason) | Deprecated.

Adds a download defined by the given request and with the specified stop reason. | | void | addListener​(DownloadManager.Listener listener) | Deprecated.

Adds a DownloadManager.Listener. | | Looper | getApplicationLooper() | Deprecated.

Returns the Looper associated with the application thread that's used to access the manager, and on which the manager will call its Listeners. | | List<Download> | getCurrentDownloads() | Deprecated.

Returns current downloads. | | DownloadIndex | getDownloadIndex() | Deprecated.

Returns the used DownloadIndex. | | boolean | getDownloadsPaused() | Deprecated.

Returns whether downloads are currently paused. | | int | getMaxParallelDownloads() | Deprecated.

Returns the maximum number of parallel downloads. | | int | getMinRetryCount() | Deprecated.

Returns the minimum number of times that a download will be retried. | | @com.google.android.exoplayer2.scheduler.Requirements.RequirementFlags int | getNotMetRequirements() | Deprecated.

Returns the requirements needed for downloads to progress that are not currently met. | | Requirements | getRequirements() | Deprecated.

Returns the requirements needed to be met to progress. | | boolean | isIdle() | Deprecated.

Returns whether the manager is currently idle. | | boolean | isInitialized() | Deprecated.

Returns whether the manager has completed initialization. | | boolean | isWaitingForRequirements() | Deprecated.

Returns whether this manager has one or more downloads that are not progressing for the sole reason that the Requirements are not met. | | void | pauseDownloads() | Deprecated.

Pauses downloads. | | void | release() | Deprecated.

Stops the downloads and releases resources. | | void | removeAllDownloads() | Deprecated.

Cancels all pending downloads and removes all downloaded data. | | void | removeDownload​(String id) | Deprecated.

Cancels the download with the id and removes all downloaded data. | | void | removeListener​(DownloadManager.Listener listener) | Deprecated.

Removes a DownloadManager.Listener. | | void | resumeDownloads() | Deprecated.

Resumes downloads. | | void | setMaxParallelDownloads​(int maxParallelDownloads) | Deprecated.

Sets the maximum number of parallel downloads. | | void | setMinRetryCount​(int minRetryCount) | Deprecated.

Sets the minimum number of times that a download will be retried. | | void | setRequirements​(Requirements requirements) | Deprecated.

Sets the requirements that need to be met for downloads to progress. | | void | setStopReason​(String id, int stopReason) | Deprecated.

Sets the stop reason for one or all downloads. |

- 

Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Detail

- 

DEFAULT_MAX_PARALLEL_DOWNLOADS

public static final int DEFAULT_MAX_PARALLEL_DOWNLOADS

Deprecated.

The default maximum number of parallel downloads. See Also:Constant Field Values

- 

DEFAULT_MIN_RETRY_COUNT

public static final int DEFAULT_MIN_RETRY_COUNT

Deprecated.

The default minimum number of times a download must be retried before failing. See Also:Constant Field Values

- 

DEFAULT_REQUIREMENTS

public static final[Requirements](../scheduler/Requirements.html "class in com.google.android.exoplayer2.scheduler")DEFAULT_REQUIREMENTS

Deprecated.

The default requirement is that the device has network connectivity.

Constructor Detail

- 

DownloadManager

public DownloadManager​([Context](https://developer.android.com/reference/android/content/Context.html "class or interface in android.content")context,[DatabaseProvider](../database/DatabaseProvider.html "interface in com.google.android.exoplayer2.database")databaseProvider,[Cache](../upstream/cache/Cache.html "interface in com.google.android.exoplayer2.upstream.cache")cache,[DataSource.Factory](../upstream/DataSource.Factory.html "interface in com.google.android.exoplayer2.upstream")upstreamFactory,[Executor](https://developer.android.com/reference/java/util/concurrent/Executor.html "class or interface in java.util.concurrent")executor)

Deprecated.

Constructs a DownloadManager. Parameters:context - Any context.databaseProvider - Provides the SQLite database in which downloads are persisted.cache - A cache to be used to store downloaded data. The cache should be configured with an CacheEvictor that will not evict downloaded content, for example NoOpCacheEvictor.upstreamFactory - A DataSource.Factory for creating DataSources for downloading data.executor - An Executor used to download data. Passing Runnable::run will cause each download task to download data on its own thread. Passing an Executor that uses multiple threads will speed up download tasks that can be split into smaller parts for parallel execution.

- 

DownloadManager

public DownloadManager​([Context](https://developer.android.com/reference/android/content/Context.html "class or interface in android.content")context,[WritableDownloadIndex](WritableDownloadIndex.html "interface in com.google.android.exoplayer2.offline")downloadIndex,[DownloaderFactory](DownloaderFactory.html "interface in com.google.android.exoplayer2.offline")downloaderFactory)

Deprecated.

Constructs a DownloadManager. Parameters:context - Any context.downloadIndex - The download index used to hold the download information.downloaderFactory - A factory for creating Downloaders.

Method Detail

- 

getApplicationLooper

public[Looper](https://developer.android.com/reference/android/os/Looper.html "class or interface in android.os")getApplicationLooper()

Deprecated.

Returns the Looper associated with the application thread that's used to access the manager, and on which the manager will call its Listeners.

- 

isInitialized

public boolean isInitialized()

Deprecated.

Returns whether the manager has completed initialization.

- 

isIdle

public boolean isIdle()

Deprecated.

Returns whether the manager is currently idle. The manager is idle if all downloads are in a terminal state (i.e. completed or failed), or if no progress can be made (e.g. because the download requirements are not met).

- 

isWaitingForRequirements

public boolean isWaitingForRequirements()

Deprecated.

Returns whether this manager has one or more downloads that are not progressing for the sole reason that the Requirements are not met. This is true if: - The Requirements are not met. - The downloads are not paused (i.e. getDownloadsPaused() is false). - There are downloads in the queued state.

- 

addListener

public void addListener​([DownloadManager.Listener](DownloadManager.Listener.html "interface in com.google.android.exoplayer2.offline")listener)

Deprecated.

Adds a DownloadManager.Listener. Parameters:listener - The listener to be added.

- 

removeListener

public void removeListener​([DownloadManager.Listener](DownloadManager.Listener.html "interface in com.google.android.exoplayer2.offline")listener)

Deprecated.

Removes a DownloadManager.Listener. Parameters:listener - The listener to be removed.

- 

getRequirements

public[Requirements](../scheduler/Requirements.html "class in com.google.android.exoplayer2.scheduler")getRequirements()

Deprecated.

Returns the requirements needed to be met to progress.

- 

getNotMetRequirements

[@RequirementFlags](../scheduler/Requirements.RequirementFlags.html "annotation in com.google.android.exoplayer2.scheduler")public @com.google.android.exoplayer2.scheduler.Requirements.RequirementFlags int getNotMetRequirements()

Deprecated.

Returns the requirements needed for downloads to progress that are not currently met. Returns:The not met Requirements.RequirementFlags, or 0 if all requirements are met.

- 

setRequirements

public void setRequirements​([Requirements](../scheduler/Requirements.html "class in com.google.android.exoplayer2.scheduler")requirements)

Deprecated.

Sets the requirements that need to be met for downloads to progress. Parameters:requirements - A Requirements.

- 

getMaxParallelDownloads

public int getMaxParallelDownloads()

Deprecated.

Returns the maximum number of parallel downloads.

- 

setMaxParallelDownloads

public void setMaxParallelDownloads​(@IntRange(from=1L)
                                    int maxParallelDownloads)

Deprecated.

Sets the maximum number of parallel downloads. Parameters:maxParallelDownloads - The maximum number of parallel downloads. Must be greater than 0.

- 

getMinRetryCount

public int getMinRetryCount()

Deprecated.

Returns the minimum number of times that a download will be retried. A download will fail if the specified number of retries is exceeded without any progress being made.

- 

setMinRetryCount

public void setMinRetryCount​(int minRetryCount)

Deprecated.

Sets the minimum number of times that a download will be retried. A download will fail if the specified number of retries is exceeded without any progress being made. Parameters:minRetryCount - The minimum number of times that a download will be retried.

- 

getDownloadIndex

public[DownloadIndex](DownloadIndex.html "interface in com.google.android.exoplayer2.offline")getDownloadIndex()

Deprecated.

Returns the used DownloadIndex.

- 

getCurrentDownloads

public[List](https://developer.android.com/reference/java/util/List.html "class or interface in java.util")<[Download](Download.html "class in com.google.android.exoplayer2.offline")> getCurrentDownloads()

Deprecated.

Returns current downloads. Downloads that are in terminal states (i.e. completed or failed) are not included. To query all downloads including those in terminal states, use getDownloadIndex() instead.

- 

getDownloadsPaused

public boolean getDownloadsPaused()

Deprecated.

Returns whether downloads are currently paused.

- 

resumeDownloads

public void resumeDownloads()

Deprecated.

Resumes downloads.

If the Requirements are met up to maxParallelDownloads will be started, excluding those with non-zero stopReasons.

- 

pauseDownloads

public void pauseDownloads()

Deprecated.

Pauses downloads. Downloads that would otherwise be making progress will transition to Download.STATE_QUEUED.

- 

setStopReason

public void setStopReason​(@Nullable[String](https://developer.android.com/reference/java/lang/String.html "class or interface in java.lang")id,
                          int stopReason)

Deprecated.

Sets the stop reason for one or all downloads. To clear the stop reason, pass Download.STOP_REASON_NONE. Parameters:id - The content id of the download to update, or null to set the stop reason for all downloads.stopReason - The stop reason, or Download.STOP_REASON_NONE.

- 

addDownload

public void addDownload​([DownloadRequest](DownloadRequest.html "class in com.google.android.exoplayer2.offline")request)

Deprecated.

Adds a download defined by the given request. Parameters:request - The download request.

- 

addDownload

public void addDownload​([DownloadRequest](DownloadRequest.html "class in com.google.android.exoplayer2.offline")request,
                        int stopReason)

Deprecated.

Adds a download defined by the given request and with the specified stop reason. Parameters:request - The download request.stopReason - An initial stop reason for the download, or Download.STOP_REASON_NONE if the download should be started.

- 

removeDownload

public void removeDownload​([String](https://developer.android.com/reference/java/lang/String.html "class or interface in java.lang")id)

Deprecated.

Cancels the download with the id and removes all downloaded data. Parameters:id - The unique content id of the download to be started.

- 

removeAllDownloads

public void removeAllDownloads()

Deprecated.

Cancels all pending downloads and removes all downloaded data.

- 

release

public void release()

Deprecated.

Stops the downloads and releases resources. Waits until the downloads are persisted to the download index. The manager must not be accessed after this method has been called.