【问题标题】:How to save a file (mp4 or pdf) loaded with StageWebView to iPhone directory?如何将使用 StageWebView 加载的文件(mp4 或 pdf)保存到 iPhone 目录?
【发布时间】:2012-04-13 11:43:26
【问题描述】:

我正在使用 StageWebView 在我的 iPhone 应用程序中加载 mp4 和 pdf 文件(适用于 iOS 的 Adob​​e air 3.2,在 Flash CS5.5 中)

下面是我用来加载 pdf 文件的代码(加载 mp4 文件的代码相同)。

我需要将文件保存在 iPhone 上,所以下次用户打开应用程序时,我会检查文件是否存在,我会使用 FileStream.open(filePath, FileMode.READ); 加载它。 有没有办法保存使用 StageWebView 加载的文件?如果没有,最好的方法是什么。

import flash.filesystem.FileMode;
import flash.filesystem.FileStream;
import flash.filesystem.File;

var fPath:String = "http://www.bloomerangs.com/Axor/Water-Bath-Design Museum - short version.pdf";

var webView = new StageWebView();
webView.stage = stage;
webView.viewPort = new Rectangle(0, 32, 320, 480);
webView.addEventListener(Event.COMPLETE, onComplete);
webView.loadURL( fPath );

function onComplete(event:Event):void{
    trace("event = ", event);
    trace("event.target = ", event.target);
}

提前致谢! :)

【问题讨论】:

    标签: actionscript-3 flash air


    【解决方案1】:

    您想节省带宽(缓存几个文件),对吗?然后您可以将文件下载(保存)到 File.applicationStorageDirectory(使用 URLStream)并稍后使用 StageWebView(http://forums.adobe.com/thread/928558)打开它

    Downloading and saving files with AIR for iOs

    【讨论】:

    • 感谢@Pavel fljōt 我已使用 URLLoader 加载(下载)文件。你怎么看? (下面我的答案中的代码)
    【解决方案2】:

    谢谢帕维尔 fljōt。

    我已使用 URLLoader 进行文件下载。

    import flash.events.Event;
    import flash.filesystem.FileMode;
    import flash.filesystem.FileStream;
    import flash.filesystem.File;
    
    var urlLoader = new URLLoader();
    urlLoader.dataFormat = URLLoaderDataFormat.BINARY;
    urlLoader.addEventListener(ProgressEvent.PROGRESS, onLoadFileProgress);
    urlLoader.addEventListener(Event.COMPLETE, onLoadFileComplete);
    urlLoader.load(new URLRequest("http://www.yourdomain.com/videos/myVideo.mp4"));
    
    function onLoadFileProgress(e:ProgressEvent):void{
        var loadedPct:uint = Math.round(100 * (e.bytesLoaded / e.bytesTotal));
        trace_txt.text = loadedPct + "% loaded.";
    }
    
    function onLoadFileComplete(e:Event):void{
        trace_txt.text = "File loaded";
        var file:File = File.documentsDirectory.resolvePath("myVideo_copied.mp4")
        var fileStream:FileStream = new FileStream();
        fileStream.openAsync(file, FileMode.WRITE);
        fileStream.addEventListener(OutputProgressEvent.OUTPUT_PROGRESS, outputProgressHandler);
        fileStream.addEventListener(Event.CLOSE, onVideoSaveClose);
        fileStream.writeBytes(e.target.data);
        fileStream.close();
    }
    function outputProgressHandler(event:OutputProgressEvent):void{
        if (event.bytesPending == 0){
            trace_txt.text = "File is completely written";
        }
    }
    
    var stageWebView = new StageWebView();
    function onVideoSaveClose(event:Event):void {
        trace("closed");
        stageWebView.stage = this.stage;
        stageWebView.viewPort = new Rectangle(0, 0, 1024, 768);
        var file:File = File.documentsDirectory.resolvePath("myVideo_copied.mp4")
        stageWebView.loadURL(file.url);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-08-16
      • 1970-01-01
      • 2015-08-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多