Implemented the delegate methods of AVContentKeySessionDelegate within my ViewController.swift in my iOS application which is to play drm content using Brightcove SDK.
Code snippet :
class ViewController: UIViewController, AVContentKeySessionDelegate, BCOVPlaybackControllerDelegate {
var contentKeySession: AVContentKeySession!
.
.
func getVideo() {
// fetching video using an API call
.
.
let asset = AVURLAsset(url: videoUrl)
self.contentKeySession = AVContentKeySession(keySystem: .fairPlayStreaming)
self.contentKeySession?.setDelegate(self, queue: DispatchQueue.main)
self.contentKeySession?.addContentKeyRecipient(asset)
}
//MARK: - AVContentKeySessionDelegate Methods
func contentKeySession(_ session: AVContentKeySession, didProvide keyRequest: AVContentKeyRequest) {
handleKeyRequest(keyRequest: keyRequest)
}
func contentKeySession(_ session: AVContentKeySession, contentKeyRequest keyRequest: AVContentKeyRequest, didFailWithError err: Error) {
print(err)
}
func contentKeySession(_ session: AVContentKeySession, contentKeyRequestDidSucceed keyRequest: AVContentKeyRequest) {
print(keyRequest)
}
}
Issue
- None of these delegate methods are getting invoked.
- Also, noticed an error in the Xcode console saying : NSURLConnection finished with error - code -1002 (Allow arbitrary loads is set to true in App Transport Settings in Info.plist)
I believe that the intent of
self.contentKeySession.processContentKeyRequest
is to cache the content key. In theory, the content session key delegate should be called as long as the content is protected.