2 Replies
      Latest reply on Apr 7, 2019 10:38 PM by Tejsvi tandon
      Tejsvi tandon Level 1 Level 1 (0 points)

        I have been trying to multiple HLS audio files together. The files are encrypted with a key. I| need to fetch the key and store it locally for offline use. When I download a small number (2 or 3 files) of files simultaneously it works fine, but if I start downloading 10-15 files simultaneously most of them fails with the error message-


        Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo={NSLocalizedFailureReason=An unknown error occurred (-17377), NSLocalizedDescription=The operation could not be completed}


        I am getting error message from NSURLErrorDomain as well but they are rare.

        Below is my download function -


        class AudioDownloader {


            var productKey: String

            var downloadUrl: URL

            var downloadSession: AVAssetDownloadURLSession?

            var fakeDownloadUrl: URL?

            var downloadTask: AVAssetDownloadTask?



        func downloadAudio() {


                if downloadSession == nil {


                    let configuration = URLSessionConfiguration.background(withIdentifier: self.productKey)

                    downloadSession = AVAssetDownloadURLSession(configuration: configuration, assetDownloadDelegate: self, delegateQueue: OperationQueue.main)

                    configuration.shouldUseExtendedBackgroundIdleMode = true

                    configuration.httpShouldSetCookies = true

                    configuration.httpShouldUsePipelining = false

                    configuration.allowsCellularAccess = true

                    configuration.isDiscretionary = true



                    self.fakeDownloadUrl = self.convertToScheme(url: self.downloadUrl, scheme: "fakehttp")


                    let asset = AVURLAsset(url: self.fakeDownloadUrl!)


                    let loader = asset.resourceLoader

                    loader.setDelegate(self, queue: DispatchQueue(label: "dispatch2"))

                    self.downloadTask = downloadSession?.makeAssetDownloadTask(asset: asset, assetTitle: "assetTitle \(self.productKey)", assetArtworkData: nil, options: nil)!

                    self.downloadTask?.taskDescription = self.productKey





        The link of the approach which I am using to fetch the key for offline use is below -



        Any help would be appreciated.

        • Re: Downloading multiple HLS audio files simultaneously fails.
          Polyphonic Apple Staff Apple Staff (70 points)

          Whenever you encounter one of these "unknown" errors, it would be helpful if you could file a bug report describing the scenario. (Post the bug number here for reference, please!)


          I don't know in detail what this error means, but it indicates some kind of timeout problem. My guess is that by increasing the number of streams you initiate, you slow the throughtput of all of them, proportionately. Eventually, they are all slow enough to hit a timeout threshold, which means they'll all fail.


          The workaround, obviously, is to limit the number of streams you initiate. Or, possibly, staggering their startup may help a bit.