play audio on web on start
This commit is contained in:
18
audio.sex
18
audio.sex
@@ -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)))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user