OGeek|极客世界-中国程序员成长平台

标题: ios - 将编码的 .mp3 保存到 applicationStorageDirectory Adob​​e Air iOS [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 20:51
标题: ios - 将编码的 .mp3 保存到 applicationStorageDirectory Adob​​e 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 myDateate = 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();
}



Best Answer-推荐答案


未经测试,但试试这个。如果可行,请根据需要将文件名修改为动态。

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

关于ios - 将编码的 .mp3 保存到 applicationStorageDirectory Adob​​e Air iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8731039/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4