[SOLVED] Return the music to a certain time

Hi!

I didn’t find any way or extension to pause the audio when switching tabs in the browser. I don’t know if it is possible to do that. I’m looking for workaround.

So, I would like to know if it would be possible to save how long the song was when the tab was changed or the browser minimized, leave the sound muted and when returning to the game put the song at the exact moment it was previously playing.

Not aware of anything that will work for browser tabs, sadly. The Window Focused condition is for desktop apps (and works for this purposes, screenshot below)

For browsers, someone might be able to implement something around the Page Visibility API? Page Visibility API - Web APIs | MDN

I’m not aware of anything currently implemented that would work in the way you’re looking for, since currently it doesn’t know if the tab is focused or not.

There is an extension that changes the volume of music to 0 and vice versa, and also pauses the game. This is an experimental extension, but it works well. The extension is called PauseFocusLost

The extension mentioned by @kotiks can mute the sound and return it when the game lose focus. As far as I’ve tried, it’s not possible to pause the sound instead of mute it. So my idea was to add something that would store the moment of the song in a variable and, when it returned, put the song back in the moment it should be.

Here the extension called PauseFocusLost:

“var sound_manager = runtimeScene.getGame().getSoundManager();
var volumen = sound_manager.getGlobalVolume();
window.addEventListener(‘focus’, function (event) {
sound_manager.setGlobalVolume(volumen);
runtimeScene.getGame().pause(false);
});
window.addEventListener(‘blur’, function (event) {
sound_manager.setGlobalVolume(0);
runtimeScene.getGame().pause(true);
});”

I don’t know if it’s possible to do what I’m suggesting. But if it is, it will solve an important problem in WEB games. We could then have songs without a loop that, when switching tabs and returning, would still be at the same moment as the rest of the game.

If someone knows how to make the sound pause instead of being muted, it would be even more practical.

Hmmm… sound manager has
PauseAllActiveSounds and ResumeAllActiveSounds functions, but I’m not sure how to make it work on that extension, as the extension logic doesn’t seem to have anything that indicates what it is doing to differentiate from paused and reaumed (tab focus)

1 Like

Big thanks, Silver!!!

I changed for what you said, tested in WEB and worked!!! :boom:

might be able to speed a sound up? then u could store this sound variable and speed up a sound or smtn like that