views:

437

answers:

2

Is it possible to pause / resume downloads with the URLStream object?

+1  A: 

I don't think it's possible using URLStream, but I think you could achieve the pause / resume ability using a Socket.

This requires setting up proper socket policies, which is a bit of a hassle and that the server accepts bytes ranges. See byte serving and RFC2616.

The idea is that you'd mantain a count of how many bytes you've read from the current response. When you want to pause, you'd close the connection. For resuming you'd reopen the connection again and send an http GET request, specifying a byte range that begins at the byte count you stored (i.e. you're picking up where you left off).

Keep in mind this is just an idea. I'm not sure if closing and reopening connections is the most optimal solution. It's probably not rocket science but involves some work to implement it right. And, as I said, I think something like this should work, but I haven't tried it myself, so I'm not 100% sure. But maybe it's worth trying.

Juan Pablo Califano
Interesting idea, but bear in mind: Using a socket will means the SWF won't work through proxy servers.
Chris W. Rea
+1  A: 

It's possible to pause/resume the URLStream using the method outlined here. Unfortunately, this method will only work within AIR.

If you're using AIR, you'll still need to check that the Response Header sent back from the server includes:

Accept-Ranges: bytes

If you have that, you should be able to use the same method.

Drew Miller
+1 - in case there is any doubt from the link, I have that approach working on an app.
eglasius