Skip to content

Instantly share code, notes, and snippets.

@michaelgiles
Created November 20, 2015 01:03
Show Gist options
  • Save michaelgiles/73e2eb73d241bb34b72b to your computer and use it in GitHub Desktop.
Save michaelgiles/73e2eb73d241bb34b72b to your computer and use it in GitHub Desktop.
var player = {
playVideo: function(container, videoId) {
if (typeof(YT) == 'undefined' || typeof(YT.Player) == 'undefined') {
window.onYouTubePlayerAPIReady = function() {
player.loadPlayer(container, videoId);
};
$.getScript('//www.youtube.com/player_api');
} else {
player.loadPlayer(container, videoId);
}
},
loadPlayer: function(container, videoId) {
window.myPlayer = new YT.Player(container, {
playerVars: {
modestbranding: 1,
rel: 0,
showinfo: 0,
autoplay: 1
},
height: 200,
width: 200,
videoId: videoId,
events: {
'onStateChange': onPlayerStateChange
}
});
}
};
var containerId = 'ytplayer';
var videoId = 'abc123';
player.playVideo(containerId, videoId);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment