Reputation: 33
I'm currently trying to implement a service to handle DRM with FairPlay streaming on a tvOS App. Here is my workflow :
I get the app certificate as Data
From this certificate i get the SPC Datas, using :
resourceLoadingRequest.streamingContentKeyRequestData(forApp: applicationCertificate, contentIdentifier: assetIDData, options: resourceLoadingRequestOptions)
From the SPC Datas encoded to base64Data I request POST (with SPC in payload) on our server to get the license which gives me the CKD Datas
Then when I get the CKC Datas, I use them as below :
guard let dataRequest = resourceLoadingRequest.dataRequest else {
print("no data is being requested in loadingRequest")
let error = NSError(domain: AssetLoaderDelegate.errorDomain, code: -6, userInfo: nil)
resourceLoadingRequest.finishLoading(with: error)
return
}
dataRequest.respond(with: datas)
resourceLoadingRequest.finishLoading()
But after these steps I get the error :
Error Domain=AVFoundationErrorDomain Code=-11835 "Cannot Open" UserInfo={NSUnderlyingError=0x170440de0 {Error Domain=NSOSStatusErrorDomain Code=-42681 "(null)"}, NSLocalizedFailureReason=This content is not authorized., NSLocalizedDescription=Cannot Open}
Does anyone have an idea or a tips ?
Additional infos :
the playback process works with non-protected content.
playerItem.errorLog() returns nil.
playerItem.status == .failed returns true.
all the server side process seems to be OK since it's already used for the website and Smart TV.
Upvotes: 3
Views: 2471
Reputation: 459
I recently ran into this exact same problem. The problem is the CKC response data returned from streamingContentKeyRequestData(forApp...
is not just data, it is base 64 encoded string data. All you need to do is decode it before you respond to the data request:
dataRequest.respond(with: Data(base64Encoded: datas)!)
For production code you'll want to handle the optionality properly. Hope this helps!
Upvotes: 2