as3 android guardando sonidos remotos en sdcard - ¿acceder más tarde?
¡Este código es genial! Intentalo. Crea una carpeta en su usuario llamada .007 y guarda un mp3 llamado yahoo.mp3.
También lo hará en un dispositivo Android si los permisos están configurados correctamente.
Una vez que crea una carpeta y guarda el mp3, pasará por la carpeta y obtendrá la ruta del archivo y el nombre del archivo.
MI PREGUNTA ES:¿Cómo acceder a él y reproducir el sonido en Android? Funciona en el escritorio como puede ver si lo prueba, pero no en el droide. ¿Alguna idea de 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();
}
}