Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

249
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda