as 3.0 播放音乐的实例代码
as 3.0 播放音乐的实例代码
package
{
import flash.display.sprite;
import flash.events.event;
import flash.events.sampledataevent;
import flash.media.sound;
import flash.utils.bytearray;
/**
* @author flash023
* @date 2010-7-31 18:27
**/
public class ps教程ound extends sprite
{
private var len:uint;
private var position:int;
private var sound:sound;
private var sounddata:bytearray;
public function psound():void {
stage?init(null):addeventlistener (event.added_to_stage, init);
}
private function init(e:event ):void {
var tempsound:rpsound=new rpsound ;
sounddata =new bytearray ;
tempsound.extract(sounddata,999999999);//获取音乐数据
len=sounddata.length;
position=int(len/8)-8;
sound = new sound ;
sound.addeventlistener(sampledataevent.sample_data,onsampledata);
sound.play();
//
removeeventlistener(event.added_to_stage, init);
}
private function onsampledata(e:sampledataevent):void {
var _i:int=2048;
while (_i--) {
sounddata.position=position*8;//重新采样,这里也可以改一改,搞成控制速度,改变采样率等效果
e.data.writefloat(sounddata.readfloat());
e.data.writefloat(sounddata.readfloat());
position--;
if (position<0) {
trace("声音播放完了");
return;
//position=int(len/8)-8;
}
}
//trace(position);
}
}
as 3.0 播放音乐的实例代码
}
补充:flash教程,As3.0