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

241
Visualizações
Javascript playing an endless loop audio file without delay

Title is pretty much self explanatory.

I want to create an endless loop with JavaScript but without stopping between reading (again) the same exact file.

Here is my code:

function playMySong(url)
{
    var audio=document.createElement('audio');
    audio.style.display="none";
    audio.src=url;
    audio.autoplay=true;
    audio.onended=function()
    {
        playMySong('whiteNoise.wav');
    };
    document.body.appendChild(audio);
}

playMySong('whiteNoise.wav');

My code works (almost) perfectly but I want to get read of the tiny delay between the end of the sound to the beginning of the same exact file.

not it's:

[whiteNoise.wav][0.2ms delay][whiteNoise.wav]

I want:

[whiteNoise.wav][whiteNoise.wav]

:)

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

0

You are loading the audio file again and again when it reaches the end. Obviously, loading resources will take time.

Why don't you use a simple loop attribute to the audio element? It will loop the audio clip itself without loading the resource again and again.

function playMySong(url)
{
    var audio=document.createElement('audio');
    audio.style.display="none";
    audio.src=url;
    audio.autoplay=true;
    audio.loop = true;
    document.body.appendChild(audio);
}

playMySong('whiteNoise.wav');

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