Search code examples
iosiphonedrmfairplayspc

Error obtaining key request data: AVFoundationErrorDomain reason: Optional("An unknown error occurred (-42650)")


I am implementing Apple Fireplay DRM for delivering encrypted content to devices. I was able to successfully load the certificate, but when I try to obtain SPC data from AVAssetResourceLoadingRequest, I am getting this error.

Error obtaining key request data: AVFoundationErrorDomain reason: Optional("An unknown error occurred (-42650)")

Following is the code to retrieve SPC content

let spcData: Data!

    do {
        /* 
         To obtain the Server Playback Context (SPC), we call 
         AVAssetResourceLoadingRequest.streamingContentKeyRequestData(forApp:contentIdentifier:options:)
         using the information we obtained earlier.
         */
        spcData = try resourceLoadingRequest.streamingContentKeyRequestData(forApp: applicationCertificate, contentIdentifier: assetIDData, options: resourceLoadingRequestOptions)
    } catch let error as NSError {
        print("Error obtaining key request data: \(error.domain) reason: \(error.localizedFailureReason)")
        resourceLoadingRequest.finishLoading(with: error)
        return
    }

I already searched for error code: 42650 on apple developer forum, but no luck!


Solution

  • I got this error also. In my case, I was generating the applicationCertificate using the wrong data format (the appIdentifier parameter in resourceLoadingRequest.streamingContentKeyRequestData(forApp:contentIdentifier:options:) function) The certificate that was given to me was base64 encoded. So I need to create data with Data(base64Encoded: yourCertificateString).