[英]Flex Mobile Missing Downloaded File
我正在使用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";
}
使用Motorola 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");
由於安全性違規問題,開發人員只能訪問ApplicationStorageDirectory而不存在任何安全風險。
同時給出文件名MyVideos/video_file.mp4
而不是僅文件夾MyVideos
。
var file:File=File.applicationStorageDirectory.resolvePath("MyVideos/video_file.mp4");
if(file.exists)
{
trace("file exists");
}
喜歡,
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";
}
}
在編寫大型文件(如視頻/音樂文件)時, better use ASYNC mode
寫入/讀取better use ASYNC mode
,這樣您的應用程序就可以在沒有UI凍結的情
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.