Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embedding wav files in AS3 Flash/Flex project?

The Flash IDE is capable of embedding many types of uncompressed sound files, including wav, and offers optional compression when publishing.

However, the [Embed] tag, only seems to allow embedding of mp3 files. Is it truly impossible to embed an uncompressed wav file, or am I missing some magic, undocumented mimeType?

I was hoping for something like:

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

...but I get

no transcoder registered for mimeType 'audio/wav'

It's possible to embed wav or other format as an octet-stream and parse at runtime, but that's pretty heavy handed I think.

I'm surprised that even though the Flash IDE can embed uncompressed sound data, [Embed] cannot, given that the swf spec can contain uncompressed sound data.

Any takers?

like image 435
aaaidan Avatar asked May 13 '10 09:05

aaaidan


2 Answers

From the LiveDocs - Basics of working with sound:

[...] 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. [...]

But apparently there's a workaround. Check post #3 in this thread from actionscript.org:

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:

[Embed(source="lib/Sounds.swf", symbol="BigShipSound")]
private static var BigShipSound: Class;
...
var bigShipSound : Sound = BigShipSound as Sound;
bigShipSound.play(0, 20);
like image 91
Baelnorn Avatar answered Sep 18 '22 21:09

Baelnorn


There's a library you can use

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

like image 20
k107 Avatar answered Sep 20 '22 21:09

k107