I want to play audio every second as it is clock so wanted to insert a ticking sound .
Is there any way to achieve that without a trigger as clock should always be automatic .
Here is code which works on trigger and running:
<audio id="audiotag1" src="Sounds\clock tick.mp3" preload="metadata" controls></audio>
<button onclick="trigger()">Start</button>
function trigger(){
setInterval(clockRunner, 1000);
function clockRunner(){
var audioElement = document.getElementById('audiotag1');
audioElement.play();
}
}
Here is code which is without trigger but not running :
setInterval(clockRunner, 1000);
function clockRunner() {
var audioElement = document.getElementById('audiotag1');
audioElement.play();
}
<audio id="audiotag1" src="Sounds\clock tick.mp3" preload="metadata" controls></audio>
Error showing is :
Uncaught DOMException: play() failed because the user didn't interact with the document first.
Here is the question referring to the problem(Error) but solution provided is for video and they can be play muted and have visual content
Thanks for help in advance