Reputation: 4331
I'm trying to manipulate an Youtube object via JavaScript. But once I call a function like seekTo(), JS engine tells me there is no such function:
<script type="text/javascript" src="swfobject.js"></script>
<div id="ytapiplayer"></div>
<script type="text/javascript">
var params = { allowScriptAccess: "always" };
var atts = { id: "ytplayer" };
swfobject.embedSWF("http://www.youtube.com/v/tS3J2BkLamQ?enablejsapi=1&playerapiid=ytplayer",
"ytapiplayer", "425", "356", "8", null, null, params, atts);
</script>
<a href="javascript:void(0);" onclick="ytplayer.seekTo(10,true)">seek</a>
There are three IDs in the official example. I tried them all with no result.
Fiefox 6 AFAIK
UPD Finally I figured out such code must be run at the server side.
Upvotes: 0
Views: 144
Reputation: 4331
The answer is: the code should be run on the server side due to restrictions of Flash.
Upvotes: 0
Reputation: 22125
You will first need to make sure your ytplayer
JS object is set to the right thing - you can do this inside a call to onYouTubePlayerReady()
:
function onYouTubePlayerReady(playerId) {
// create a global variable called ytplayer
ytplayer = document.getElementById("ytplayer");
}
I think the API calls this function for you once the player has loaded - you don't need to register it.
Edit: here is a link to a working jsfiddle:
Upvotes: 2