Register 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 example shows how to register the download:

//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;
    }
  }
  (...)
};

See the Download class reference for details of the API calls used above.

Next

Download content.