as3實(shí)現(xiàn)播放.wav擴(kuò)展名的聲音文件
廣告:
源代碼:
import de.popforge.audio.output.SoundFactory;
import de.popforge.audio.output.Audio;
var _wavLoader:URLLoader;
var _wavRequest:URLRequest;
var _channel:SoundChannel;
var param:Object = this.root.loaderInfo.parameters;
flash.system.Security.allowDomain("53bk.com");
var soundurl:String="wav/article_474.wav";
if(param["file"]!=null){
soundurl= param["file"];
}
var autoplay:Boolean =true;
if(param["autoplay"]!=null && param["autoplay"]=="true"){
autoplay=true;
}
//此處為過程
Play(soundurl);
function Play(url:String) {
_wavRequest = new URLRequest();
_wavRequest.url=url;
_wavLoader = new URLLoader();
_wavLoader.dataFormat=URLLoaderDataFormat.BINARY;
_wavLoader.load(_wavRequest);
_wavLoader.addEventListener(Event.COMPLETE,onStartPlay);
_channel = new SoundChannel();
}
//聲音加載完成,轉(zhuǎn)成二進(jìn)制
function onStartPlay(evt:Event):void {
var wave:ByteArray=_wavLoader.data as ByteArray;
SoundFactory.fromByteArray(wave,1,16,11025,onOk);
//括號(hào)里的數(shù)字是可以調(diào)節(jié)的,根據(jù)你所用的音頻的頻率調(diào)
}
//聲音二進(jìn)制轉(zhuǎn)換完成,開始播放
function onOk(evt:Sound):void {
_channel=evt.play();
}
廣告: