Save encoded .mp3 to applicationStorageDirectory A

2019-05-24 23:43发布

I'm developing an iOS iPad app w/ Flash CS5.5 AIR v.3.1

I'm using ShineMp3Encoder to encode a Wav to a Mp3 from: https://github.com/kikko/Shine-MP3-Encoder-on-AS3-Alchemy

Basically it converts a byteArray (wav) to a byteArray (mp3) or "mp3encoder.mp3Data" in the code.

I have no trouble saving this using a (new FileReference()).save(mp3Data, filename); but because this is being used in a iOS AIR app I wanted to switch to using the File.applicationStorageDirectory so that I could put the saved mp3 into it's own folder to keep organized. When I run the code it goes through all the steps, converts the wav to mp3, and then says that it saves but doesn't with no errors. The sound IS stored in memory, as it is able to be played back until the app is closed. I've changed the resolvePath to the root folder, myApp/, and to /sounds - None of which work. I've never attempted to do this before so I'm a little lost why no file is being created. Anyone with any suggestions would help a lot.

function onEncoded(e:Event):void{
    myTI.text = "Mp3 encoded and saved. Press Play.";
    mp3encoder.mp3Data.position = 0;
    var myDate:Date = new Date();
    var theDate:String = myDate.monthUTC.toString() + myDate.dayUTC.toString() 
        + myDate.hoursUTC.toString() + myDate.minutesUTC.toString() 
        + myDate.secondsUTC.toString();

    var file:File = File.applicationStorageDirectory.resolvePath("myApp/sounds/myVoice+"+theDate+".mp3");
    var fileStream:FileStream = new FileStream;
    fileStream.open(file,FileMode.UPDATE);
    fileStream.writeBytes(mp3encoder.mp3Data);
    fileStream.close();
}

2条回答
一纸荒年 Trace。
2楼-- · 2019-05-25 00:15

Untested but try this. If it works, modify the filename to be dynamic as you require.

var myfilename:File = File.applicationStorageDirectory;
myfilename = myfilename.resolvePath("myVoice.mp3");


var outputStream:FileStream = new FileStream();
outputStream.open(myfilename,FileMode.WRITE);
outputStream.writeBytes(mp3encoder.mp3Data,0,mp3encoder.mp3Data.length);
outputStream.close();
查看更多
Root(大扎)
3楼-- · 2019-05-25 00:25

I know my answer is little bit late, but maybe it will be useful for somebody who will find this post in future.

When you develop on Windows in Adobe AIR and try to save something in File.applicationStorageDirectory it will NOT saved in the same folder like your swf or fla file.

It will be saved here: C:\Users[WIN_LOGIN]\AppData\Roaming[APP_ID]\Local Store

Your APP_ID you will find and set in Publish Settings for IOS.

查看更多
登录 后发表回答