fix: add state to pause existing audio for demo menus, add support fo… (#10428)
This commit is contained in:
parent
32e6bcae3b
commit
15801a01ba
3 changed files with 35 additions and 7 deletions
|
|
@ -106,5 +106,12 @@ export function soundSrc(id: string | undefined) {
|
|||
export function playSound(src: string | undefined) {
|
||||
if (typeof Audio === "undefined") return
|
||||
if (!src) return
|
||||
void new Audio(src).play().catch(() => undefined)
|
||||
const audio = new Audio(src)
|
||||
audio.play().catch(() => undefined)
|
||||
|
||||
// Return a cleanup function to pause the sound.
|
||||
return () => {
|
||||
audio.pause()
|
||||
audio.currentTime = 0
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue