I'm using AVAggregateAssetDownloadTask to download HLS videos in my application. I just added a pause/resume functionality. Simply, I'm suspending the task when the user wants to pause the download.
But, somehow in this case, actually task won't stop. It keeps downloading the asset. When I press the resume button I'm calling the task's .resume() method. Somehow, the process going super fast till the %100, and it gives an error (keep reading or goto Error Message title).
How do I test
- Start to download an item via AVAggregateAssetDownloadTask
- Tap Pause at the %3.
- Call the task?.suspend()
- Wait for 1 minute or 2
- Tap the resume download button
- Call the task?.resume()
- Task resumes from %29
- Task fails at %48
Code
@objc public func pauseDownload(for productId: String) {
var asset: Asset?
var task: AVAggregateAssetDownloadTask?
for (taskKey, assetValue) in activeDownloadsMap where productId == assetValue.productId {
asset = assetValue
task = taskKey
task?.suspend() // **task is not nil!**
break
}
// Here: I'm sending a notification to the UI cases
}
@objc public func resumeDownload(for productId: String) {
var asset: Asset?
var task: AVAggregateAssetDownloadTask?
for (taskKey, assetValue) in activeDownloadsMap where productId == assetValue.productId {
asset = assetValue
task = taskKey
task?.resume() // **task is not nil!**
break
}
// Here: I'm sending a notification to the UI cases
}
Other Cases
- Without suspending the task, it downloads flawlessly.
Technical Details
- Xcode Version 12.4 (12D4e)
- iOS Version 14.4
Error Message
Error Domain=CoreMediaErrorDomain Code=-16657
"(null)" UserInfo={_NSURLErrorRelatedURLSessionTaskErrorKey=( "BackgroundAVAssetDownloadTask .<1>"), _NSURLErrorFailingURLSessionTaskErrorKey=BackgroundAVAssetDownloadTask .<1>}
developer.apple.com
Here is the same issue at developer.apple.com:
https://developer.apple.com/forums/thread/674090
Reported Bug
FB9043262
If you believe you are faced with the same issue, please consider the help.
Best.
I just had this error on iOS 16.1
It seems that a change in
AVAggregateAssetDownloadTask
as part of iOS16 is causing the the root.m3u8
to be retrieved multiple times.We generate these root
.m3u8
playlists on-the-fly and put a token on URIs pointing to child subtitle.m3u8
files. Each time the root playlist was retrieved a new token was generated, and it had a slightly different URI for the subtitle playlist. In a proxyman network trace, we could see both subtitle playlists being retrieved, and the eventual.vtt
subtitle files coming from the URIs specified in the second playlist.Ensuring a consistent URI value for the subtitle playlist across multiple root playlist retrievals fixed the issue.