Allow playSound volume

This commit is contained in:
Ketchetwahmeegwun T. Southall 2022-01-30 01:17:46 -08:00
parent fa575615f3
commit 63f8e2c514

View File

@ -88,16 +88,21 @@ export function playSong(name: string) {
} }
} }
export function playSound(name: string): HTMLAudioElement { export function playSound(name: string, volume: number): HTMLAudioElement {
let s = new Audio() let s = new Audio()
if (!enabled) return s if (!enabled) return s
s.src = audio[name] s.src = audio[name]
s.volume = volume
s.autoplay = true s.autoplay = true
s.preload = '' s.preload = ''
;(async () => { let promise = s.play()
await s.play() if (promise !== undefined) {
})() promise.then(() => {
// ok
}).catch((error: any) => {
})
}
return s return s
} }