All those cases can be handled with MainLoop’s NOTIFICATION_WM_FOCUS_OUT.
func _notification(what):
match what:
MainLoop.NOTIFICATION_WM_FOCUS_OUT:
#Pause however you want here
MainLoop.NOTIFICATION_WM_FOCUS_IN:
#Unpause
This works great in the editor, but nothing happens on the HTML5 exported version
my code:
func _notification(what):
match what:
MainLoop.NOTIFICATION_WM_FOCUS_OUT:
if $background.playing:
print('pausing background')
$background.stream_paused = true
MainLoop.NOTIFICATION_WM_FOCUS_IN:
if play_background and Settings.is_music_on():
if $background.stream_paused:
$background.stream_paused = false
print('resuming background')
dpensky | 2021-04-20 11:56
Well… this sucks. I discovered that this notification is only emitted on the Release version and not in the Debug version of the HTML5 exported version for some obscure reason, which is a pain to test
dpensky | 2021-04-20 12:40
That’s not the case either. Something else is interfering with this notification.
Sometimes this works, sometimes don’t.