0

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)
MGY
  • 7,245
  • 5
  • 41
  • 74
Alen Alexander
  • 725
  • 6
  • 22
  • 1
    When you saw an error with -1002 code in iOS FairPlay, this usually means that you didn't get the content key. You already found the answer. Congrats. Best. – MGY Aug 19 '20 at 08:08

2 Answers2

2

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.

1

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.

Alen Alexander
  • 725
  • 6
  • 22