我尝试将Apple示例代码(FairPlay Streaming Server SDK v4.2.0)用于FairPlay在线播放,但它没有';行不通
我尝试用HLSCatalogWithFPS-AVContentKeySession苹果示例代码播放fairplay视频。 我只修改了2个func“func requestApplicationCertificate()抛出->数据”和“func requestContentKeyFromKeySecurityModule(spcData:Data,assetID:String)抛出->数据”,并在stream.plist上添加视频url func requestApplicationCertificate()抛出->数据{我尝试将Apple示例代码(FairPlay Streaming Server SDK v4.2.0)用于FairPlay在线播放,但它没有';行不通,sdk,streaming,fairplay,Sdk,Streaming,Fairplay,我尝试用HLSCatalogWithFPS-AVContentKeySession苹果示例代码播放fairplay视频。 我只修改了2个func“func requestApplicationCertificate()抛出->数据”和“func requestContentKeyFromKeySecurityModule(spcData:Data,assetID:String)抛出->数据”,并在stream.plist上添加视频url func requestApplicationCertif
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:.空格和换行符)
设base64UrlSafe=base64spc.replacingOccurrences(of:“+”,with:“-”).replacingOccurrences(of:“/”,with:“”).replacingOccurrences(of:“=”,with:”)
让postString=“spc=\(base64UrlSafe.base64EncodedString())&assetId=\(assetId)”
错误消息表明服务器无法解析SPC以找到assetId。您是否使用对streamingContentKeyRequestData(…)的调用创建SPC?您的服务器希望您如何通过SPC?(我们没有相关文件)