Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/209.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Flex Mobile缺少下载的文件_Android_Apache Flex_Actionscript_Flash Builder_Flex Mobile - Fatal编程技术网

Android Flex Mobile缺少下载的文件

Android Flex Mobile缺少下载的文件,android,apache-flex,actionscript,flash-builder,flex-mobile,Android,Apache Flex,Actionscript,Flash Builder,Flex Mobile,我正在使用Flex和Flash Builder开发Android应用程序。 我使用以下代码使用URLLoader和FileStream下载了一段视频 public function download():void{ var loader:URLLoader = new URLLoader(); loader.dataFormat = URLLoaderDataFormat.BINARY; loader

我正在使用Flex和Flash Builder开发Android应用程序。
我使用以下代码使用URLLoader和FileStream下载了一段视频

public function download():void{
                var loader:URLLoader = new URLLoader();
                loader.dataFormat = URLLoaderDataFormat.BINARY;
                loader.addEventListener(IOErrorEvent.IO_ERROR,function(e:IOErrorEvent):void{
                    progressLabel.text = "Loader IO Error";
                });
                loader.addEventListener(Event.COMPLETE,downloadComplete);
                loader.load(new URLRequest("[MY URL GOES HERE]"));
                progressLabel.text = "Downloading...";
            }
private function downloadComplete(event:Event):void{
                try{
                    var file:File=File.applicationStorageDirectory.resolvePath("file:///mnt/sdcard/MyVideos");

                var ba:ByteArray  = event.target.data as ByteArray;
                var fileStream:FileStream = new FileStream();
                fileStream.addEventListener(IOErrorEvent.IO_ERROR,function(e:IOErrorEvent):void{
                    progressLabel.text = "File IO Error";
                });
                fileStream.open(file, FileMode.WRITE);
                fileStream.writeBytes(ba);
                fileStream.addEventListener(Event.COMPLETE, fileClosed); 
                fileStream.close(); 
                progressLabel.text = "Download Sucessful";
            }
            catch(eeee){
                progressLabel.text = "Error";
            }
        }
        private function fileClosed(event:Event):void {
            openLabel.text = "File Closed";
        }
使用摩托罗拉Xoom进行测试时,显示下载成功,但在目录中找不到该文件:

var file:file=file.applicationStorageDirectory.resolvePath(“file:///mnt/sdcard/MyVideos");

使用
File.applicationStorageDirectory.resolvePath(“MyVideos/video_File.mp4”)而不是
File.applicationStorageDirectory.resolvePath(“file:///mnt/sdcard/MyVideos");
由于存在安全违规问题,因此开发人员只能访问ApplicationStorage Directory,而不存在任何安全风险

同时给出文件名
MyVideos/video\u file.mp4
,而不是只给出文件夹
MyVideos

var file:File=File.applicationStorageDirectory.resolvePath("MyVideos/video_file.mp4");

if(file.exists)
{
    trace("file exists");
}


在编写大型文件(如视频/音乐文件)时,最好使用异步写入/读取模式,这样应用程序就不会冻结用户界面。

Wow。谢谢但是,有没有办法将下载的mp4存储到SD卡上?是的,您可能需要更改应用程序XML描述符文件,之后您可以将更多详细信息写入SD卡。谢谢。
private function downloadComplete(event:Event):void
{
    try
      {
        var file:File=File.applicationStorageDirectory.resolvePath("MyVideos/video_file.mp4");

        var ba:ByteArray  = event.target.data as ByteArray;
        var fileStream:FileStream = new FileStream();
        fileStream.addEventListener(IOErrorEvent.IO_ERROR,function(e:IOErrorEvent):void{
            progressLabel.text = "File IO Error";
        });
        fileStream.open(file, FileMode.WRITE);
        fileStream.writeBytes(ba);
        fileStream.addEventListener(Event.COMPLETE, fileClosed); 
        fileStream.close(); 
        progressLabel.text = "Download Sucessful";
        trace(file.nativePath); //Where file actually stored
    }
    catch(eeee){
        progressLabel.text = "Error";
    }
}