Skip to main content

3. Content Download

Notice

This document is a machine-translated draft and is currently undergoing review. Some content may be inaccurate or differ from the original Korean version. For the most precise information, refer to the Korean documentation.

Content download through the Kollus SDK always proceeds in two steps. First, content metadata is loaded from a URL to obtain the media content key (MediaContentKey, mck), and then the actual file download begins based on that key.

All sample code in this document is based on the official sample app kollus_player_v2_android.


Download flow

// DownloadService.LoadTask.run()
KollusContent content = mInfo.getMultiKollusContent().getKollusContent();
String extraDrmParam = null; // Dynamic DRM parameter (null if not needed)

// Step 1: Load content metadata (synchronous)
int nErrorCode = mInfo.getKollusStorage().load(mInfo.getUrl(), extraDrmParam, content);
if (nErrorCode != ErrorCodes.ERROR_OK) {
// Load failed: ERROR_STORAGE_FULL, ERROR_INCORRECT_AUTH_KEY, ERROR_EXPIRATION_*
return;
}

// Step 2: Start actual download based on media content key
int nRet = mInfo.getKollusStorage().download(content.getMediaContentKey());
if (nRet >= 0) {
// Download started successfully: the onProgress callback loop begins.
} else {
// Download start failed: nRet value indicates the error code.
}

Check available device storage

Before starting a download, verify that the available device storage is at least the sum of the content file size and the minimum free space (e.g., 150MB).

long freeSize = Utils.getAvailableMemorySize(mStoragePath) - content.getFileSize();
if (freeSize < MIN_FREE_SIZE) { // Official sample policy: 150MB
// Handle ERROR_STORAGE_FULL when insufficient free space
return;
}

Download cancellation, pause, and resume policy

ActionAPIDescription
Start downloadstorage.download(mck)If nRet is 0 or greater, the download proceeds normally; if negative, it indicates an error.
Cancel downloadstorage.unload(mck)Completely stops the download session and cleans up any partially saved files.
Pause downloadNo dedicated APISince no explicit Resume API is provided, call unload to cancel and then restart. The SDK may preserve some data internally, but in general you should assume the download restarts from the beginning.
Resume downloadCall download(mck) again-
Control model of the sample application

The official sample app does not implement separate pause and resume UI components, and instead adopts a cancel and restart approach.


Track download progress

Real-time download progress is tracked by referencing the properties of the KollusContent instance injected inside the onProgress event. For more details, refer to the 8. Download Events/Callbacks document.

APIDescription
KollusContent.getFileSize()Content file size
KollusContent.getReceivingSize()Received size
KollusContent.getDownloadPercent()Download progress (0–100)
KollusContent.isDownloadCompleted()Whether the download is complete

If the initial download progress returns 0, you can explicitly implement the calculation below to correct the real-time progress information.

long percent = content.getDownloadPercent();
if (content.getFileSize() > 0) {
percent = content.getReceivingSize() * 100 / content.getFileSize();
}

Prevent duplicate downloads of the same content

If download(mck) is called for content that is already being downloaded or has already been downloaded, the following errors are returned.

  • ERROR_ALREADY_DOWNLOADING: A download is currently in progress
  • ERROR_ALREADY_DOWNLOADED: The download has already been completed

It is recommended to first query the list of already downloaded content before calling a new download API. For more details, refer to the 4. Download List Management document.