views:

130

answers:

2

Having had a quick look at the Flex docs I can't seem to find any reference to providing audio content to be played from a custom (possibly encrypted - don't worry, it's not that evil) container format. Is this possible and if so, could someone point me in the right direction.

Or if that's not possible, some way to hook into the disk/network (disk is much more important in this case) I/O of the sound playing mechanism to provide a supported container in memory from a custom wrapper.

+1  A: 

Since Flash Player 10, it's posible to write PCM / raw audio data to a Sound Object.

Basically, you call play on an "empty" Sound Object and it will start dispatching periodically a SampleDataEvent, requesting data. You then can write to the audio stream through the data ByteArray exposed by the event object.

http://help.adobe.com/en_US/FlashPlatform//reference/actionscript/3/flash/events/SampleDataEvent.html?filter_flex=4

http://www.adobe.com/devnet/flash/articles/dynamic_sound_generation/index.html

Also, if you're interested in good articles and reference for audio programming in Actionscript, you might want to check out Andre Michelle's stuf:

http://blog.andre-michelle.com/

http://lab.andre-michelle.com/

Juan Pablo Califano
Unfortunately this doesn't really cover what I need to do, since I'd need to decode the MP3 to PCM audio in ActionScript and while this looks doable, it hardly has acceptable performance. Since providing the Sound Object with MP3 data doesn't look possible, maybe someone knows of a way to hijack the file I/O?
Joonas Trussmann
Mm, I see. I thought you already had access to the PCM raw data, since you said you had some audio custom format. I agree that a real time mp3 decoder will probably be too taxing on the CPU (and quite a lot of work as well). I doubt you can hijack the file I/O, though.
Juan Pablo Califano
A: 

A flash.media.Sound must either be:

  • constructed/loaded with a URLRequest,
  • inherit its data through embedding

There currently is no provision for directly piping mp3 (or aac, or video) data to a any "media" object, such as Sound. You can only get the Sound object to download the data for itself. There are people who are upset about this, including myself; you are not alone!

I say "at this stage" because it's not unthinkable that Adobe will update the API to make this possible in a future version. For the now, you're best to go with the decoding-to-a-dynamic-sound workaround mentioned by Juan, if you really need to be able to do this.

And post a feature request at Adobe's bug tracker, or vote on an existing one!

aaaidan