I know that this is not the answer you want to hear, but there is no way to stop it, regardless of whether you wrote your own flash library to play sound or not.
For everyone who said, "this works great for me!" try resizing or moving the browser window when the demo version of the player is played. You will hear more than just a subtle delay. This is most noticeable in Firefox and IE, but even Chrome will experience it.
Worse, if you click and hold the mouse in the close window of the browser window, the sound will stop completely until you release the mouse (you can release it outside the close field and actually close the window, FYI).
What's going on here?
It turns out that when you start resizing or moving around the browser window, the browser tries to multitask to change the properties of the window, given that javascript continues to work in the window. He briefly changes the window when he needs to.
When you hold the mouse over a closing window in the browser window, the time completely stops. This is what happens in smaller increments when recalibrating or moving the window: time in the javascript world remains small, sporadic pieces (or large pieces, depending on how slow your machine is).
Now you can say: "Of course, resizing the browser or pressing the close button pauses the browser, but usually it will not." Unfortunately, you are mistaken.
It happens all the time, really. I ran the tests, and it turns out that even leaving the browser window completely motionless, without touching the mouse or touching the keyboard, the background processes on the computer can still cause hiccups, which means that for a short time (maybe up to several milliseconds) , the time "stays still" in the browser, a completely random interval out of your control.
What do I mean by standing? Let's say you have a setInterval () call (this also applies to setTimeout) that runs every 33 milliseconds (about 30 frames per second). Now you expect that after every 33 milliseconds of the real world, your function will be called. And most of the time this is true.
But when the hiccups begin, your setInterval call can happen in 43 milliseconds. What happened in 10 ms? Nothing. Time froze. Nothing was updated in the browser. If you had a sound game, it will continue to play, but no new sound calls will start to play, because no javascript is executed at all. If you had 5 setInterval () functions running, at some point they would be paused for 10 ms.
The only way to say that "time has stopped" is to poll the real time in your setInterval callbacks. You can see that the browser tries to keep up most of the time, but when you start resizing the window or doing something stressful, the intervals will be longer than usual, but all your code will remain synchronized (I make games using this technique, so you You’ll see that all updates to your game happen synchronously, but they just stutter slightly).
Usually, I have to point out that these stutters are completely invisible, and if you did not write a function to register real-time during setInterval time (as I already did in my own testing), you would not even know about it. But this becomes a problem if you try to create some kind of repeating sound (for example, an audio signal against the background of Asteriods) using repeated calls to play ().
My suggestion? If you have a sound that, as you know, will be looped, give it a long time, maybe 10 seconds, and you are less likely to notice hiccups (now the graphics on the screen may still be hiccups, but you are screwed there).
If you are writing a game and shooting from the main character with a machine gun, do not make 10 quick calls to playSound ("singleShot"), one call to playSound ("machineGunFire10Rounds") or anything else along these lines.
You will need to cheat a little to get around it, but in most cases everything will be fine.
It seems that Flash applets start in a process that somehow affects all this time “freeze time” occurring in a normal browser / javascript environment, but I can still achieve this even with your ToneMatrix link, for example, by resizing or moving the browser window.
But Flash still seems a lot better than javascript. When I stay in the browser, I bet that Flash does not freeze for a while, and these intervals always work on time.
TL; DR:
- you screwed up what you hope to achieve.
- try to handle this using some workarounds
- rewrite the project in clean flash (without javascript)
- wait until the browsers get better (Firefox 4 gets a new javascript engine called JaegerMonkey , which will be interesting to view)
- How do I know all this? I have done many tests and logging with javascript, setInterval and sound calls soundManager / html5.