0
votes

I read How to play MP3 sound from buffer (ByteArray/Stream) in ActionScript 3?. And really want to do that.

From adobe: http://help.adobe.com/en_US/FlashPlatform/beta/reference/actionscript/3/flash/media/Sound.html#loadCompressedDataFromByteArray()

My codes:

private function playBase64(content:String):void {
  var mp3Bytes:ByteArray;
  var mp3Sound:Sound = new Sound();
  mp3Bytes = Base64.decodeToByteArray(content);
  mp3Bytes.position = 0;
  mp3Sound.loadCompressedDataFromByteArray(mp3Bytes, mp3Bytes.length);
  mp3Sound.play();
}

But I get:

Warning: Running "mxmlc:all" (mxmlc) task
    >> Error: Command failed: /Users/michaeljin/git/yinlang/training/node_modules/flex-sdk/lib/flex_sdk/bin/mxmlc -debug=true -optimize=true -library-path=client/assets/flash/libs -output client/assets/flash/YLSoundPlayer.swf -- client/assets/flash/YLSoundPlayer.as
    >> /Users/michaeljin/git/yinlang/training/client/assets/flash/YLSoundPlayer.as(59): col: 16 Error: Call to a possibly undefined method loadCompressedDataFromByteArray through a reference with static type flash.media:Sound.
    >>
    >>       mp3Sound.loadCompressedDataFromByteArray(mp3Bytes, mp3Bytes.length);
    >>                ^
    Warning: FAILED Use --force to continue.

    Aborted due to warnings.

Edit: Found out it works with mxmlc 4.6, but not with 4.0

1
It would be helpful if you quoted what you think is pertinent from the function's documentation, after all the text isn't much longer than the link you've posted...eirikdaude
I think this method exists which adobe show it in the document. But it doesn't work for me.emj365
Maybe the string you encoded does not decode into a valid MP3? There are limits on what MP3s does Flash support for conversion to Sound objects.Vesper

1 Answers

0
votes

You are targeting an FP version < 11, target Flash Player 11 at least to have this method available.