Skip to main content
Skip table of contents

Registering the download

The register download operation shown in the diagram below outlines how an application must first register an asset to the downloader before actually downloading it.

The registration step fetches the metadata that is related to the asset. As soon as an application registers a URL, the downloader will fetch the HLS playlists. When information contained in the playlist is available to the application for reading, the state of the download will change PREPARED.

If the playlist cannot be acquired, the state of the download will change to FAILED.

If an Android M user declines the WRITE_EXTERNAL_STORAGE permission, the SDK produces a download error with a state of FAILED and a reason of ERROR_NO_STORAGE_ACCESS.

Example code

The following code shows how to register the download:

JAVA
//Instance DownloadManager
DownloadManager mDlManager = new DownloadManager(mContext);

//Set download assets root storage path.
mDlManager.setStorage(getFilePath());

//Register download listener.
mDlManager.registerDownloadStateListener(mDownloadListener);

//Register a download via stream URL.
String uuid = mDlManager.registerDownload(xStream.getStreamURL());

// Create a download listener to track events while downloading.
private IDownloadListener mDownloadListener = new IDownloadListener() {
  public void onDownloadStateChange(Download xDownload) {
    ...
    DownloadState state = xDownload.getState();
    switch (state) {
    case STATE_PREPARED:
      //Download prepared, need prefetch licence for the download
      break;
    case STATE_RUNNING:
      //Download is continuous.
      break;
    case STATE_PAUSED:
      //Download paused.
      break;
    case STATE_SUCCESSFUL:
      //Download successfully finished.
      break;
    case STATE_FAILED:
      //Download failed.
      break;
    }
  }
  (...)
};

For details of the API calls used above, see the Download class reference.

Next step Clear: Download content

Next step Encrypted: Import licences


JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.