Created
December 9, 2013 21:14
-
-
Save dfuenzalida/7880996 to your computer and use it in GitHub Desktop.
Creating several YouTube videos, play and pause using 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
<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