暂停和柔性恢复下载? [英] Pause and resume download in flex?

查看:199
本文介绍了暂停和柔性恢复下载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能在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);
}

这篇关于暂停和柔性恢复下载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆