Pavel Vlasov
Pavel Vlasov

Reputation: 4331

None API function could be found scripting a YouTube object

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

Answers (2)

Pavel Vlasov
Pavel Vlasov

Reputation: 4331

The answer is: the code should be run on the server side due to restrictions of Flash.

Upvotes: 0

Timothy Jones
Timothy Jones

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:

http://jsfiddle.net/cZdZK/

Upvotes: 2

Related Questions