YouTube Javascript API: load doesn't work in Firefox

I have an implementation of the YouTube Javscript API that works perfectly fine in Chrome and Safari, but not in Firefox. Yes, I'm doing this on a webserver ;)

On document ready, I call my function showVideo();

This is all the relevant code:

<script type="text/javascript" src=""></script>    

<div id="ytplayer" class="youtubepromovideo"></div>

<script type="text/javascript">   
function showVideo(){
    var params = { allowScriptAccess: "always" };
    swfobject.embedSWF("", "ytplayer", "400", "400", "8", null, null, params);

function onYouTubePlayerReady(playerId) {
    console.log("player ready: "+playerId);

function loadNewVideo() {
    var id = 'jc8n44ddy9A';
    var startSeconds = 0;
    console.log("loading video");
    ytplayer.loadVideoById(id, startSeconds);

In all browsers the player shows, but in Firefox the video doesn't load. My log shows the "loading video" message on firefox, but nothing else happens after that. Not even an error. If I try to call ytplayer.loadVideoById('jc8n44ddy9A', 0); manually after everything is loaded, I get the error ReferenceError: ytplayer is not defined.

I realize that ytplayer isn't explicitly defined as a variable by me, but my guess(?) is that the YouTube API does that because it works in the other browsers. Also if I defined just var ytplayer globally somewhere it doesn't fix it.

Any advise is much appreciated!


Not sure where the other browsers get the ytplayer reference from, but you should have it defined globally (for the example you've given, anyway) and add the reference to it in onYouTubePlayerReady:

ytplayer = document.getElementById( playerId );

You would likely be better off using the iframe player, for support in browsers without Flash, too. I believe it can be loaded without controls using the "controls" parameter.

Need Your Help

How to use the XQuery fn:id() function?

schema xquery

I'm failing in my first attempt to get the fn:id() XQuery function to do something.

Is it good idea to clone cakephp model objects?

php cakephp

How can I use cake's model object for me to be able to do this in a controller: