Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

238
Visualizações
Why audio error is showing up when it is played muted

I have a error which is

Error showing is :
Uncaught DOMException: play() failed because the user didn't interact with the document first.

The error does not prevent function to run but it should not be shown as some of the question in SO , Chrome , Mozilla documentation states that audio or video which are muted are not blocked from playing.

So there must be something I am doing wrong . Can you tell that or any way to remove the error.

I have muted the audio at first hand then why it is still showing up . As function is running every second so error is also showing up every second .

The error stop showing up when I click the start btn which plays the audio .

Is there any way to remove this error :

var start = document.getElementById("triggerSnd")
var audioElement = document.getElementById('audiotag1')
var demo = document.getElementById('demo')
var interval, isMuted = true

clockRunner();
clock();
setInterval(() => clock(), 1000)

start.addEventListener('click', clockRunner)

function clockRunner() {
  audioElement.muted = isMuted
  start.innerText = isMuted ? "Start" : "Stop"
  isMuted = !isMuted
}

function clock(isMuted) {
  //Clock code goes here , here only used a simple timer
  demo.innerText = new Date();
  audioElement.play();
}
<audio id="audiotag1" src="https://soundbible.com/mp3/Tick-DeepFrozenApps-397275646.mp3" preload="metadata"></audio>
<button id="triggerSnd">Start</button>
<div id="demo"></div>

It is not showing up in above snippet but can seen in console of VS code(Using it, so can tell about it) every second

Thanks for help in advance

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda