Youtube Javascript API play(); not working.. what am I doing wrong?
Posted
by
odpogn
on Stack Overflow
See other posts from Stack Overflow
or by odpogn
Published on 2011-01-08T08:22:07Z
Indexed on
2011/01/08
8:54 UTC
Read the original article
Hit count: 176
Hello,
I'm playing around with YouTubes Javascript API. I've set up a test page on my local enviornment, but the play function is not working. The video loads, and I can press play on the yt video screen, but my link "play" isn't working. Can someone tell me what I'm doing wrong??
I've been following this: http://code.google.com/apis/youtube/js_api_reference.html
<html>
<head>
<script type="text/javascript" src="public/javascripts/swfobject.js"></script>
</head>
<body>
<div id="ytapiplayer">
You will need Flash 8 or better to view this content.
</div>
<script type="text/javascript">
var params = { allowScriptAccess: "always" };
var atts = { id: "myytplayer" };
swfobject.embedSWF("http://www.youtube.com/v/OQSNhk5ICTI&enablejsapi=1&playerapiid=ytplayer", "ytapiplayer", "425", "365", "8", null, null, params, atts);
function onYouTubePlayerReady(playerId) {
ytplayer = document.getElementById("myytplayer");
}
function play() {
if (ytplayer) {
ytplayer.playVideo();
}
}
</script>
<a href="javascript:void(0);" onclick="play();">Play</a>
</body>
</html>
© Stack Overflow or respective owner