Thursday, July 30, 2009

Sending a PLAY event to the JW Player

The JW Players by longtail video are used to display a video player control on a web page. In script, you can send events to the player to programmatically load and play a video, like this:

function initWMVPlayer(objPlayer, theFile) {
objPlayer.sendEvent('LOAD', theFile);
objPlayer.sendEvent('PLAY', 'true');
}

This seemed to work when I associated it with the click event on a playlist, but sporadically. Sometimes it worked on the first click, sometimes on the 2nd click. Then I found some references (this blog and this forum) that said you always should have a delay before sending the PLAY event. So the function should look like this:

function initWMVPlayer(objPlayer, theFile) {
objPlayer.sendEvent('LOAD', theFile);
setTimeout(function() {objPlayer.sendEvent('PLAY', 'true');}, 50);
}

No comments:

Post a Comment