Created
May 23, 2014 19:36
-
-
Save KaeruCT/dcfae82a15af514ea95e to your computer and use it in GitHub Desktop.
Playing music in the background using the Youtube JS API
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
<!DOCTYPE html> | |
<html> | |
<body> | |
<div id="player" style="position: absolute; top: -9999px; left: -9999px;"></div> | |
<div id="info">loading...</div> | |
<script src="http://www.youtube.com/player_api"></script> | |
<script> | |
var info = document.getElementById('info'); | |
function onYouTubePlayerAPIReady() { | |
var player = new YT.Player('player', { | |
videoId: 'gzeOWnnSNjg', // this is the id of the video at youtube (the stuff after "?v=") | |
loop: true, | |
events: { | |
onReady: function (e) { | |
info.innerHTML = 'video is loaded'; | |
e.target.playVideo(); | |
}, | |
onStateChange: function (event) { | |
if (event.data === 1) { | |
info.innerHTML = 'video started playing'; | |
} | |
} | |
} | |
}); | |
// you can do more stuff with the player variable | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment