Wednesday, January 9, 2013

Sample code


<!doctype html>
<html>
<head>
<title>This is a Nice Title</title>
<script async src="https://www.youtube.com/iframe_api"></script>
<script src="script.js"></script>
</head>
<body>
<iframe id="player" src="http://www.youtube.com/embed/KUbHep0bUWs?enablejsapi=1" style="width:400px;height:400px"></iframe>
</body>
</html>


var player;
function onYouTubeIframeAPIReady(){
player = new YT.Player("player",{events:{onReady:"ready",onStateChange:"change"}});
//player.cueVideoById({videoId:"KUbHep0bUWs", startSeconds:8, endSeconds:18, suggestedQuality:"hd1080"});
}
function ready(event){
event.target.playVideo();
//player.cueVideoById({videoId:"KUbHep0bUWs", startSeconds:4, endSeconds:10, suggestedQuality:"hd1080"});
//event.target.playVideo();
}
function change(event){
if(event.data == YT.PlayerState.PLAYING){
setTimeout(stop,6000);
}
}
function stop(){
player.stopVideo();
player.clearVideo();
}


No comments: