【问题标题】:Externally loaded sounds echoes in certain browsers外部加载的声音在某些浏览器中回响
【发布时间】:2011-05-17 18:17:36
【问题描述】:

我正在努力解决一个问题,在 Mac 上的 Chrome 和 PC 上的 Chrome、Opera 和 Safari 中,它似乎播放了两次声音,产生了一个带有相当随机延迟的不需要的回声效果(总是低于半第二个)。

我有 2 个通过 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;
}

以前有人偶然发现过这个问题吗?我很迷茫。

【问题讨论】:

    标签: flash actionscript-3 audio


    【解决方案1】:
       private var channel:SoundChannel;
    
       public function onSoundComplete(e:Event):void
       {
          if( channel != null )
               channel.stop();
    
          channel = audio.play( 0 , 1 );
       }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-05
      • 2011-07-15
      • 1970-01-01
      • 2011-12-08
      • 2020-10-23
      • 1970-01-01
      相关资源
      最近更新 更多