如何从缓冲区(的ByteArray /流)在ActionScript 3播放MP3的声音? [英] How to play MP3 sound from buffer (ByteArray/Stream) in ActionScript 3?

查看:325
本文介绍了如何从缓冲区(的ByteArray /流)在ActionScript 3播放MP3的声音?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以..我有一个缓冲带MP3数据(如果我保存这个缓冲区,并调用它buffer.mp3会上场,但在这种情况下,我不应该将其保存到文件系统) 。 我要玩的话,但我做不到,我该怎么办?


我试了下code到播放buffrer(ByteArray的\流)(我从服务器获取数据的方法工作正常的MP3数据(上测试文本廉政局等),我称之为返回的ByteArray readResponse因为我有一些seading方法,这是它的响应)。

 受保护的功能播放(事件:MouseEvent)方法:无效
{
VAR为mySound:声音=新的声音();
mySound.addEventListener(的SampleDataEvent.SAMPLE_DATA,soundFill);
mySound.play();
}

公共职能soundFill(事件:的SampleDataEvent):无效
{
event.data.writeBytes(readResponse.buffer,0,readResponse.buffer.length);
}
 

解决方案

本之一,因为SampleDataEvent.data不起作用预计uncom pressed原始样本数据,而不是MP3。使用 http://wiki.github.com/claus/as3swf/玩-MP3-直接从 - ByteArray的代替。

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);	
		}

解决方案

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

这篇关于如何从缓冲区(的ByteArray /流)在ActionScript 3播放MP3的声音?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆