I'm developing an iOS app which is able to download m3u8 videos and play it offline according to the iOS 10
latest feature Offline HLS.
I'm trying to protect as best as I can HTTP Live Stream
format videos on our CDN.
Each video has multiple bitrates so the HLS
files consist of a master m3u8 manifest which points to several sub manifest files which in turn point to ts
files (transport stream).
So I need to append this CDN token to the URLs of master m3u8, sub manifest m3u8 and .ts
files. The token will be valid for 60 seconds, so it needs to get refreshed and the current token should get append with the URL.
How can I do this?
I tried this, but its appending to only master m3u8.
My Code :
var components = URLComponents(string: playUrl)
let token = URLQueryItem(name: "token", value: CDNTokenManager.getCDNToken())
components?.queryItems = [token]
let url = components?.url
let asset = AVURLAsset(url: url!)
let downloadTask = downloadURLSession.makeAssetDownloadTask(asset: asset,
assetTitle: "title",
assetArtworkData: nil,
options: nil)
downloadTask?.resume()