Created
April 2, 2014 10:47
-
-
Save fatuk/9931812 to your computer and use it in GitHub Desktop.
youtube-api-example
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
$(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