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

118
Vistas
Sound Lag issue on mousedown in javascript

I am making a website which is a simple piano. I hosted the site, but the audio is lagging now. When I play it from my local system it works fine, but not from the hosted site.

So I want all the audio resources to load and save it in the user's device (as cache or something else) and play the audio from it so the audio won't lag. I can't figure out how do I do it. please help me with a solution.

This is what I tried:

const pianoKeys = document.querySelectorAll('.key');
function playSound(soundUrl){
    const sound = new Audio(soundUrl)
    sound.currentTime = 0
    sound.play()
}
pianoKeys.forEach((pianoKey, i)=> {
    const num = i<9 ? '0'+(i+1) : (i+1);
    const soundUrl = 'sounds/key'+num+'.ogg';
    pianoKey.addEventListener('mousedown', ()=>playSound(soundUrl))
})

The soundUrl creates the directory to the audio file. Is there any way to load the file and play from it?

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