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

179
Vistas
Making an Azan (alarm clock) to open an mp3 file when specific time in api and the device matches

I am building an Azan clock with Javascript with the following code, but the code does not launch the mp3 file when the time from the API and my PC match.

I am already converting the system time to string time to match with the API but it is kind of ignored by the console.

Screenshot of time format in console

both the system and API time matches

My code is below

// Enable JQuery
var script = document.createElement("script");

script.src = "https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js";

document.head.appendChild(script);

// Call and Parse the API
var request = new XMLHttpRequest();
request.open(
  "GET",
  "https://api.aladhan.com/v1/timingsByCity?city=AbuDhabi&country=uae&method=8",
  false
); // `false` makes the request synchronous
request.send(null);
if (request.status === 200) {
  var azan = JSON.parse(request.responseText);
}

// Convert system time format

var convertFormat = new Date().toLocaleTimeString("en-US", {
  hour: "numeric",
  hour12: false,
  minute: "numeric",
});

// Play the mp3 file if it is time
var intervalId = window.setInterval(function () {
  playazan();
  console.log("Checking Prayer Time");
}, 5000);

function playazan() {
  if (azan.data.timings.Asr === convertFormat) {
    new Audio('https://www.islamcan.com/audio/adhan/azan20.mp3').play()
    console.log("Its time for Dhuhrr");
  } else {
    console.log("Still time remains");
  }
}
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