将编码的 .mp3 保存到 applicationStorageDirectory Adobe Air iOS
我正在开发一个带有 Flash CS5.5 AIR v.3.1 的 iOS iPad 应用程序
我正在使用 ShineMp3Encoder 将 Wav 编码为 Mp3: https://github.com/kikko/Shine-MP3-Encoder-on -AS3-Alchemy
基本上它将 byteArray (wav) 转换为 byteArray (mp3) 或代码中的“mp3encoder.mp3Data”。
我使用 (new FileReference()).save(mp3Data, filename); 保存它没有问题。但因为这是在 iOS AIR 应用程序中使用的,所以我想切换到使用 File.applicationStorageDirectory,以便我可以将保存的 mp3 放入它自己的文件夹中以保持组织。当我运行代码时,它会执行所有步骤,将 wav 转换为 mp3,然后说它已保存,但没有出现任何错误。声音存储在内存中,因为它可以播放,直到应用程序关闭。我已将resolvePath 更改为根文件夹myApp/ 和/sounds - 这些都不起作用。我以前从未尝试过这样做,所以我有点迷失为什么没有创建文件。任何有任何建议的人都会有很大帮助。
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();
}
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();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
未经测试但尝试这个。如果有效,请根据需要将文件名修改为动态。
Untested but try this. If it works, modify the filename to be dynamic as you require.
我知道我的回答有点晚了,但也许它对将来发现这篇文章的人有用。
当您在 Windows 上使用 Adobe AIR 进行开发并尝试将某些内容保存在 File.applicationStorageDirectory 中时,它不会保存在与 swf 或 fla 文件相同的文件夹中。
它将保存在这里:
C:\Users[WIN_LOGIN]\AppData\Roaming[APP_ID]\Local Store
您可以在 IOS 的发布设置中找到并设置您的 APP_ID。
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.