javascriptdom-eventsjwplayer

JWPlayer 4 javascript events are ignored


First of all, I can't upgrade to a newer version of the player, because I need the displayclick=fullscreen option to work, and it doesn't with version 5.

So, what I need to do is this: have the player auto-start with no volume and no controls on the page (this works just fine), and when the user clicks the screen the player must go full-screen and the volume must turn on.

The problem is all Javascript interaction seems to be completely ignored by the player, and I really can't see where the problem is.

When the page is loaded, I embed the player:

var so = new SWFObject('path_to_player.swf','div_id','200','120','10');
so.addParam('allowfullscreen','true');
so.addParam('allowscriptaccess','sameDomain');
so.addParam('bgcolor','#000000');

so.addParam('flashvars','file=path_to_playlist.xml&autostart=true&displayclick=fullscreen&controlbar=none&volume=0&icons=false&image=path_to_thumb.jpg');
so.write('div_id');

This seems to work just fine, the player is loading.

Then I add the event listeners:

var player = null;
function playerReady(p) {
    player = document.getElementById(p.id);
    addListeners();
}

function addListeners() {
    if (player) {
        console.log('add the listener');
        console.log(player.getConfig().volume);
        player.addControllerListener("RESIZE", "checkResize");
    } else {
        setTimeout("addListeners()", 100);
    }
}

function checkResize(obj) { 
    console.log('resized');
    if (obj.fullscreen) { 
        player.sendEvent("VOLUME", "60");
    } else { 
        player.sendEvent("VOLUME", 0);
    }
}

The "add the listener" message gets displayed in the console, but the second one, with the player's volume doesn't, and neither does the "resized" one when the player enters or exits fullscreen (and, obviously, the volume doesn't turn on).

I've tried other listeners, for both model and controller, and they don't seem to work. Sending events doesn't work either.

I've tried running just the code for the player separately, to make sure there are no other things interfering with the code, but I still have the same problem.


Solution

  • Well, it seems I've found the answer myself. Upgrading to a newer version of swfobject and using swfobject.embedSWF() seems to work just fine.