为Android下载并保存远程文件AS3空气 [英] as3 Air for Android downloading and saving remote files

查看:271
本文介绍了为Android下载并保存远程文件AS3空气的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在code以下下载使用AS3空气Android的一台服务器一个MP3到手机上。我想在应用程序后使用这些文件,所以我有以下问题:

The Code below downloads an mp3 to your phone from a server using as3 Air For Android. I want to use these files later in the app so I have the following question:

我怎样才能使它所以将文件保存到特定的文件夹中的Andr​​oid应用程序,而不是一个盒子开口,选择一个位置的用户?

import flash.net.FileReference;

/// It can be an mp3,jpg, png, etc... just change the url
/// and the extension name. nice huh?
var yourFileLocation = "http://YourWeb.com/YourSong.mp3";
var yourFileName = "YourSong.mp3";

var daFile:FileReference = new FileReference();
daFile.download(new URLRequest(yourFileLocation), yourFileName);

也将是甜蜜的监测这一进展,当它启动,停止和进步,但我认为的EventListener可能的工作这一点。

Would also be sweet to monitor this progress, when it starts, stops and progress but I think an eventListener might work with that.

推荐答案

下面code下载来自远程URL一个mp3,使一个文件夹,名为 0.007 (你可以改名字或添加许多或没有文​​件夹)。然后将其保存到该位置。

The Following Code downloads an mp3 from a remote url and makes a folder called .007(You can change the name or add many or no folders). Then it saves to that location.

import flash.filesystem.*;
/// Change the line below to point to your mp3 online
var urlString:String = "http://YourWebsite.com/YourSound.mp3";
var urlReq:URLRequest = new URLRequest(urlString);
var urlStream:URLStream = new URLStream();
var fileData:ByteArray = new ByteArray();
urlStream.addEventListener(Event.COMPLETE, loaded);
urlStream.load(urlReq);

function loaded(event:Event):void
{
    urlStream.readBytes(fileData, 0, urlStream.bytesAvailable);
    writeAirFile();
}

function writeAirFile():void
{ 
    // Change the folder path to whatever you want plus name your mp3
    // If the folder or folders does not exist it will create it.
    var file:File = File.userDirectory.resolvePath(".007/Yahoo.mp3");
    var fileStream:FileStream = new FileStream();
    fileStream.open(file, FileMode.WRITE);
    fileStream.writeBytes(fileData, 0, fileData.length);
    fileStream.close();
    trace("The file is written.");
}

P.S。记得授予采用Android正确的权限在APP

这篇关于为Android下载并保存远程文件AS3空气的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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