如何在ActionScript 3中从缓冲区(ByteArray/Stream)播放MP3声音?

Rel*_*lla 12 mp3 buffer bytearray stream actionscript-3

所以..我有一个MP3数据缓冲区(如果我保存这个缓冲区,并将其称为buffer.mp3它将播放,但在这种情况下,我不应该将它保存到文件系统).我必须玩它,但我不能,我该怎么办?


我尝试了下一个代码来播放该缓冲区(ByteArray\Stream)(我从服务器获取MP3数据,获取数据的方法工作正常(在文本int上测试等)我调用返回的ByteArray readResponse,因为我有一些seading方法,它是这是回应).

            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);  
        }
Run Code Online (Sandbox Code Playgroud)

小智 5

由于SampleDataEvent.data需要未压缩的原始样本数据,而不是MP3,因此这一操作不起作用。请改用https://github.com/claus/as3swf/wiki/play-mp3-direct-from-bytearray