as3 android salvando sons remotos em sdcard - acessando mais tarde?
Este código é muito legal! Tente. Ele cria uma pasta no seu usuário chamada .007 e salva um mp3 chamado yahoo.mp3.
Ele também fará isso em um dispositivo Android se as permissões estiverem definidas corretamente.
Depois de criar uma pasta e salvar o mp3, ele passará pela pasta e obterá o caminho do arquivo e o nome do arquivo.
MINHA PERGUNTA É:Como você acessa e toca o som no Android? Ele funciona na área de trabalho, como você pode ver se você testá-lo, mas não no droid. Alguma idéia por quê?
import flash.filesystem.*;
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
{
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.");
var desktop:File = File.userDirectory.resolvePath(".0");
var files:Array = desktop.getDirectoryListing();
for (var i:uint = 0; i < files.length; i++)
{
trace(files[i].nativePath);// gets the path of the files
trace(files[i].name);// gets the name
var mySound:Sound = new Sound();
var myChannel:SoundChannel = new SoundChannel();
var lastPosition:Number = 0;
mySound.load(new URLRequest(files[0].nativePath));
myChannel = mySound.play();
}
}