菜鸟教程小白 发表于 2022-12-11 20:51:51

ios - 将编码的 .mp3 保存到 applicationStorageDirectory Adob​​e Air iOS


                                            <p><p>我正在开发一个带有 Flash CS5.5 AIR v.3.1 的 iOS iPad 应用程序</p>

<p>我正在使用 ShineMp3Encoder 将 Wav 编码为 Mp3,来自:
<a href="https://github.com/kikko/Shine-MP3-Encoder-on-AS3-Alchemy" rel="noreferrer noopener nofollow">https://github.com/kikko/Shine-MP3-Encoder-on-AS3-Alchemy</a> </p>

<p>基本上它在代码中将 byteArray (wav) 转换为 byteArray (mp3) 或“mp3encoder.mp3Data”。</p>

<p>我可以使用 (new FileReference()).save(mp3Data, filename);但是因为这是在 iOS AIR 应用程序中使用的,所以我想切换到使用 File.applicationStorageDirectory 以便我可以将保存的 mp3 放入它自己的文件夹中以保持井井有条。当我运行代码时,它会完成所有步骤,将 wav 转换为 mp3,然后说它保存但没有错误。声音存储在内存中,因为它可以在应用程序关闭之前播放。我已将 resolvePath 更改为根文件夹 myApp/和/sounds - 这些都不起作用。我以前从未尝试过这样做,所以我有点迷失为什么没有创建文件。任何有任何建议的人都会有很大帮助。</p>

<pre><code>function onEncoded(e:Event):void{
    myTI.text = &#34;Mp3 encoded and saved. Press Play.&#34;;
    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(&#34;myApp/sounds/myVoice+&#34;+theDate+&#34;.mp3&#34;);
    var fileStream:FileStream = new FileStream;
    fileStream.open(file,FileMode.UPDATE);
    fileStream.writeBytes(mp3encoder.mp3Data);
    fileStream.close();
}
</code></pre></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>未经测试,但试试这个。如果可行,请根据需要将文件名修改为动态。</p>

<pre><code>var myfilename:File = File.applicationStorageDirectory;
myfilename = myfilename.resolvePath(&#34;myVoice.mp3&#34;);


var outputStream:FileStream = new FileStream();
outputStream.open(myfilename,FileMode.WRITE);
outputStream.writeBytes(mp3encoder.mp3Data,0,mp3encoder.mp3Data.length);
outputStream.close();
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 将编码的 .mp3 保存到 applicationStorageDirectory Adob​​e Air iOS,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/8731039/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/8731039/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 将编码的 .mp3 保存到 applicationStorageDirectory Adob​​e Air iOS