Pause music when the game tab of browser is no longer enabled

Hello!

I’m finishing my game in the testing phase. I want to publish it on gd.games. But I’m finding a difficulty related to sound. Currently the effect is weird: the entire game stops except for the music if I change tabs in browser or minimize it. This is a big problem for songs that need to be in sync with the game or that only play once.

In other topics I learned about the “PauseFocusLost” extension. But despite this name, “pause”, the music doesn’t actually pause. It simply turns down the volume. So, if someone click on another browser tab and return to the game a few minutes later, the unlooped song will probably have already ended, leaving the game without music.

Is there a way to pause the sounds and return them when the tab is reactivated? I tried:

But neither code worked (the music doesn’t play). These conditions are described to be used on Windows, Linux, and Mac. Maybe that’s why they don’t work for WEB.

These don’t work on web as because they aren’t implemented and probably differ based on browser. If you know how to code in JS, you could attach a function on document blur that would stop the music and reenable on focus.

Though I think an alternative should exists. I’ll keep tinkering.

Thanks, Ansel!
I don’t know about JS Code… :disappointed: