我正在关注 Apple Media Playback Programming Guide示例。
以下代码适用于 iOS 11,但在 iOS 10 上崩溃。
我将下载设置如下:
func setupAssetDownload(for item: DownloadItem) {
let url = URL(string: item.urlVideo!)!
let asset = AVURLAsset(url: url)
// Create new AVAssetDownloadTask for the desired asset
guard let task = downloadSession.makeAssetDownloadTask(asset: asset,
assetTitle: item.title!,
assetArtworkData: nil,
options: [AVAssetDownloadTaskMinimumRequiredMediaBitrateKey: 265_000])
else { return }
// Start task and begin download
task.resume()
}
并在这里失败:
func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?) {
/*
This is the ideal place to begin downloading additional media selections
once the asset itself has finished downloading.
*/
if let error = error as NSError? {
switch (error.domain, error.code) {
case (NSURLErrorDomain, NSURLErrorCancelled):
/*
This task was canceled, you should perform cleanup using the
URL saved from AVAssetDownloadDelegate.urlSession(_:assetDownloadTask:didFinishDownloadingTo:).
*/
...
case (NSURLErrorDomain, NSURLErrorUnknown):
fatalError("Downloading HLS streams is not supported in the simulator.")
default:
fatalError("An unexpected error occured \n\(error.code) - \(error.domain) - \(error.localizedDescription)")
}
} else {
// downloaded
}
}
我收到以下错误:
Error Domain=AVFoundationErrorDomain
Code=-11800 \"The operation could not be completed\"
UserInfo={
NSLocalizedDescription=The operation could not be completed,
NSLocalizedFailureReason=An unknown error occurred (-12780)
}
有人可以指点我如何解决这个问题吗?
注意:我读过一些关于使用fileURLWithPath
而不是string
编写的东西URL
,但根本没有用。
与 NSAppTransportSecurity 无关。