Alen Alexander
Alen Alexander

Reputation: 735

AVContentKeySessionDelegate methods not called

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)

Upvotes: 0

Views: 1067

Answers (2)

Celso Santa Rosa
Celso Santa Rosa

Reputation: 39

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.

Upvotes: 2

Alen Alexander
Alen Alexander

Reputation: 735

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.

Upvotes: 1

Related Questions