Android Flex Mobile缺少下载的文件
我正在使用Flex和Flash Builder开发Android应用程序。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
我使用以下代码使用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";
}
}