Retrieving the licence
Set up your application to request licences from the licence server in a similar way as for encrypted streaming. In both cases, OTVPersistenceManager fetches the licence and persists it for the lifetime of the OTVPersistenceAsset it creates.
Prefetch the licence before downloading
If the content identifier is known to the application, the application may request the licence before instigating the download; this is sometimes called the prefetch stage. When requesting a licence for a persistent asset, the App must request the licence from the OTVDRMManager with the licence option OTVLicenseOptionOffline set to true. An instance of OTVLicenseDelegate needs to be set on drmmanager before prefetching the licence. Make sure this prefetch method is used only for a single download at a time.
To prefetch licences for multiple downloads, use the following to ensure that there are separate delegates associated with each download:
OTVPersistenceManager.shared.startDownload(urlAsset: urlAsset, title: assetName, licenseDelegate: delegate, artwork: nil, options: option) {
}
Request the licence while downloading
If the content identifier is not known and is embedded within the EXT-X-KEY or EXT-X-SESSION-KEY tag of the HLS playlists, the OTVPersistenceManager handles requesting the licence on behalf of the application.
Example code
if let contentId = stream.contentId, !contentId.isEmpty {
let options = [OTVDRMManager.Keys.OTVLicenseOptionOffline: true as Any]
OTVDRMManager.shared.requestLicense(identifier: contentId, license: options)
}
Next step: For encrypted content, you can now start the download.