+ 1
Code help
So I have made this stopwatch code and I want a beep sound after every 1 minute. Pls help me to make this change. https://sololearn.com/compiler-playground/Wxlw8OTqTrXa/?ref=app
2 Antworten
+ 3
whirl coder ☕ Your audio source is not valid, as the code logs in the console. The link you used for the source leads to a page which says "Access denied", likely because your file is private or something. So you need to fix the source url first.
After fixing, simply add this at the start in the onclick function of startBtn:
beep.play();
beep.pause();
beep.currentTime = 0;
Also you could add a flag so once the audio has played for first time, it doesn't play again(e.g when you press play again after pressing reset button)
Initially the browser detected the audio play as automatic and did not recognize any user gesture(and autoplay with audio isn't allowed in browsers) so it got blocked. This plays and pauses the audio instantly, making the browser recognize your gesture and so does not block the audio.