I'm developing an android app using adobe flash cs5.5 AIR. I have a simple sound button that playing a sound clip. I want to save this music1.mp3
file into phone or tab SD card memory using Button called save. I don't know how to do that. Can anyone have answer..?
This is a example script that im using:
musicbtn.addEventListener(MouseEvent.CLICK, fl_ClickToPlayStopSound);
var fl_SC:SoundChannel;
var fl_ToPlay:Boolean = true;
function fl_ClickToPlayStopSound(evt:MouseEvent):void
{
if (fl_ToPlay)
{
var s:Sound = new Sound(new URLRequest("sound/music1.mp3"));
fl_SC = s.play();
}
else
{
fl_SC.stop();
}
fl_ToPlay = !fl_ToPlay; }
You can save to an andriod sd card in adobe AIR through the File class.
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/filesystem/File.html
var soundfile:File = File.applicationStorageDirectory.resolvePath("music1.mp3");
var fstream:FileStream = new FileStream();
fstream.open(soundfile, FileMode.WRITE);
fstream.writeBytes(ba, 0, ba.length);
fstream.close();
where ba is a ByteArray containing the music data. If you are not sure how to do that I include it below.
Using the extract function in the Sound class we can extract a sound file to a byteArray. Check out the link for the documentation:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/media/Sound.html#extract()
ByteArray ba;
sound.extract(ba, 4096);
You can then compress this byteArray using different compression algorithms (it may save some space since you are going for mobile), but if you do so, you will have to decompress them in your code when you want to play them.