sdk - 我尝试将 Apple 示例代码(FairPlay Streaming Server SDK v4.2.0)与 Fairplay 在线播放一起使用,但它不起作用
问题描述
我尝试使用 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!
}
我收到错误消息,我该如何解决?
解决方案
我认为您应该尝试创建 base64 编码的 url 安全 src 数据。
let base64spc = spcData.base64EncodedString().trimmingCharacters(in: .whitespacesAndNewlines)
let base64UrlSafe = base64spc.replacingOccurrences(of: "+", with: "-").replacingOccurrences(of: "/", with: "_").replacingOccurrences(of: "=", with: "")
let postString = "spc=\(base64UrlSafe.base64EncodedString())&assetId=\(assetID)"
推荐阅读
- android-studio-3.0 - 使用:在 android (manifest.xml)
- crdt - 如何在 delta-crdt 中管理和保持 delta-state 的大小最小
- c++ - 使用 max 函数和/或替代方法的正确方法
- typescript - 单击按钮共享时未加载社交共享
- python - 带有捕获组的 Python 正则表达式可选组不起作用
- javascript - Cloud Functions 中的 Firestore:文档删除是异步的吗?
- django - params={'value': value}, django.core.exceptions.ValidationError: ["'' value 必须是 True 或 False。"]
- javascript - 尝试进行身份验证时出现 react-aad-msal 无限循环错误
- arrays - 当切片的最大长度小于底层数组的长度时,切片的“动态大小”一词如何合理?
- bash - makefile 中的主机名操作