Download file in chunks (Windows Phone)

前端 未结 2 1461
抹茶落季
抹茶落季 2020-12-14 13:00

In my application I can download some media files from web. Normally I used WebClient.OpenReadCompleted method to download, decrypt and save the file to IsolatedSto

2条回答
  •  一生所求
    2020-12-14 13:51

    To download a file in chunks you'll need to make multiple requests. One for each chunk.
    Unfortunately it's not possible to say "get me this file and return it in chunks of size X";

    Assuming that the server supports it, you can use the HTTP Range header to specify which bytes of a file the server should return in response to a request.
    You then make multiple requests to get the file in pieces and then put it all back together on the device. You'll probably find it simplest to make sequential calls and start the next one once you've got and verified the previous chunk.

    This approach makes it simple to resume a download when the user returns to the app. You just look at how much was downloaded previously and then get the next chunk.

    I've written an app which downloads movies (up to 2.6GB) in 64K chunks and then played them back from IsolatedStorage with the MediaPlayerLauncher. Playing via the MediaElement should work too but I haven't verified. You can test this by loading a large file directly into IsolatedStorage (via Isolated Storage Explorer, or similar) and check the memory implications of playing that way.

提交回复
热议问题