-
-
Save parzibyte/178799804feb5f8d6b8d2033481faf1f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Carga un sonido a través de su fuente y lo inyecta de manera oculta | |
const cargarSonido = function (fuente) { | |
const sonido = document.createElement("audio"); | |
sonido.src = fuente; | |
sonido.setAttribute("preload", "auto"); | |
sonido.setAttribute("controls", "none"); | |
sonido.style.display = "none"; // <-- oculto | |
document.body.appendChild(sonido); | |
return sonido; | |
}; | |
const $botonReproducir = document.querySelector("#btnReproducir"), | |
$botonPausar = document.querySelector("#btnPausar"), | |
$botonReiniciar = document.querySelector("#btnReiniciar"); | |
// El sonido que podemos reproducir o pausar | |
const sonido = cargarSonido("sonido.flac"); | |
$botonReproducir.onclick = () => { | |
sonido.play(); | |
}; | |
$botonPausar.onclick = () => { | |
sonido.pause(); | |
}; | |
$botonReiniciar.onclick = () => { | |
sonido.currentTime = 0; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment