I am using a server-side method to drop in YouTube videos with playlists and functioning buttons (think of a website widget that can be called anyway on a page, and potentia
onYouTubeIframeAPIReady()
is executed after YouTube API is ready to be used, that is after API's Javascript file http://www.youtube.com/iframe_api is loaded.
You can create more players inside onYouTubeIframeAPIReady()
var ytplayer1 = undef;
var ytplayer2 = undef;
function onYouTubeIframeAPIReady() {
ytplayer1 = new YT.Player('player-youtube-1', {
width: '640',
height: '480',
videoId: 'M7lc1UVf-VE'
});
ytplayer2 = new YT.Player('player-youtube-2', {
width: '640',
height: '480',
videoId: 'smEqnnklfYs'
});
}
Note that you need to declare ytplayer1
and ytplayer2
outside of onYouTubeIframeAPIReady()
so you can use them later:
ytplayer1.pauseVideo();
ytplayer2.playVideo();