defold-fmod icon indicating copy to clipboard operation
defold-fmod copied to clipboard

Config option to mute FMOD audio while window is minimized?

Open subsoap opened this issue 6 years ago • 10 comments
trafficstars

2019-08-18 22_57_50-Window

subsoap avatar Aug 19 '19 05:08 subsoap

Sounds reasonable. Might take a look at this a bit later into the week

dapetcu21 avatar Aug 21 '19 08:08 dapetcu21

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.

subsoap avatar Aug 25 '19 06:08 subsoap

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

subsoap avatar Aug 25 '19 07:08 subsoap

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.

subsoap avatar Aug 25 '19 07:08 subsoap

Idk. I'll take a look on monday

dapetcu21 avatar Aug 25 '19 21:08 dapetcu21

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)

dapetcu21 avatar Aug 26 '19 12:08 dapetcu21

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.

subsoap avatar Aug 29 '19 17:08 subsoap

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).

dapetcu21 avatar Aug 29 '19 21:08 dapetcu21

We will add the minimize event in the release in two weeks.

britzl avatar Aug 30 '19 03:08 britzl

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

dapetcu21 avatar Jun 14 '20 10:06 dapetcu21