Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@dfuenzalida
Created December 9, 2013 21:14
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dfuenzalida/7880996 to your computer and use it in GitHub Desktop.
Save dfuenzalida/7880996 to your computer and use it in GitHub Desktop.
Creating several YouTube videos, play and pause using JS
<div id="player-TMoPuv-xXMM"></div>
<hr/>
<div id="player-bpOR_HuHRNs"></div>
<a href="#" id="pause">Pause</a>
<a href="#" id="resume">Resume</a>
<script src="http://www.youtube.com/player_api"></script>
<script>
// 3. This function creates an <iframe> (and YouTube player)
// after the API code downloads.
var players = [];
function createVideo(vid){
return new YT.Player('player-' + vid, {
height: '315',
width: '560',
videoId: vid,
});
}
function onYouTubePlayerAPIReady() {
players.push(createVideo("TMoPuv-xXMM"))
players.push(createVideo("bpOR_HuHRNs"))
document.getElementById('resume').onclick = function() {
for(var i=0; i < players.length; i++){
players[i].playVideo();
}
};
document.getElementById('pause').onclick = function() {
for(var i=0; i < players.length; i++){
players[i].pauseVideo();
}
};
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment