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

297
Visualizações
Is there any working way to autoplay audio on all major browsers using Javascript?

I have set up some HTML & Javascript that can control the playing of an audio track on a webpage, I really like simplicity of JavaScript with play/stop function but I can't make it play automatically. Here's my javascript code:

$('body');
var audio = document.getElementById("audio-player");
audio.volume = 0.2;

if ($(window).length) {
  $('.bg-player').css({
    'visibility': 'visible'
  });
  
  $('body').addClass("audio-on");
  
  if ($('body').hasClass('audio-on')) {
    $('body').removeClass('audio-off');
  }
  
  $(".bg-player").on('click', function() {
    $('body').toggleClass("audio-on audio-off");
    
    if ($('body').hasClass('audio-off')) {
      audio.pause();
    }
    
    if ($('body').hasClass('audio-on')) {
      audio.play();
    }
  });
}

I tried to add the autoplay property but no success:

audio.autoplay = true;

I would like know if there is a way for play the file on the page load.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

It's a browser security feature to not autoplay an audio unless there is some user interaction.

https://developers.google.com/web/updates/2017/09/autoplay-policy-changes#new-behaviors

Autoplay with sound is allowed if:

User has interacted with the domain (click, tap, etc.). On desktop, the user's Media Engagement Index threshold has been crossed, meaning the user has previously played video with sound. The user has added the site to their home screen on mobile or installed the PWA on desktop.

about 4 years ago · Juan Pablo Isaza Relatório
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