Skip to main content
Lorenzo Nuvoletta
Inspiring
Feb 14, 2013 2:10 AM UTC
Answered

Playing an MP3 Sound using its ByteArray

With AS3 we can do this to load an MP3 and play it:

var sound:Sound = new Sound( new URLRequest("sound.mp3") );

sound.play();

That is very easy, but what if I already have the entire ByteArray of that MP3 loaded and I want to simply play it?

Why cant AS3 have a simple method to simply pass the ByteArray working exactly like it works now passing a URLRequest?

In my case I need this because I am loading a ZIP file containing a bunch of MP3s and when I uncompress it I can read the bytearray of each MP3 but I can't play them.

This topic is closed to new replies. Start a new post to keep the conversation going.
Jacob CorreiaCorrect answer
Participating Frequently
Mar 3, 2013 4:31 AM UTC

Have you tried loadCompressedDataFromByteArray in the Sound class?


Assuming you have the ByteArray already instantiated, try:

var sound:Sound = new Sound();

sound.loadCompressedDataFromByteArray ( mp3Bytes, mp3Bytes.length );

sound.play();

4 replies

Jacob CorreiaCorrect answer
Participating Frequently
Mar 3, 2013 4:31 AM UTC

Have you tried loadCompressedDataFromByteArray in the Sound class?


Assuming you have the ByteArray already instantiated, try:

var sound:Sound = new Sound();

sound.loadCompressedDataFromByteArray ( mp3Bytes, mp3Bytes.length );

sound.play();

Translate
Lorenzo Nuvoletta
Inspiring
Mar 4, 2013 6:22 PM UTC

Awesome. thanks I was not aware of this new method.

Translate
Lorenzo Nuvoletta
Inspiring
Mar 2, 2013 1:40 AM UTC

Anyone knows?

Translate