Suspend/Resume AVAssetDownloadTask

I was trying to implement the pause/resume feature in the apple sample code https://developer.apple.com/library/prerelease/content/samplecode/HLSCatalog/Introduction/Intro.html#//apple_ref/doc/uid/TP40017320

I'm able to pause the AVAssetDownloadTask using suspend() method and resume it back using resume() method.

But this pause/resume will work only two times. When I pause 3rd time I'm not able to resume it back. And I cannot start a new asset download after this.

I need to reboot the device to start download again.

I'm using the below code to do pause/resume (in the above sample code)

if task?.state == .running {

task?.suspend()

}

else if task?.state == .suspended {

task?.resume()

}

Replies

While you posted this months ago, I thought I'd share what I've seen in case it helps others.

I too can reproduce the behaviour you describe with using suspend "too often". I had to resort to a device restart in order to start downloads again. Lesson learned: stay away from the suspend method when using AVAssetDownloadTask. I'll be filing a bug report for this one, as it doesn't make much sense to me.


What I did find is that I had much better luck using the -cancel method of the AVAssetDownloadTask. With this method I could cancel and resume the download many times in a row without issue. This is also what I used when canceling a download -> killing app -> reopen app and resume the download. It will pick up right back where it left off - seems quite seemless so far (not to jinx it).

How do you resume from where it was left out? The task will be gone when you call cancel(), in my case if I cancel a task, then I will have to create another AVAssetDownloadTask and it will start from the beginning, pretty annoying.

Created bug

31049921

I've been reliably informed that this was a bug on our side and is fixed as of iOS 10.3 beta 3.

I tested Apple HLSCatalog sample without any modification on iOS 10.3.3 and is did not work. https://developer.apple.com/library/content/samplecode/HLSCatalog/Introduction/Intro.html


If I start "Advanced Stream" https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/bipbop_16x9_variant.m3u8


App download video and next download 1 audio - Ok

Next it begin to download second audio and download it many many times without success.

Second audio did not appear in AVAssetCache.

And after every download of second audio nextMediaSelectionmediaSelection() return you need to download it again.



This did not happen on iOS 11 beta 6.



Can anyone cofirm that it better not to use AVAssetDownloadTask in iOS 10 and wait iOS 11 release ?

I am not shure that AVAssetDownloadTask in iOS 10 can be used for production App.

How do you resume from where it was left out? The task will be gone when you call cancel(), in my case if I cancel a task, then I will have to create another AVAssetDownloadTask and it will start from the beginning, pretty annoying.

I also have the above questions. Please give me some hint.