3. コンテンツダウンロード
Kollus SDK を通じたコンテンツダウンロードは、常に 2 つのステップを経て進行します。
まず URL からコンテンツのメタ情報を読み込んでメディアコンテンツキー(MediaContentKey、mck)を取得した後、そのキーを基に実際のファイルダウンロードを開始します。
このドキュメントのすべてのサンプルコードは、公式サンプルアプリ kollus_player_v2_android を基に作成されています。
ダウンロードフロー
// 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.
}
デバイスの空き容量確認
ダウンロード開始前に、デバイスの空き容量がコンテンツファイルサイズと最小空き容量(例: 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;
}