increpare / PuzzleScript

Open Source HTML5 Puzzle Game Engine
MIT License
903 stars 159 forks source link

Trying to play a sound while it's already playing does nothing #159

Closed Draknek closed 10 years ago

Draknek commented 10 years ago

E.g. any game where there's a sound on movement, it'll play the first time you move but if you're moving quickly it'll only play every second or third move.

Demo: http://www.puzzlescript.net/editor.html?hack=8569268

If there is a technical reason to restrict it to only one copy of the same sound at once, I think it would be better if new sounds interrupted the old ones.

increpare commented 10 years ago

can't repro this on osx - firefox, chrome, or safari - if you want to try looking into it yourself, it's probably something weird happening in

SoundEffect.prototype.play = function() { }

in sfxr.js . If not, let me know what browser it happens in.

poking @shghs

increpare commented 10 years ago

quoth alan:

"Just tested in Chrome and it works there Just Firefox 20/Linux I can report it on"

increpare commented 10 years ago

if you think it might be fallback-related, that’d be this bit to tell: if (typeof AudioContext != 'undefined') { AUDIO_CONTEXT = new AudioContext(); } else if (typeof webkitAudioContext != 'undefined') { AUDIO_CONTEXT = new webkitAudioContext(); }

Draknek commented 10 years ago

It's definitely using the fallback Audio API. I'm really not sure why it's refusing to play a second copy of the sound though.

Paging @shghs! Is there some reason that two Audio instances with the same src might be interfering with one another?

ghost commented 10 years ago

Hmm... I can't seem to reproduce this either. :( I tried Firefox 17.0.11 along with the latest versions of Firefox and Chrome on both Windows and OS X. Maybe it's Linux-specific? Was it working prior to the 1.4 release?

To test this, I find a reasonably long sound effect (bird sounds are good for that!) and just trigger it over and over fast. I also tried pressing R a lot on your demo @Draknek and it seemed to work.

(FYI, this might be a useful testing trick: In order to test the fallback API, you can copy lines 626-658 from sfxr.js and paste them into the JavaScript console. Any new sounds generated from then on should use the fallback API. Alternatively, if you're running a local instance, it's much easier to just comment out the two lines in sfxr.js that assign to AUDIO_CONTEXT.)

The fallback should handle multiple sfx with cloning as it did previously. I did add an extra check to see if the sound is already playing, so maybe that's it? I'll try grab a Linux VM when I get back to work next week to see if that's the cause.

ghost commented 10 years ago

I did add an extra check to see if the sound is already playing, so maybe that's it?

Now that I've thought about this some more, I do think this extra check is responsible. @Draknek I think I've fixed the problem. Here's a download link for the zip – it'd be really great if you could test this and let us know if that solves the problem.

@increpare My bad. Let me know if you'd like me to send a pull request, otherwise I think if you just apply this change c1ff98149aa5a90e35f72ea3ecdceda178bda342 it should fix this bug.

P.S. Thanks a lot for finding this one, Alan!

Draknek commented 10 years ago

Yeah, that works! Thanks :)

increpare commented 10 years ago

should be live now - try refreshing and let me know if it works.

thanks to both of you!

increpare commented 10 years ago

super duper

On Sun, Apr 20, 2014 at 12:03 PM, Alan Hazelden notifications@github.comwrote:

Yeah, that works! Thanks :)

— Reply to this email directly or view it on GitHubhttps://github.com/increpare/PuzzleScript/issues/159#issuecomment-40892604 .

ghost commented 10 years ago

Works for me :)