3

I'm following Apple Media Playback Programming Guide example.

The following code works on iOS 11, but crash on iOS 10.

I setup the download as following:

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()
}

And fails here:

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
    }
}

I get the following error:

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)
}

Could someone point me on how to solve this?

Note: I read something about using fileURLWithPath instead of string for composing the URL, but didn't work at all.

Not related with NSAppTransportSecurity.

jherran
  • 3,337
  • 8
  • 37
  • 54
  • Did you try this in the simulator or a physical device? You cannot download in the simulator, only on a physical device. – Craig Oct 05 '18 at 10:27
  • 1
    Physical device. I know that can't be downloaded on simulator. – jherran Oct 05 '18 at 10:28
  • I have not tested this on iOS 10.* but is there a reason it should work on iOS 10.*? Apple's adoption rate is pretty good, most users are already on iOS 12. A very small fraction of people are on iOS 10. – Craig Oct 05 '18 at 10:55
  • Possible duplicate of [Getting Error when trying to download a m3u8 video using AVAssetDownloadURLSession in iOS](https://stackoverflow.com/questions/51532165/getting-error-when-trying-to-download-a-m3u8-video-using-avassetdownloadurlsessi) – Cœur Jul 29 '19 at 09:12

0 Answers0