Skip to content Skip to sidebar Skip to footer

How To Get A Certain Path For Saving And Loading An Mp3 (AIR For Android)

I'm using shine mp3 encoder for saving an mp3 file. It has a saveFile method that can save an mp3 file. When that method runs (with only one argument name:String), it automatically

Solution 1:

Here is an example using the File and FileStream classes in AIR - Which lets you save a file synchronously (or asynchronously) without user interaction.

Let's say your shine mp3 object is in a var called myMp3:

First, get a reference to your file (doesn't matter if it exists yet or not), use this same file for saving and loading:

var file:File = File.applicationStorageDirectory.resolvePath("MyMP3Name.mp3");
//applicationStorageDirectory is most appropriate place to save data for your app, and probably also the only place you'll have permission to do so

To Save

var stream:FileStream = new FileStream();
sream.open(file, FileMode.WRITE);
stream.writeBytes(myMp3.mp3Data); //write the byte array to the file
stream.close();

To Load (using the same File object from above)

var stream:FileStream = new FileStream();
    stream.open(file, FileMode.READ);

var sound:Sound = new Sound();
var mp3Bytes:ByteArray;
stream.readBytes(mp3Bytes); //read the bytearray in the file into the mp3Bytes var
stream.close();

sound.loadCompressedDataFromByteArray(mp3Bytes); //load that byte array into the sound object

sound.play();

Post a Comment for "How To Get A Certain Path For Saving And Loading An Mp3 (AIR For Android)"