AVAssetDownloadURLSession downloads but is not playable offline

I am on an application starting from the sample apple provides.

I made a dynamic list of HLS streams which are on a wowza server.

All streams play fine on streaming in the app.

Download works also.

But when I go offline (airplane mode) the downloaded assets do not play.

I inspect the files, they are here, the cache is also here, but it is not playable offline.

The only time the play offline is because I have played them as streaming before and only the beginning, so I suspect this is from another streaming cache that is actually used.


These are the files that are downloaded. I did not move them, only inspect, and I use the bookmark method from the sample code. It's all there and uses space, but it does not play.


I thought maybe there is a problem with the path, but as I are not supposed to touch this...


asset file:///private/var/mobile/Containers/Data/Application/072345D0-F634-4493-89C8-3BF3E7A2C2FA/Library/com.apple.UserManagedAssets.EIgU7r/pass-chateau-de-sable_68CFC567840914CC.movpkg/

asset is playable

there is an asset

asset is NOT playable offline

file 1856 0-YJCJJGLJTV23ZY67GNJFN2NSSDBTKELB-1644569

file 1525 0-YJCJJGLJTV23ZY67GNJFN2NSSDBTKELB-1644569.m3u8

file 14122 StreamInfoBoot.xml

file 422 StreamInfoRoot.xml

file 819868 [0]_[0]_[10.082].frag

file 1659852 [10.082]_[0]_[9.88501].frag

file 594080 [100.171]_[0]_[9.88501].frag

file 1300396 [110.056]_[0]_[10.063].frag

file 1196432 [120.119]_[0]_[10.359].frag

file 1242680 [130.478]_[0]_[10.201].frag

file 1099988 [140.679]_[0]_[9.54801].frag

file 995460 [150.227]_[0]_[9.50901].frag

file 1097920 [159.736]_[0]_[9.88501].frag

file 1196244 [169.621]_[0]_[10.201].frag

file 1175752 [179.822]_[0]_[9.88501].frag

file 1395524 [189.707]_[0]_[9.74601].frag

file 1673576 [19.967]_[0]_[9.66701].frag

file 1443088 [199.453]_[0]_[9.58801].frag

file 1275956 [209.041]_[0]_[9.72701].frag

file 1694256 [218.768]_[0]_[9.88401].frag

file 1666244 [228.652]_[0]_[10.241].frag

file 1162028 [238.893]_[0]_[9.88501].frag

file 1291936 [248.778]_[0]_[9.88401].frag

file 1657784 [258.662]_[0]_[9.88501].frag

file 1205832 [268.547]_[0]_[10.142].frag

file 996964 [278.689]_[0]_[9.74601].frag

file 1037572 [288.435]_[0]_[10.082].frag

file 1790700 [29.634]_[0]_[9.88501].frag

file 1352848 [298.517]_[0]_[10.32].frag

file 1213164 [308.837]_[0]_[10.201].frag

file 1042648 [319.038]_[0]_[9.62801].frag

file 1429364 [328.666]_[0]_[9.56801].frag

file 1113900 [338.234]_[0]_[9.88501].frag

file 766852 [348.119]_[0]_[10.22].frag

file 1545172 [358.339]_[0]_[9.76601].frag

file 1224068 [368.105]_[0]_[9.74701].frag

file 1180828 [377.852]_[0]_[9.88401].frag

file 827012 [387.736]_[0]_[9.86501].frag

file 1736368 [39.519]_[0]_[9.88501].frag

file 776440 [397.601]_[0]_[10.3].frag

file 911800 [407.901]_[0]_[10.379].frag

file 818552 [418.28]_[0]_[9.88501].frag

file 701052 [428.165]_[0]_[9.88401].frag

file 684884 [438.049]_[0]_[9.88501].frag

file 645216 [447.934]_[0]_[9.88501].frag

file 517940 [457.819]_[0]_[9.88401].frag

file 460412 [467.703]_[0]_[10.024].frag

file 494816 [477.727]_[0]_[10.438].frag

file 497824 [488.165]_[0]_[10.359].frag

file 1076112 [49.404]_[0]_[9.88401].frag

file 485604 [498.524]_[0]_[9.88501].frag

file 571896 [508.409]_[0]_[10.082].frag

file 169576 [518.491]_[0]_[4.86001].frag

file 1451172 [59.288]_[0]_[10.043].frag

file 1717756 [69.331]_[0]_[10.162].frag

file 1497420 [79.493]_[0]_[10.378].frag

file 744104 [89.871]_[0]_[10.3].frag

file 702 boot.xml

file 380 root.xml

I found the reason it did not work. The sample application HLSCatalog downloads the stream twice.


The first time, AssetPersistanceManager.downloadStream() creates only the above structure.


Then the delegate URLSession(_ :task:didCompleteWithError:) looks additional media selection and downloads this. As the first download was only implicite on mediaselection, it will download exactly the same stream again, if there is only one media selection in the m3u8 file. But this second step creates locally the playlist master m3u8 file which is essential that the file is playable offline.


I tried to cut this second step to cut the second download and therefore it didn't work.


If I keep downloading two times, wasting bandwidth and download time, the code works.


The next step probably is to make an explicite media selection on the first download, so that the AssetPersistanceManager.nextMediaSelection() is aware that the selection is already downloaded and not waste this bandwidth.

AVAssetDownloadURLSession downloads but is not playable offline
 
 
Q