AVContentKeySessionDelegate methods not called

865 views Asked by At

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

  1. None of these delegate methods are getting invoked.
  2. 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)
2

There are 2 answers

0
Celso Santa Rosa On

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.

0
Alen Alexander On

Adding

self.contentKeySession.processContentKeyRequest(withIdentifier: "<identifier>", initializationData: nil, options: nil)

fixed the issue. When the request to process content key is made, the delegate methods are getting invoked.