【问题标题】:AVContentKeySessionDelegate methods not called未调用 AVContentKeySessionDelegate 方法
【发布时间】:2020-10-05 16:50:07
【问题描述】:

在我的 iOS 应用程序的 ViewController.swift 中实现了 AVContentKeySessionDelegate 的委托方法,使用 Brightcove SDK 播放 drm 内容。

代码sn-p:

 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)
  }
 }


问题

  1. 这些委托方法都没有被调用。
  2. 另外,注意到 Xcode 控制台中出现错误提示:NSURLConnection finished with error - code -1002(在 Info.plist 的 App Transport Settings 中将允许任意加载设置为 true

【问题讨论】:

  • 当您在 iOS FairPlay 中看到 -1002 代码错误时,这通常意味着您没有获得内容密钥。你已经找到了答案。恭喜。最好的。

标签: ios swift drm brightcove avcontentkeysession


【解决方案1】:

我相信self.contentKeySession.processContentKeyRequest 的意图是缓存内容密钥。理论上,只要内容受到保护,就应该调用内容会话密钥委托。

【讨论】:

    【解决方案2】:

    添加

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

    解决了这个问题。当请求处理内容密钥时,将调用委托方法。

    【讨论】:

      猜你喜欢
      • 2022-10-19
      • 2019-10-14
      • 2014-03-04
      • 2019-09-01
      • 2015-10-15
      • 2014-06-26
      • 2020-01-12
      • 2017-09-07
      • 2016-10-30
      相关资源
      最近更新 更多