Skip to content

Instantly share code, notes, and snippets.

@fatuk
Created April 2, 2014 10:47
Show Gist options
  • Save fatuk/9931812 to your computer and use it in GitHub Desktop.
Save fatuk/9931812 to your computer and use it in GitHub Desktop.
youtube-api-example
$(function () {
window.Vivaster = {
Youtube: {}
};
window.onYouTubeIframeAPIReady = function () {
console.log(123);
Vivaster.Youtube.player = new YT.Player('player', {
height: '390',
width: '640',
videoId: 'M7lc1UVf-VE',
events: {
'onReady': Vivaster.Youtube.onPlayerReady,
'onStateChange': Vivaster.Youtube.onPlayerStateChange
}
});
};
$.getScript('https://www.youtube.com/iframe_api', function () {
Vivaster.Youtube.onPlayerReady = function (event) {
};
Vivaster.Youtube.onPlayerStateChange = function (event) {
};
Vivaster.Youtube.playVideo = function () {
Vivaster.Youtube.player.playVideo();
};
Vivaster.Youtube.stopVideo = function () {
Vivaster.Youtube.player.stopVideo();
};
$('#playBtn').on('click', function (event) {
event.preventDefault();
Vivaster.Youtube.playVideo();
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment