Allow playSound volume
This commit is contained in:
parent
fa575615f3
commit
63f8e2c514
|
@ -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()
|
||||
if (!enabled) return s
|
||||
|
||||
s.src = audio[name]
|
||||
s.volume = volume
|
||||
s.autoplay = true
|
||||
s.preload = ''
|
||||
;(async () => {
|
||||
await s.play()
|
||||
})()
|
||||
let promise = s.play()
|
||||
if (promise !== undefined) {
|
||||
promise.then(() => {
|
||||
// ok
|
||||
}).catch((error: any) => {
|
||||
})
|
||||
}
|
||||
|
||||
return s
|
||||
}
|
Loading…
Reference in New Issue
Block a user