How to get a certain path for saving and loading an mp3 (AIR for Android)

妖精的绣舞 提交于 2019-12-12 06:15:05

问题


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?


回答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();


来源:https://stackoverflow.com/questions/30515733/how-to-get-a-certain-path-for-saving-and-loading-an-mp3-air-for-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!