Posts

Post not yet marked as solved
1 Replies
887 Views
i try to playback fairplay video with HLSCatalogWithFPS - AVContentKeySession apple sample code.and i just modify 2 func "func requestApplicationCertificate() throws -> Data" and "func requestContentKeyFromKeySecurityModule(spcData: Data, assetID: String) throws -> Data" and add video url on the stream.plistfunc 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: " DRM license url")! 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!}and i get the error message , How can i solve it ??response = Optional(<NSHTTPURLResponse: 0x28283d040> { URL: DRM License URL } { Status Code: 500, Headers { Connection = ( close ); "Content-Length" = ( 94 ); "Content-Type" = ( "application/json" ); Date = ( "Mon, 03 Feb 2020 15:07:16 GMT" ); Server = ( "Apache-Coyote/1.1" );} })responseData = Optional("FPS Error code = -42581 | Error in parsing Server playback context to retrieve assetId and HU.")ckc = ()Fatal error: Unexpectedly found nil while unwrapping an Optional value2020-02-03 23:07:16.061540+0800 HLSCatalog[4006:862460] Fatal error: Unexpectedly found nil while unwrapping an Optional value
Posted
by chtdapp.
Last updated
.