Javascript events in JW Player 5.7 not working
Like it says.... The player loads, the video appears and plays properly, but none of the events are firing. My setup code looks like:
jwplayer("preview").setup({
flashplayer: "a-valid-path",
file: "-a-valid-url",
image: "-a-valid-url",
width: "600",
height: "362",
events: {
onReady: function(开发者_JAVA百科event) { alert("player is ready"); },
onPlay: function(event) { alert("player is playing"); }
}
});
Nothing's coming up in the js console; I'm getting the same the same (non-)result in all the obvious browsers. I've also tried breaking the event handlers out into standalone functions per the documentation, but to no effect. Any advice out there? Thanks!
OK, my bad, I guess. I was converting my code from an older version of JW Player, one where the method of hooking up the listeners to the player required some code like this:
var player = null;
function playerReady(thePlayer) {
player = document.getElementById(thePlayer.id);
addListeners();
function addListeners() {
if (player) {
console.log('add the listener');
player.addModelListener('STATE', 'mediaPlayerState');
}
else {
setTimeout("addListeners()", 100);
}
}
function mediaPlayerState(obj) {
doStuff();
}
Anyway, I had neglected to take that out, and something, somewhere was breaking (without error messages). Once the old code was removed, my events stuff began to work.
I just had the same issue. The fix I found was to make sure the flashplayer and jwplayer.js urls are on the same domain as the page being loaded. If they do not match the video will still play and everything else will work fine but events will not fire.
精彩评论