I made a website where if the user clicks, it plays a sound. To prevent the sound from overlapping, I had to add the code:
n.pause();
n.currentTime = 0;
n.play();
But that causes the error:
The play() request was interrupted by a call to pause()
To come up each time the sound event is triggered right after another trigger. The sounds still plays fine, but I want to prevent this error message constantly popping up. Any ideas?
onCanPlay()
. All these answers are dirty hacks. – Martin Dawson Dec 23 '16 at 16:13n.play()
thenn.pause()
. For that, this Web Fundamentals article describes the solution. tl;dr:n.play().then(() => { n.pause()})
– totymedli Jul 5 '18 at 18:27