play audio on web on start

This commit is contained in:
2026-11-08 20:52:03 +03:00
parent 5de55fd152
commit 9ffceb91ed
3 changed files with 33 additions and 1 deletions

View File

@@ -15,6 +15,7 @@
;; NULL when no music is playing
(var current-music (* Music) NULL)
(var audio-unlocked bool false)
(fn load-sound ((file (* const char))) Sound
(var sound Sound (LoadSound file))
@@ -70,7 +71,24 @@
(pub fn audio-play-fishing-music () void
(switch-music (& fishing-music)))
;; Browsers keep the audio context suspended until the first user gesture.
;; Restart the current track once after that gesture so the music actually begins.
#+emscripten
(pub fn audio-unlock () void
(if audio-unlocked
(return))
(= audio-unlocked true)
(if (!= current-music NULL)
(do
(StopMusicStream (* current-music))
(PlayMusicStream (* current-music)))))
#-emscripten
(pub fn audio-unlock () void
(return))
(pub fn audio-play-menu-click () void
(audio-unlock)
(if (IsSoundValid menu-click)
(PlaySound menu-click)))