1

在使用 AVContentSessionKey 的 FairPlay Streaming Server SDK v4.0.1 中的演示之后,我正在使用 HLS Fairplay 实现离线播放。我下载了三个内容,每个内容都正确下载并保存,文件目录上的.movpkg及其内容键,当我关闭WIFI时,这三个下载的内容可以正常播放,没有任何问题,在播放之前我使用这个代码:

let urlAsset = element.urlAsset!
ContentKeyManager.shared.contentKeySession.addContentKeyRecipient(urlAsset)
if !urlAsset.resourceLoader.preloadsEligibleContentKeys {
  urlAsset.resourceLoader.preloadsEligibleContentKeys = true
}

self.present(playerViewController, animated: true, completion: {
  AssetPlaybackManager.sharedManager.setAssetForPlayback(urlAsset)
})

到目前为止,一切都很好。但问题是当我关闭应用程序(主页按钮关闭应用程序)然后播放下载的内容时,只有最后下载的内容正确播放,其他内容(第一个和第二个)在控制台上发送这些错误。

Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed"
UserInfo={NSUnderlyingError=0x1c065d760 {Error Domain=NSOSStatusErrorDomain Code=-16227 "(null)"},
NSLocalizedFailureReason=An unknown error occurred (-16227),
NSURL=file:///private/var/mobile/Containers/Data/Application/A950D8DB-B711-47E3-AAF5-C95CC9682430/Library/com.apple.UserManagedAssets.kkG8Ih/644986_7798B8476A473F68.movpkg/, NSLocalizedDescription=The operation could not be completed}

我用文档目录中的键仔细检查 .movpkg 并正确显示

/Documents/.keys/one-key
/Documents/.keys/two-key
/Documents/.keys/three-key

在错误发生之前,调用 ContentKeyDelegate 并正确加载密钥并将其传递给请求。

如果persistableContentKeyExistsOnDisk(withContentKeyIdentifier:assetIDString){

    let urlToPersistableKey = urlForPersistableContentKey(withContentKeyIdentifier: assetIDString)

    guard let contentKey = FileManager.default.contents(atPath: urlToPersistableKey.path) else {
        /

        pendingPersistableContentKeyIdentifiers.remove(assetIDString)
        return
    }

    /
    Create an AVContentKeyResponse from the persistent key data to use for requesting a key for
    decrypting content.
    */
    let keyResponse = AVContentKeyResponse(fairPlayStreamingKeyResponseData: contentKey)

    /
    keyRequest.processContentKeyResponse(keyResponse)

    return
}

如果我打印 contentKeyRecipients 三个内容正确显示

 - (lldb) po
   ContentKeyManager.shared.contentKeySession.contentKeyRecipients ▿ 3
   elements
   - 0 : AVURLAsset: 0x1c0234d40, URL = file:///private/var/mobile/Containers/Data/Application/E791A4DE-4261-46B7-A84D-D10B27035FAE/Library/com.apple.UserManagedAssets.kkG8Ih/539628_20469336224AA388.movpkg
   - 1 : AVURLAsset: 0x1c0234fa0, URL = file:///private/var/mobile/Containers/Data/Application/E791A4DE-4261-46B7-A84D-D10B27035FAE/Library/com.apple.UserManagedAssets.kkG8Ih/644986_7798B8476A473F68.movpkg
   - 2 : AVURLAsset: 0x1c42391c0, URL = file:///private/var/mobile/Containers/Data/Application/E791A4DE-4261-46B7-A84D-D10B27035FAE/Library/com.apple.UserManagedAssets.kkG8Ih/573744_62377F9549C45B93.movpkg

我的测试在 iOS 11.1.2 和 iOS 11.2 beta 2 中

我不确定发生了什么,但似乎是持久密钥的问题,我不知道是否每个内容都需要与一个 AVContentKeySession 相关联。

如果有人遇到类似的问题,任何帮助将不胜感激。

提前致谢

4

4 回答 4

1

我有类似的问题。

但是,由于我需要支持 iOS 10,所以我没有使用新的 AVContentKeyResponse 类。相反,我自己加载持久内容密钥,并将其传递给加载请求。

无论如何,我得到与你完全相同的错误和相同的行为。需要注意的一件事是,如果我删除从磁盘加载持久内容密钥的代码,并始终从服务器获取密钥,那么一切正常。但这违背了“离线”播放的目的......

因此,系统似乎认为持久内容密钥无效......

于 2018-03-06T23:50:03.860 回答
1

您在服务器端使用哪个 TLLV 来指定下载内容的租借持续时间?您使用的是内容密钥持续时间 TLLV 还是离线密钥 TLLV?如果您使用离线密钥 TLLV,您需要仔细检查每个下载电影的“内容 ID”字段是否不同。

于 2018-03-12T17:56:33.647 回答
0

我们也遇到过这个错误信息。当内容超过服务器端设置的过期日期时,就会发生这种情况。

例如 :

  1. 我们为视频 A 提供 10 分钟的到期日期

  2. 下载此视频 A,并正确验证 CKC 交付(打印日志)

  3. 无连接播放视频 A

  4. 休息(11分钟后),关闭App,再次启动App,选择视频A播放

显示下面来自 AVPlayerItem.error.description 的错误消息:

Error Domain=AVFoundationErrorDomain Code=-11800 
"The operation could not be completed" UserInfo={NSLocalizedFailureReason=An unknown error occurred (-16227), 
NSLocalizedDescription=The operation could not be completed, NSUnderlyingError=0x1d4257310 
{Error Domain=NSOSStatusErrorDomain Code=-16227 "(null)"}}

您可以通过以下方式再次刷新加密数据

  1. AVAssetResourceLoaderDelegate
  2. 或使用 AVContentSessionKey

参考:https ://developer.apple.com/videos/play/wwdc2018/507/

于 2018-07-27T09:20:03.317 回答
0

确保在服务器端设置正确的离线内容标识符。您设置的标识符应与许可证允许的特定再现/流相关联。这对我有帮助。

于 2020-05-05T09:05:14.367 回答