在某些浏览器中,外部加载的声音会回响

时间:2010-11-30 09:20:52

标签: flash actionscript-3 audio

我遇到了一个问题,在Mac上的Chrome和Chrome,Opera和Safari上的PC上,它似乎播放了两次声音,产生了一种不必要的回声效果,并且有一个相当随机的延迟(总是低于一半)第二个)。

我有两个通过LocalConnection进行通信的swf文件,主swf只是在第二个swf上调用一个函数,并将一个url作为参数传递给一个mp3文件。然后第二个swf加载文件,onComplete播放它。

这完全适用于IE(这是第一个)以及Mac和PC上的Firefox,但如上所述相呼应。

我甚至实行了一次双重检查,以确保在声音播放时声音无法播放。

一些示例代码:

var audio:Sound;
var isPlayingSound:Boolean = false;
var soundURL:String;

public function lcRecieve(url:String = ""):void{
    soundURL = url;
    if (soundOn && !isPlayingSound){
        playSound();
    }
}

public function playSound():void {
    if(!isPlayingSound){
        audio = new Sound(new URLRequest(soundURL));
        audio.addEventListener(Event.COMPLETE, onSoundComplete);
    }

}
public function onSoundComplete(e:Event):void{
        audio.play(0, 1).addEventListener(Event.SOUND_COMPLETE, soundFinnishedPlaying);
        isPlayingSound = true;
}

private function soundFinnishedPlaying(e:Event):void {
        e.target.removeEventListener(Event.SOUND_COMPLETE, soundFinnishedPlaying);
        audio = null;
        isPlayingSound = false;
}

之前有人对这个问题进行过标记吗?我很失落。

1 个答案:

答案 0 :(得分:0)

   private var channel:SoundChannel;

   public function onSoundComplete(e:Event):void
   {
      if( channel != null )
           channel.stop();

      channel = audio.play( 0 , 1 );
   }