defold-fmod
defold-fmod copied to clipboard
Config option to mute FMOD audio while window is minimized?

Sounds reasonable. Might take a look at this a bit later into the week
Looks like code already exists it's just only activated on HTML5 and Android
https://github.com/dapetcu21/defold-fmod/blob/master/fmod/src/fmod_extension.cpp#L35
So just needs a flag set from game.project to allow it to work elsewhere.
I like the option to enable it on PC platforms but since the engine atm pauses without option it's probably better to always have it enabled everywhere for now.
That must not be it? I tested adding defined(DM_PLATFORM_WINDOWS) and it didn't pause audio while window was minimized on Windows. OpenAL extension does pause audio on minimize and has similar code.
https://github.com/Lerg/extension-openal/blob/ab3d3fc22d5a51c86b597fbc72cf7c9cebdced32/openal/src/extension.cpp#L166
FMODBridge_deactivateApp only works on HTML5/Android?
https://github.com/dapetcu21/defold-fmod/blob/351a6e6b523ad375166462869df0939bf2e51dd0/bridge/src/fmod_init.cpp#L190
So that lib will have to be rebuilt to allow it to work on other platforms too I think.
Idk. I'll take a look on monday
I remembered the reason why it wasn't turned on on desktop is because I get EVENT_ID_ACTIVATEAPP and EVENT_ID_DEACTIVATEAPP whenever my window loses or gains focus (at least that's the case on macOS), but what I really want to detect is the minimise event (because that the only time the engine pauses). @britzl I think we need minimise events in native extensions (or engine pause/resume events)
I realized that with window.set_listener() we can see in engine if the window has lost focus or not. It seems like not a great option but could be used to combine with the existing versions of the events to tell the extension to pause audio or not. Since minimizing will not give a chance to send any info about in engine window state so it's most likely a minimize and not simply losing focus.
That's complicated and involves timers on the C side, which are not trivial to implement without access to the run loop (at least in windows and linux).
We will add the minimize event in the release in two weeks.
I implemented pausing the sound when the engine is minimised. FMOD should now respect the current setting of engine.run_while_iconified. If, for some reason you'd like a different behaviour that that one (maybe to pause the sound but not the engine while it's minimised, use fmod.run_while_iconified).
The only problem is that none of this works yet on macOS, due to a bug: https://github.com/defold/defold/issues/4910