Skip to content

Instantly share code, notes, and snippets.

@aboutaaron
Created October 17, 2012 23:36
Show Gist options
  • Save aboutaaron/3909018 to your computer and use it in GitHub Desktop.
Save aboutaaron/3909018 to your computer and use it in GitHub Desktop.
YouTube player from Edmonton Journal
<script src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
function onYouTubePlayerReady(playerId) {
ytplayer = document.getElementById("myytplayer");
setInterval(updateytplayerInfo, 250);
updateytplayerInfo();
ytplayer.addEventListener("onStateChange", "onytplayerStateChange");
ytplayer.addEventListener("onError", "onPlayerError");
}
function onPlayerError(errorCode) {
alert("An error occured: " + errorCode);
}
function onytplayerStateChange(newState) {
setytplayerState(newState);
}
// functions for the api calls
function loadNewVideo(id, startSeconds) {
if (ytplayer) {
ytplayer.loadVideoById(id, parseInt(startSeconds));
}
}
function seekTo(seconds) {
if (ytplayer) {
ytplayer.seekTo(seconds, true);
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment