May 13th, 2009
Working with audio can be pretty limiting in the Flash Player. There’s a multitude of audio formats out there, but heretofore the only native support is for MP3 and AAC (the latter arriving only as recently as the beta releases of Flash Player 9, so long as the file has been encoded in the correct fashion.)
This leaves out a number of still-popular formats, particularly OGG, WMA, and Real. WMA is a common format for those who encode audio with Windows Media Player (as well as many streaming online radio stations). While Real is fading from view, OGG continues to grow in popularity, particularly due to the fact that it is open-source and requires no licensing fees to broadcast.
Fortunately we can add another format to the list. Adobe’s labs release of Alchemy allows us to compile C/C++ code, with a bit of tweaking, into a precompiled SWC file that can then be accessed from ActionScript. The sample library includes an OGG codec, which you can use either directly or within a wrapper class recently published by Maurice Zarzycki. This makes playing back OGG files as simple as:
oggDecoder = new OggRadio(yourUrl); oggDecoder.play();
While playing OGG files does appear to be more CPU intensive than MP3, I’m impressed for its stability; I’ve yet to find an OGG file it couldn’t handle.
This opens the debate as to what other C++ libraries might be of use in SWF or AIR. Along the lines of audio, there is still the WMA format, which though propriety technology of Microsoft, has an open-source codec, libwma, developed by FFmpeg and further reworked into SoundCodecWMA by the Rockbox team. How difficult it would be to translate this into Flash Player functionality using Alchemy to build a SWC?