я пытаюсь использовать образец кода Apple (FairPlay Streaming Server SDK v4.2.0) с онлайн-воспроизведением Fairplay, но он не работает - PullRequest
0 голосов
/ 04 февраля 2020

Я пытаюсь воспроизвести честное видео с помощью HLSCatalogWithFPS - примера кода Apple AVContentKeySession. и я просто изменяю 2 fun c "fun c requestApplicationCertificate () throws -> Data" и "fun c requestContentKeyFromKeySecurityModule (spcData: Data, assetID: String) throws -> Data" и добавляю URL-адрес видео в поток .plist

fun c 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!

}

и я получаю сообщение об ошибке, Как я могу ее решить ??

enter image description here

...