Skip to main content
Skip table of contents

Starting the download

As soon as the application starts a registered download, the application is notified that the download has switched to the RUNNING state. In the RUNNING state, the downloader keeps on fetching media segments from the CDN sequentially from the first to the last. When all files of the provided assets have downloaded, the download state changes to COMPLETED.

If a non-recoverable error is encountered, the download enters the FAILED state. The start download operation can take place on a registered event in the PREPARED state. If more than one media asset is available (different bitrates), it must be chosen first.

Example code

The following code example shows how to start the download.

CODE
// If download is prepared, get the bitrate from the media asset and start

if (self.download.state == STATE_PREPARED)  {
    NSArray* mediaInfos = self.download.asset.mediaInfo;
    if(mediaInfos.count == 1) {
      NMPMediaInfo* mediaInfo = self.download.asset.mediaInfo[0];
      [downloadManager startDownload:self.download.UUID bitrate: mediaInfo.bitrate];
    }
    else   {
      NSMutableArray* arr = [[NSMutableArray alloc] initWithCapacity:mediaInfos.count];
      for(NMPMediaInfo *info in mediaInfos) {
        [arr addObject:@(info.bitrate)];
      }
      [delegate chooseBitrate:arr withCallback:^(long bitrate) {
        [downloadManager startDownload:self.download.UUID bitrate: bitrate];
      }];
    }
  }

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

Next step: You can watch the download.

JavaScript errors detected

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

If this problem persists, please contact our support.