关于 actionscript 3:在 AS3 Flash/Flex 项目中嵌入 wav 文件?

Embedding wav files in AS3 Flash/Flex project?

Flash IDE 能够嵌入多种类型的未压缩声音文件,包括 wav,并在发布时提供可选压缩。

然而,[Embed] 标签似乎只允许嵌入 mp3 文件。是否真的不可能嵌入未压缩的 wav 文件,还是我错过了一些神奇的、未记录的 mimeType?

我希望得到类似的东西:

1
[Embed source="../../audio/wibble.wav" mimeType="audio/wav"]

...但我明白了

1
no transcoder registered for mimeType 'audio/wav'

可以将 wav 或其他格式嵌入为八位字节流并在运行时解析,但我认为这相当繁琐。

令我惊讶的是,即使 Flash IDE 可以嵌入未压缩的声音数据,[Embed] 却不能,因为 swf 规范可以包含未压缩的声音数据。

有接受者吗?


来自 LiveDocs - 使用声音的基础知识:

[...]
Although there are various sound file
formats used to encode digital audio,
ActionScript 3.0, Flash Player and AIR
support sound files that are stored in
the mp3 format. They cannot directly
load or play sound files in other
formats like WAV or AIFF.
[...]

但显然有一种解决方法。检查来自 actionscript.org 的此线程中的帖子 #3:

Replying to myself in case anyone has
the same question in the future and is
searching for an answer.

I couldn't find any direct support for
embedding WAV files in a Flex Builder
3 / ActionScript 3 application. What I
did try and was delighted to see it
works is to create a Flash Movie in
Flash CS 3 (you will need to own that
or get an evaluation) and import your
sounds to the library and link them to
be exported by ActionScript. Export
the Flash CS3 project to a SWF movie
and save it in your project (I added
it to a"lib folder").

Your ActionScript code to create and
play the sound should be:

1
2
3
4
5
[Embed(source="lib/Sounds.swf", symbol="BigShipSound")]
private static var BigShipSound: Class;
...
var bigShipSound : Sound = BigShipSound as Sound;
bigShipSound.play(0, 20);


有一个你可以使用的库

http://code.google.com/p/as3wavsound/


Flash 播放器不知道如何直接播放 wav 文件。确实可以将它们导入创作工具,但是当您发布 SWF 时,您的音频将被转换为 mp3 或 adpcm 或您在发布设置中选择的任何内容。即使您在运行时读取 wav,播放它的唯一方法是解析二进制流,因此如果您嵌入文件,自然会有相同的限制。

这个问题的一些相关信息。奇怪的是,你似乎在去年发表了评论! :)