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

108
Vistas
How to autoplay audio when countdown is finished without pausing other audio on device

I have a countdown timer that plays a sound when it finishes, and I would like the sound to not pause/interfere with existing audio that is playing on the user's device via another app (like Spotify). On a computer (Macbook Pro), this works across browsers and the alarm sound plays over background music. On a mobile phone (iPhone) background music is paused when the countdown is finished and alarm plays and am required to replay background audio. I don't have the knowledge to come up with a workaround for this and any help is really appreciated! I modified the code below from this post which helped solve the barrier to autoplay initially:

const audio = new Audio("https://www.fesliyanstudios.com/play-mp3/4385");
let time = ${time};

btn.onclick = e => {
  // mark our audio element as approved by the user
  audio.load();
  countdown();
  btn.disabled = true;
};


function countdown() {
  document.getElementById("pre").style.color ="#12A89E";
  document.getElementById("pre").innerHTML = --time + "s work time";
  if(time === 0) return onend();
  setTimeout(countdown, 1000);
}


function onend() {
  audio.play(); // now we're safe to play it
  document.getElementById("pre").style.color ="#A81248";
  document.getElementById("pre").innerHTML = "NEXT MOVEMENT";
  time = ${time}
  btn.disabled = false;
}
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