Skip to content

Instantly share code, notes, and snippets.

@avm99963
Created July 10, 2015 22:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avm99963/edb637fb40f6bba6493b to your computer and use it in GitHub Desktop.
Save avm99963/edb637fb40f6bba6493b to your computer and use it in GitHub Desktop.
AutoMute YouTube
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>AutoMute YouTube</title>
</head>
<body>
<div id="apDiv1">
<iframe id="player" width="500" height="375" src="//www.youtube.com/embed?version=3&enablejsapi=1&listType=playlist&list=PLPsrk7dWbWKR4FaOdcCm0OBOupR3XEBek&autoplay=1&controls=0&loop=1&fs=0&rel=0&theme=light&modestbranding=1&color=red&vq=large&disablekb=0&hd=1&cc_load_policy=0&playsinline=1" frameborder="0"></iframe>
</div>
<button id="iwantithigher">¡Pon el volumen más alto!</button>
<script src="https://www.youtube.com/iframe_api"></script>
<script>
var player;
// Cuando el reproductor de YouTube está listo se dispara esta función, que lo pone en mute y a 0 de volumen
function onPlayerReady(event) {
event.target.setVolume(0);
event.target.mute();
}
// Esta función se dispara cuando se hace clic en el botón "Pon el volumen más alto"
function highVolume() {
// Si el reproductor está silenciado, desiléncialo
if (player.isMuted() === true)
player.unMute();
// Súbe un 10% de volumen al reproductor, pero si sobrepasa el 100%, ponlo a 100%
if (player.getVolume() < 90)
player.setVolume(player.getVolume() + 10);
else
player.setVolume(100);
}
// Aquí definimos el reproductor de YouTube y configuramos que cuando esté listo el reproductor se lanza la función onPlayerReady
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
events: {
'onReady': onPlayerReady
}
});
};
// Cuando se haga clic al botón, que se lanze la función highVOlume
document.querySelector("#iwantithigher").addEventListener("click", highVolume);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment