Created
July 13, 2020 21:26
-
-
Save aazbeltran/afd5b59c7c2ef97a2b8ff250ced10d9f to your computer and use it in GitHub Desktop.
Ejemplo rápido para Instituto Birmingham de como implementar la funcionalidad de atrasar o adelantar un audio en HTML con JS
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
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"> | |
</script> | |
<audio controls autoplay src="https://upload.wikimedia.org/wikipedia/commons/6/6e/Micronesia_National_Anthem.ogg"></audio> | |
<input type="button" id="atrasar" value="Atrasar"><input type="button" id="adelantar" value="Adelantar"><input type="button" id="play" value="Reproducir/Detener"> | |
<script> | |
var audio = $("audio")[0]; | |
$(document).keydown(function(e) { | |
var unicode = e.charCode ? e.charCode : e.keyCode; | |
switch (unicode) { | |
case 39: | |
adelantar(); | |
break; | |
case 37: | |
atrasar(); | |
break; | |
case 32: | |
play_or_pause(); | |
break; | |
} | |
}); | |
function atrasar() { | |
audio.currentTime -= 5; | |
} | |
function adelantar() { | |
audio.currentTime += 5; | |
} | |
function play_or_pause() { | |
if (audio.paused) { | |
audio.play(); | |
} else { | |
audio.pause() | |
} | |
} | |
$("#atrasar").click(atrasar); | |
$("#adelantar").click(adelantar); | |
$("#play").click(play_or_pause); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment