Skip to main content

Downloader

The CLDownloader downloads a video stream, so the video could be played offline. It also supports track selection for download and offline key storage for encrypted videos.

Setup​

Android​

Add the foreground service permission to the AndroidManifest.xml file:

<manifest>
<!-- ... -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
</manifest>

Usage​

Clear content​

Download a clear content:

import { CLDownloader } from "@castlabs/react-native-prestoplay";

class DownloadExample {

async download() {

// Define a new downloader
const downloader = new CLDownloader();

// Define the download configuration
const downloadConfig = {
id: "1",
url: "http://demo.castlabs.com/media/TOS/abr/Manifest_clean_sizes.mpd",
};

// Prepare the downloader and get available tracks for download
const trackSet = await downloader.prepare(downloadConfig);

// Choose the tracks for download
const selection = {
videoQuality: 0,
audioTracks: [0],
subtitleTracks: [0],
};

// Start the download
downloader.start(selection);
}
}

Protected content​

Download a Widevine protected content:

import {
DrmSystem,
DrmTodayEnvironment,
DrmType,
CLDownloader,
} from '@castlabs/react-native-prestoplay';

class DownloadExample {

async download() {

// Define a new downloader
const downloader = new CLDownloader();

// Define the download configuration
const downloadConfig = {
id: "1",
url: "http://demo.castlabs.com/media/TOS/DASH/DEMO.mpd",
drm: {
drmType: DrmType.DRMTODAY,
drmSystem: DrmSystem.WIDEVINE,
drmConfiguration: {
environment: DrmTodayEnvironment.STAGING,
userId: "purchase",
sessionId: "sessionId",
merchant: "six",
assetId: "dasheverywhere_demo",
offlineId: "dasheverywhere_demo",
},
},
};

// Prepare the downloader and get available tracks for download
const trackSet = await downloader.prepare(downloadConfig);

// Choose the tracks for download
const selection = {
videoQuality: 0,
audioTracks: [0],
subtitleTracks: [0],
};

// Start the download
downloader.start(selection);
}
}