问题描述
我有一个旧文件格式,其中包含嵌入其中的声音(以各种编码).我希望能够通过从文件中读取声音字节并用它们实例化 Sound 对象来在 Flash(Air?)中播放这些声音.
I have a legacy file format that contains sounds embedded in it (in various encodings). I would like to be able to play these sounds in Flash (Air?) by reading the sound bytes out of the file and instantiating a Sound object with them.
如果声音未编码(例如原始 pcm),我发现我可以使用新的 flex 4 SampleDataEvent.SAMPLE_DATA 事件来播放声音.
If the sound is unencoded (e.g., raw pcm), I've found that I can use the new flex 4 SampleDataEvent.SAMPLE_DATA event to play the sound.
但是,如果声音被编码(例如,mp3),那么我会不知所措.SampleDataEvent.SAMPLE_DATA 预期的声音必须是原始 pcm.据我所知,编码的声音只能通过 [嵌入] 来实例化,或者使用带有 Sound.load() 的 URLRequest.
However, if the sound is encoded (e.g., mp3), then I'm at a loss. The sound expected by SampleDataEvent.SAMPLE_DATA has to be raw pcm. From what I've seen, encoded Sounds can only be instantiated by [Embed]ing them, or by using a URLRequest with Sound.load().
当然有第三种方式吗?AMF 还是 e4x?
Surely there's a third way? AMF or e4x?
推荐答案
实际上只有两条路可以走.第一种是在 ActionScript 中编写解码器.您可以使用 Alchemy 来移植一些 C/C++ 代码,从而使这项工作变得更加容易(并且可能更高效).这正是我让 Ogg Vorbis 播放与 Flash 配合使用的方式.
There are really only two routes for you to go. The first is to write a decoder in ActionScript. You may be able to use Alchemy to port over some C/C++ code to make this job significantly easier (and possibly more performant). This is exactly how I got Ogg Vorbis playback to work with Flash.
另一种选择是在 ByteArray 内动态创建有效的 SWF.该 SWF 可以包含由您的声音数据组成的嵌入声音对象.在 Flash Player 10 可用之前,许多人过去已经完成了类似的黑客攻击.我相信您可以在 Andre Michelle 和 Joa Ebert 的 PopForge 代码库中找到一个很好的起点.
The other option is to dynamically create a valid SWF inside of a ByteArray. That SWF could contain an embedded sound object that was made up of your sound data. A number of folks have pulled off similar hacks in the past before Flash Player 10 was available. I believe you can find a good place to start in Andre Michelle's and Joa Ebert's PopForge codebase.
这篇关于在 flex 中,从编码字节动态加载 Sound 对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!