Android OpenTV Player SDK  4.23.3.1610362082
DownloadManager Class Reference

Public Member Functions

boolean registerDownloadStateListener (IDownloadListener xListener)
 Registers an IDownloadListener object to the DownloadManager. More...
 
boolean unregisterDownloadStateListener (IDownloadListener xListener)
 Unregisters an IDownloadListener interface from the DownloadManager. More...
 
boolean setStorage (String xPath)
 Provide the storage area to the DownloadManager. More...
 
String getStorage ()
 Retrieve the storage area currently in use by the DownloadManager. More...
 
String registerDownload (String xUrl)
 Registers an asset download to the DownloadManager via its URL. More...
 
Download [] getDownloads ()
 Returns all downloads currently registered in the DownloadManager. More...
 
Download getDownloadByUUID (String xUUID)
 Returns the download registered to the DownloadManager matching the UUID specified in parameter. More...
 
Download [] getDownloadByContentId (String xContentId)
 Returns all downloads matching the Content ID specified in parameter. More...
 
boolean removeDownload (String xUUID)
 Removes the download specified in parameter. More...
 
boolean startDownload (String xUUID, int xBitrate)
 Starts the download specified in parameter. More...
 
boolean pauseDownload (String xUUID)
 Pauses the running download specified in parameter. More...
 
boolean resumeDownload (String xUUID)
 Resumes the paused download specified in parameter. More...
 
void setPrivateMetadata (String xUUID, String xMetadata)
 Associate a private string to the download. More...
 
String getPrivateMetadata (String xUUID)
 Returns the private string previously associated to the download. More...
 

Detailed Description

This class offers the downloading and the storage management of adaptive streaming assets.

The client application can register, start, pause or remove the download of assets. Information pertaining to the downloads can be queried. The queries extract snapshots of the downloads in the form of one or more Download objects.

Before usage, the DownloadManager must be provided with a storage path and an IDownloadListener interfacing object. Once the path has been set and one IDownloadListener has been registered, the client application can start registering downloads. Downloads registered to the DownloadManager will immediately attempt to access the network and retrieve metadata pertaining to the asset requested, but the raw media data will not be downloaded before the download is explicitly started by the client application.

The preparing and downloading are driven by the callbacks of IDownloadListener.

Objects of this class can be instantiated multiple times, but all instances will point to a single underlying database maintaining all ongoing or finished downloads. The lifecycle of downloads are directly linked to the DownloadManager.

The DownloadManager currently supports the following adaptive streaming protocols and protocol versions :

  • HTTP Live Streaming, up to protocol version 5

To setup the DownloadManager, the client application must do the following :

DownloadManager manager = new DownloadManager();
manager.setStorage("/path/to/my/desired/storage");
manager.registerDownloadStateListener(myListener);
...

The DownloadManager can also be configured to perform metadata refreshes when a download items is resumed, enabling this functionality can be useful where the remote content is load balanced and the ideal server may have changed since the download was paused. By default, this functionality is disabled. To do this, the client application must do the following :

DownloadManager manager = new DownloadManager(context, true); // true parameter added
manager.setStorage("/path/to/my/desired/storage");
manager.registerDownloadStateListener(myListener);
...

To create a download and start it, the client application can do the following :

String contentURL = "http://somewhere.out.there/on/a/cdn/index.m3u8";
String uuid = manager.registerDownload(contentURL);
manager.setPrivateData(uuid, MyPrivateJSONString);
manager.startDownload(uuid);
...
See also
Download
IDownloadListener

Member Function Documentation

◆ getDownloadByContentId()

Download [] getDownloadByContentId ( String  xContentId)

Returns all downloads matching the Content ID specified in parameter.

Parameters
xContentIdContent ID of the download
Returns
A collection of Download objects. The collection will be empty if not found.

◆ getDownloadByUUID()

Download getDownloadByUUID ( String  xUUID)

Returns the download registered to the DownloadManager matching the UUID specified in parameter.

Parameters
xUUIDUniversal Unique ID of the download
Returns
A Download object or null if not found.

◆ getDownloads()

Download [] getDownloads ( )

Returns all downloads currently registered in the DownloadManager.

Returns
A collection of Download objects.

◆ getPrivateMetadata()

String getPrivateMetadata ( String  xUUID)

Returns the private string previously associated to the download.

Parameters
xUUIDUniversal Unique ID of the download
Returns
the private string previously associated, null if no string has ever been set.

◆ getStorage()

String getStorage ( )

Retrieve the storage area currently in use by the DownloadManager.

Returns
xPath - Path where the DownloadManager shall store all assets.

◆ pauseDownload()

boolean pauseDownload ( String  xUUID)

Pauses the running download specified in parameter.

The download will change to the STATE_PAUSED state.

Parameters
xUUIDUniversal Unique ID of the download
Returns
true if the action succeeded; false otherwise.

◆ registerDownload()

String registerDownload ( String  xUrl)

Registers an asset download to the DownloadManager via its URL.

Parameters
xUrlThe URL to the master playlist of an adaptive streaming asset.
Returns
The Universal Unique ID attributed to the download, or null if the download could not be registered.

◆ registerDownloadStateListener()

boolean registerDownloadStateListener ( IDownloadListener  xListener)

Registers an IDownloadListener object to the DownloadManager.

All callbacks coming from the DownloadManager will be fired on this interface.

Parameters
xListenerIDownloadListener interfacing object to register
Returns
true if the action succeeded; false otherwise.

◆ removeDownload()

boolean removeDownload ( String  xUUID)

Removes the download specified in parameter.

The download will disappear from the list of downloads and be unregistered from DownloadManager. onDownloadRemoved() will be fired when effective.

Parameters
xUUIDUniversal Unique ID of the download
Returns
true if the action succeeded; false if the UUID does not exist or there is no permission to remove the download (Android M onwards).

◆ resumeDownload()

boolean resumeDownload ( String  xUUID)

Resumes the paused download specified in parameter.

The download will change to the STATE_RUNNING state.

Parameters
xUUIDUniversal Unique ID of the download
Returns
true if the action succeeded; false if the UUID does not exist or there is no permission to remove the download (Android M onwards).

◆ setPrivateMetadata()

void setPrivateMetadata ( String  xUUID,
String  xMetadata 
)

Associate a private string to the download.

This allows the client application to associate applicative data with the download. The format is at the developer's convenience. (JSON, XML, ...)

Parameters
xUUIDUniversal Unique ID of the download
xMetadataString to associate to the download

◆ setStorage()

boolean setStorage ( String  xPath)

Provide the storage area to the DownloadManager.

This URL should not change over time. If the application developer wishes to move it, it must copy that directory and set a new storage path to the DownloadManager while no downloads are active.

Parameters
xPathPath where the DownloadManager shall store all assets.
Returns
true if the action succeeded; false otherwise. Failure reasons can include: Wrong formatting of the path.

◆ startDownload()

boolean startDownload ( String  xUUID,
int  xBitrate 
)

Starts the download specified in parameter.

The download will change to the STATE_RUNNING state.

Parameters
xUUIDUniversal Unique ID of the download
xBitrateThe consumption bitrate to use with the download. Only bitrates found in MediaInfo objects are eligible.
Returns
true if the action succeeded; false if the UUID does not exist or there is no permission to remove the download (Android M onwards).

◆ unregisterDownloadStateListener()

boolean unregisterDownloadStateListener ( IDownloadListener  xListener)

Unregisters an IDownloadListener interface from the DownloadManager.

Parameters
xListenerIDownloadListener interfacing object to unregister
Returns
true if the action succeeded; false otherwise.