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 triggers a pop up and asks the user where to save the mp3 file.
How can I prevent this pop up from AIR?
I need a path for saving that sound and I want to load and play that sound later.
Can someone help me find a way to prevent having to get the path from the user and instead use a fixed path that I can load back in later?
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();