Thursday, January 10, 2013

loadVideoById


<!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/7z2hIPJkc5w?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:"http://www.youtube.com/watch?v=RNIjbYl8K4U", startSeconds:8, endSeconds:18, suggestedQuality:"hd1080"});
}
function ready(event){
//event.target.playVideo();
//player.loadVideoById({videoId:"RNIjbYl8K4U", startSeconds:4, endSeconds:10, suggestedQuality:"hd1080"});
player.cueVideoByUrl({mediaContentUrl:"http://www.youtube.com/v/RNIjbYl8K4U?version=3", startSeconds:8, endSeconds:18, 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: