Tried iOS13.0 and iOS13.1 and still not working, I tried both AVAggregateAssetDownloadTask and AVAssetDownloadURLSession but none of them working. Not any delegate was called to tell me error of finish, and I found downloaded cache was only 25Kb what was not the right size.
The error is:
Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo={NSLocalizedDescription=The operation could not be completed, _NSURLErrorFailingURLSessionTaskErrorKey=BackgroundAVAssetDownloadTask <AFDCA3CC-FA49-488B-AB16-C74425345EE4>.<1>, _NSURLErrorRelatedURLSessionTaskErrorKey=(
"BackgroundAVAssetDownloadTask <AFDCA3CC-FA49-488B-AB16-C74425345EE4>.<1>"
), NSLocalizedFailureReason=An unknown error occurred (-16654)}
Found out
AVAssetDownloadURLSessioncan only download HLS with master playlist structure which containscodecattribute intoEXT-X-STREAM-INFm3u8 meta on iOS 13+.I have no idea if this is a bug or function restriction. (m3u8 meta have no
CODECSattribute can be played withAVFoundation, but can't be downloaded withAVAssetDownloadURLSession)Anyway, the solution is:
If you have HLS master playlist:
add
CODECSattribute into your#EXT-X-STREAM-INFin m3u8 meta. e.g.If you haven't HLS master playlist yet:
You have to make a master playlist even if you're not supporting adaptive streaming.
The master playlist is the only m3u8 which can contain
#EXT-X-STREAM-INFhenceCODECSattribute.