Hi, I'm having a problem with the Youtube Player API: I want it to load a video (by ID) but I can't make it work.
It shows the video(s) in a "handmade" lightbox. When you click showVideo, it must load another video then the one that is already loaded.
Here's the link...
and here's the source:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>lightbox</title>
<script src="http://www.google.com/jsapi"></script>
<script type="text/javascript" src="Object.extended.js"></script>
<style>
#overlay {
position: fixed;
left: 0;
top: 0;
width: 100%;
height: 100%;
background: rgba(0,0,0,0.7);
z-index: 1000;
display: none;
}
#videoBox {
position: fixed;
width: 640px;
height: 385px;
background: #fff;
z-index: 1001;
display: none;
padding: 10px;
}
#videoBox a {
display: block;
position: absolute;
top: -30px;
right: 0px;
border: 10px solid transparent;
font-family: Arial;
font-size: 16px;
color: #eee;
text-decoration: none;
text-transform: uppercase;
}
#videoBox a:hover {
border: 10px solid #fff;
background: #fff;
color: #000;
}
</style>
<script>
var videoBox, video;
document.on('DOMContentLoaded', function() {
video = {
vid: document.getElementById('video'),
load: function(id) {
this.vid.loadVideoById(id);
}
};
videoBox = {
box: document.getElementById('videoBox'),
overlay: document.getElementById('overlay'),
show: function(id) {
this.box.style.left = ((window.innerWidth / 2) - 320) + 'px';
this.box.style.top = ((window.innerHeight / 2) - 205) + 'px';
this.box.style.display = 'block';
this.overlay.style.display = 'block';
video.load(id);
},
hide: function() {
this.box.style.display = 'none';
this.overlay.style.display = 'none';
}
}
});
function onYouTubePlayerReady(playerId) {
if (playerId && playerId != 'undefined') {
video.vid = document.getElementById('video');
}
}
</script>
</head>
<body>
<a href="#" onclick="videoBox.show('KgLnyDJ2R8E')">showVideo</a>
<div id="overlay"></div>
<div id="videoBox">
<a href="javascript:void(0)" onclick="videoBox.hide()">Close</a>
<object id="video" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="640" height="385">
<param name="movie" value="http://www.youtube.com/v/ylLzyHk54Z0&enablejsapi=1&playerapiid=video" />
<param name="allowFullScreen" value="true">
<param name="allowScriptAccess" value="always">
<embed id="video" type="application/x-shockwave-flash" src="http://www.youtube.com/v/ylLzyHk54Z0&enablejsapi=1&playerapiid=video" width="640" height="385" allowfullscreen="true" allowscriptaccess="always"></embed>
</object>
</div>
</body>
</html>
Please help me!