我尝试使用 HLSDatalogWithFPS - AVContentKeySession 苹果示例代码播放公平播放视频。我只是修改 2 func "func requestApplicationCertificate() throws -> Data" 和 "func requestContentKeyFromKeySecurityModule(spcData: Data, assetID: String) throws -> Data" 并在 stream.plist 上添加视频 url
func requestApplicationCertificate() throws -> Data {
let certificateURL = Bundle.main.url(forResource: "fairplay", withExtension: "cer")
let applicationCertificate: Data? = try? Data(contentsOf: certificateURL!)
return applicationCertificate!
}
func requestContentKeyFromKeySecurityModule(spcData: Data, assetID: String) throws -> Data {
// MARK: ADAPT - You must implement this method to request a CKC from your KSM.
var ckcData: Data? = nil
let url = URL(string: "http://drmlab.ott.hinet.net:8064/fpsa/v1.0/?deviceId=NDJhNjQ1MmQtZGFkZC0zNjE3LTllOTUtMmNlNWVlMzYwZmRi")!
var request = URLRequest(url: url)
let postString = "spc=\(spcData.base64EncodedString())&assetId=\(assetID)"
let postData = postString.data(using: .utf8, allowLossyConversion: true)
request.httpMethod = "POST"
request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
request.setValue(String(postData!.count), forHTTPHeaderField: "Content-Length")
request.httpBody = postData
let session = URLSession.shared
let semaphore = DispatchSemaphore(value: 0)
let task = session.dataTask(with: request) { (data, response, error) in
guard let data = data, error == nil else {
print("error=\(error)")
return
}
print("response = \(response)")
let responseData = String(data: data, encoding: .utf8)
print("responseData = \(responseData)")
print("ckc = \(ckcData = Data(base64Encoded: responseData!))")
semaphore.signal()
}
task.resume()
_ = semaphore.wait(timeout: DispatchTime.distantFuture)
return ckcData!
}
我收到错误消息,我该如何解决?