开发者

Externally loaded sounds echoes in certain browsers

开发者 https://www.devze.com 2023-01-27 08:24 出处:网络
I\'m struggeling with a problem where, in Chrome on Mac and in Chrome, Opera and Safari on PC, it appears to be playing sounds twice, generating an unwanted echo-effect with a rather random delay(alwa

I'm struggeling with a problem where, in Chrome on Mac and in Chrome, Opera and Safari on PC, it appears to be playing sounds twice, generating an unwanted echo-effect with a rather random delay(always under half a second though).

I have 2 swf-files that communictes through a LocalConnection, the main swf simply calls a function on the second swf and passing a url to an mp3-file as parameter. The second swf then loads the file and onComplete plays it.

This works perfectly on IE(that's a first) and Firefox on both mac and PC but echoes as mentioned above.

I even implemented a double-check to make sure a sound wouldn't play if a sound is already playing.

Some sample code:

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

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

pu开发者_如何学编程blic 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;
}

Anyone stumbeled upon this problem before? I'm very much lost.


   private var channel:SoundChannel;

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

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

精彩评论

暂无评论...
验证码 换一张
取 消