Skip to content

Latest commit

 

History

History
25 lines (25 loc) · 743 Bytes

File metadata and controls

25 lines (25 loc) · 743 Bytes
音频播放
export function playAudio ({muted = true}) {
    const audio = new Audio(require('@/assets/water.wav'))
    audio.autoplay = 'autoplay'
    audio.preload = 'preload'
    audio.muted = muted
    audio.oncanplaythrough = (event) => {
        const playedPromise = audio.play()
        if (playedPromise) {
            playedPromise.then((data) => {
                // to do nothing
            }).catch((e) => {
                setTimeout(() => {
                    audio.pause()
                    audio.load()
                }, 1000)
                if (e.name === 'NotAllowedError' || e.name === 'NotSupportedError') {
                    console.log(e.name)
                }
            })
        }
    }
}