2010-11-30 51 views
0

我很困难,在Mac上的Chrome和Chrome,Opera和Safari在PC上,它似乎播放声音两次,产生一个不想要的回声效果随机延迟(总是不到半秒)。外部加载的声音回声在某些浏览器

我有2个swf文件通过LocalConnection进行通信,主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; 
} 

任何人在这个问题stumbeled过吗?我非常失落。

回答

0
private var channel:SoundChannel; 

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

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

显然,这个作品完美。 :)非常感谢的人。 – Gubb 2010-11-30 15:38:00