暂停和柔性恢复下载?柔性

由网友(你还好么久违的旧人。)分享简介:是否有可能在AIR应用程序开始下载,暂停,之后恢复它? Is it possible in an air application to start a download, pause it and after that resume it? 我想下载很大的文件(1-3Gb),我需要确定,如果连接的是下一次用户试图下...

是否有可能在AIR应用程序开始下载,暂停,之后恢复它?

Is it possible in an air application to start a download, pause it and after that resume it?

我想下载很大的文件(1-3Gb),我需要确定,如果连接的是下一次用户试图下载它从最后一个位置开始文件中断,那么。

I want to download very big files (1-3Gb) and I need to be sure if the connection is interrupted, then the next time the user tries to download the file it's start from the last position.

任何想法和源$ C ​​$ C样品将AP preciated。

Any ideas and source code samples would be appreciated.

推荐答案

是的,你想用的 URLStream类(的URLLoader不支持部分下载)和的 HTTP Range头。需要注意的是有范围头部上的一些繁重的安全限制,但它应该是罚款AIR应用程序。下面是一些未经检验的code,应该给你的总体思路。

Yes, you would want to use the URLStream class (URLLoader doesn't support partial downloads) and the HTTP Range header. Note that there are some onerous security restrictions on the Range header, but it should be fine in an AIR application. Here's some untested code that should give you the general idea.

private var _us:URLStream;
private var _buf:ByteArray;
private var _offs:uint;
private var _paused:Boolean;
private var _intervalId:uint;
...
private function init():void {
    _buf = new ByteArray();
    _offs = 0;

    var ur:URLRequest = new URLRequest( ... uri ... );
    _us = new URLStream();

    _paused = false;
    _intervalId = setInterval(500, partialLoad);
}
...
private function partialLoad():void {
    var len:uint = _us.bytesAvailable;
    _us.readBytes(_buf, _offs, len);
    _offs += len;

    if (_paused) {
        _us.close();
        clearInterval(_intervalId);
    }
}
...
private function pause():void {
    _paused = true;
}
...
private function resume():void {
    var ur:URLRequest = new URLRequest(... uri ...);
    ur.requestHeaders = [new URLRequestHeader("Range", "bytes=" + _offs + "-")];
    _us.load(ur);
    _paused = false;
    _intervalId = setInterval(500, partialLoad);
}
阅读全文

相关推荐

最新文章