When fiddling with using zip in Flex/As3, I discovered that the Sound class doesn’t have a .loadBytes method (corresponding to the Loader class .loadBytes method). I was able to get the byteArray data out of the zip, but no way to feed a Sound object with it! Grr..!
Luckily, there are lots of gifted bravehearts and generous brightheads around in the blogosphere!
Thanks to article by Chris at flexiblefactory.co.uk about reading sound from a FileReference, I could make it work! Here is how his elegant solution works – well, at least “kind of how”…:
- Reading the mp3 bytearray code from the file
- Building a SWF from the ground up, including the messy header stuff, and embedding the mp3 data into it
- Loading the SWF into a Loader object, and typecast it from there as a SoundClass to a Sound object
- Play! π
Thank you, Chris!
Posted in: Actionscript 3, Flex
biggyspender
July 8, 2009
Always good to see people using my code. /chris
chris j
August 21, 2009
Very nice solution. What next?
shammi
May 14, 2010
hi can i see the sample file. i need to extract some portions of the mp3 file and save it as a new sound object that can be played not the entire song. then later-on i want all the sound playing to be mixed and saved as a mp3 file. like a sound mixing application.
Prasad
June 29, 2011
This method only works for standard sampling frequencies that are multiples of 11. For instance, in my case, i have a 16 kHz mp3 file. Flash converts these frequencies to the appropriate multiple of 11, but that isn’t possible if you’re creating a sound object that is loaded with the 16khz file to begin with. I’d probably need to try to convert a portion of the lame encoder via alchemy up convert the sampling rate.