在Flash Player里播放声音的两种方法 -电脑资料

电脑资料 时间:2019-01-01 我要投稿
【meiwen.anslib.com - 电脑资料】

1、建立 Sound 对象用 load() 方法加载外部的 mp3 来播放;

2、让 Sound 对象监听 sampleData 事件,这样可以播放由程序动态生成的声音,例如:
下面的示例播放简单的正弦波,

在Flash Player里播放声音的两种方法

var mySound:Sound = new Sound();
function sineWaveGenerator(event:SampleDataEvent):void {
    for ( var c:int=0; c<8192; c++ ) {
        event.data.writeFloat(Math.sin((Number(c+event.position)/Math.PI/2))*0.25);
        event.data.writeFloat(Math.sin((Number(c+event.position)/Math.PI/2))*0.25);
    }
}

mySound.addEventListener(Event.SAMPLE_DATA,sineWaveGenerator);
mySound.play();

最新文章