How to play MP3 sound from buffer (ByteArray/Stream) in ActionScript 3?

actionscript-3, arrays, buffer, mp3, stream

Solution

This one doesn't work since SampleDataEvent.data expects uncompressed raw sample data, not MP3. Use https://github.com/claus/as3swf/wiki/play-mp3-directly-from-bytearray instead.

Problem

So.. I have a buffer with MP3 data (If I would save this buffer and call it buffer.mp3 it would play, but in this situation I should not save it to file system). I have to play it, but I can not, what shall I do? I tried the next code to play that buffrer(ByteArray\Stream) (I get MP3 data from server the method of getting data works fine (tested on text int's etc) I call the returned ByteArray readResponse because I have some seading method and It is it's response). ``` protected function Play(event:MouseEvent):void { var mySound:Sound = new Sound(); mySound.addEventListener(SampleDataEvent.SAMPLE_DATA, soundFill); mySound.play(); } public function soundFill(event:SampleDataEvent):void { event.data.writeBytes(readResponse.buffer, 0, readResponse.buffer.length); } ```

Original source