Name is required.
Email address is required.
Invalid email address
Answer is required.
Exceeding max length of 5KB

JW Player - not working the event


Hello everyone, I can not understand why the event does not work, for example onPlay:

bc.. <html>
<head>
<script type="text/javascript" src="/jwplayer.js"></script>
</head>

<div id="videoplayer220"></div>

<script type="text/javascript">
jwplayer("videoplayer220").setup({
flashplayer: "/player.swf",
file: "/list.xml",
width: 390,
height: 295,
events: {
onPlay: function() { alert("Player is playing"); }

/*onPause: function(e) {
alert ('321');
if (e.oldstate == 'PLAYING')
{
alert ('321');
}
}*/
}
});
</script>
</html>



Although the video is playing well and there are no JavaScript errors ...

No one with such a problem not encountered?

9 Community Answers

JW Player

User  
0 rated :

unfortunately the demo page, I can not put an example of the error, if anything, can copy the code that I wrote in the first post, personally I have not earned it ... By the way heard that the events in this player does not work in all browsers?

JW Player

User  
0 rated :

I don't understand.. I have the same problem. no events are fired at all.
there are no JS errors, the player is loaded fine and the songs play OK. everything is just OK, but the events are never fired...

JW Player

User  
0 rated :

I'm having the same problem, and I am on https. Any advice?

JW Player

User  
0 rated :

Hello everyone. I'm having the same issues here. I see events fire perfectly on OS X with Chrome only. They work perfectly with IE8, Chrome, and FF4 on Windows.

FF4 and Safari on OS X I see no events being fired either in the console or obviously in the server log. The following is a snippet of what we're doing:
bc.. jwplayer('viewer').setup({
flashplayer: '/media/js/jw5-5/player.swf',
height: 320,
width: w,
controlbar: 'over',
screencolor: '#000000',
autostart: true,
skin: '/media/js/jw5-5/modieus.zip',
file: url+vid,
provider: 'rtmp',
'rtmp.loadbalance': 'true',
tags: trsrc
});


jwplayer().onPlay(function(event){
console.log('onPlay', 'oldstate=='+event.oldstate+'');
alert(event.oldstate);
Ext.Ajax.request({
url: '/dashboard/chuckstemppost/',
params: "eventname=onPlay&oldstate=" + event.oldstate
});
}).onMute(function(event){
console.log('onMute', event.mute+'');
}).onVolume(function(event){
console.log('onVolume', 'volume=='+event.volume+'');
}).onFullscreen(function(event){
console.log('onFullscreen', event.fullscreen+'');
}).onError(function(event){
console.log('onError', 'message=='+event.message+'');
}).onBufferChange(function(event){
console.log('onBufferChange', event.percent+'%');
}).onPause(function(event){
console.log('onPause', 'oldstate=='+event.oldstate+'');
}).onBuffer(function(event){
console.log('onBuffer', 'oldstate=='+event.oldstate+'');
}).onComplete(function(event){
console.log('onComplete', 'fired.');
}).onTime(function(event){
strDuration = event.duration+'';
strPosition = event.position+'';
strOffset = event.offset+'';
theData = strDuration+', '+strPosition+', '+strOffset;
console.log('onTime', theData);
});

JW Player

User  
0 rated :

To clarify, the video / audio plays perfectly in all cases. Just no JS API events on those two browsers.

JW Player

User  
0 rated :

Further, we are currently playing back in http only.

JW Player

User  
0 rated :

Sorry, these particular items are company protected and behind a login. I have discovered that for some reason the API doesn't work consistently unless you're running through an actual web server. The local django test server that I was causing issues.

Now, however, I've noticed something related, but different. Across all browsers the API stops firing events after a page refresh or if the same page is opened in a separate tab or window during the same session. I'm using some randomization to name everything---from jwplayer instance, to the <div> being used to load the page, etc with a js function. Even then, no matter what only the first video first page shows any API activity and then only until you refresh the page. Any ideas on that one?


examples:
bc.. function randomString() {
var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
var string_length = 12;
var randomstring = '';
for (var i=0; i<string_length; i++) {
var rnum = Math.floor(Math.random() * chars.length);
randomstring += chars.substring(rnum,rnum+1);
}
return randomstring;
}

var localTrack;
var localPlayer;

function initVid(vid,player,url,title,trsrc){
//gen key
var ci = randomString();

var mediaspace_attributes=document.getElementById("mediaspace").attributes

mediaspace_attributes["id"].value += '_'+ci;

//alert('mediaspace_attributes("id").value=='+mediaspace_attributes("id").value);

//alert('local random string=='+context_identifier);

//console.log('medial library initVid trsrc=='+trsrc);
//Need to set the info tab to active at this point
tabs = Ext.getCmp('upperLayout').getComponent('catcont').getComponent('cattabs');
tabs.setActiveTab('t3');
try {
var assetTitle = Ext.get('vidTitle');
assetTitle.update(title);
var w;
switch (player) {
case 1:
//4x3 limelight CDN
w = "475";
break;
case 2:
//16x9 limelight CDN
w = "563";
break;
case 8:

w = "475";
break;
case 9:
w = "563";
break;
case 19:
w = "533";
break;
case 20:
w = "425";
break;
case 21:
w = "475";
break;
}
/*
if(jwplayer('viewer')){
jwplayer().remove();
}
*/
if (player == 8 || player == 9 || player == 20) {
window['localPlayer'+ci] = jwplayer('mediaspace_'+ci).setup({
flashplayer: '/media/js/jw5-5/player.swf?clear='+context_identifier+Math.floor(Math.random()*1000),
id: 'jw_'+ci,
height: 320,
width: w,
controlbar: 'over',
screencolor: '#000000',
autostart: true,
skin: '/media/js/jw5-5/modieus.zip',
file: url + vid,
provider: 'rtmp',
'rtmp.loadbalance': 'true',
//tags: trsrc

});
}else if (player == 21) {
window['localPlayer'+ci] = jwplayer('mediaspace_'+ci).setup({
flashplayer: '/media/js/jw5-5/player.swf?clear='+context_identifier+Math.floor(Math.random()*1000),
id: 'jw_'+ci,
height: 320,
width: w,
controlbar: 'over',
screencolor: '#000000',
autostart: true,
skin: '/media/js/jw5-5/modieus.zip',
playlist: url,
provider: 'rtmp',
'rtmp.loadbalance': 'true',

});
console.log('playertype 21 line 82, url=='+url);
//wplayer().load({'file':"'"+url+"'", 'provider':'rtmp', 'rtmp.loadbalance':'true'});
}else if (player == 22) {
window['localPlayer'+ci] = jwplayer('mediaspace_'+ci).setup({
flashplayer: '/media/js/jw5-5/player.swf?clear='+context_identifier+Math.floor(Math.random()*1000),
id: 'jw_'+ci,
height: 320,
width: w,
controlbar: 'over',
screencolor: '#000000',
autostart: true,
skin: '/media/js/jw5-5/modieus.zip',
'playlistfile': url,
provider: 'rtmp',
'rtmp.loadbalance': 'true',
"playlist.position": "right",
"playlist.size": 300,

});
console.log('playertype 22 line 100, url=='+url);
//wplayer().load({'file':"'"+url+"'", 'provider':'rtmp', 'rtmp.loadbalance':'true'});
}
else {
Ext.MessageBox.alert('Player Selection Error', 'The wrong player has been chosen. Please contact support.')
}


console.log('junk','Mike wants me to throw this junk {{ context_identifier }}');


//window['localTrack'+ci] = '';

window['localTrack'+ci] = new localTrackModel();
window['localTrack'+ci].local_id = context_identifier+Math.floor(Math.random()*1000);
window['localTrack'+ci].event_type = 'init';
window['localTrack'+ci].filename = vid;
window['localTrack'+ci].tracking_source = trsrc;
window['localTrack'+ci].context_identifier = ci;
window['localTrack'+ci].last_position = 0;
window['localTrack'+ci].current_position = 0;
window['localTrack'+ci].total_time = 0;
window['localTrack'+ci].iterator = 0;
jwplayer().onPlay(function(event){
//console.log('console onPlay', 'oldstate=='+event.oldstate+'');
window['localTrack'+ci].reportJWStaticTracking('onPlay',event);
//expand to start or kill localTimer
}).onMute(function(event){
//console.log('onMute', event.mute+'');
window['localTrack'+ci].reportJWStaticTracking('onMute',event);
}).onVolume(function(event){
//console.log('onVolume', 'volume=='+event.volume+'');
window['localTrack'+ci].reportJWStaticTracking('onVolume',event);
}).onFullscreen(function(event){
//console.log('onFullscreen', event.fullscreen+'');
window['localTrack'+ci].reportJWStaticTracking('onFullscreen',event);
}).onPause(function(event){
//console.log('onPause', 'oldstate=='+event.oldstate+'');
window['localTrack'+ci].reportJWStaticTracking('onPause',event);
}).onBuffer(function(event){
//console.log('onBuffer', 'oldstate=='+event.oldstate+'');
window['localTrack'+ci].reportJWStaticTracking('onBuffer',event);
}).onComplete(function(event){
//console.log('onComplete', 'fired.');
event='';
window['localTrack'+ci].reportJWStaticTracking('onComplete',event);
window['localTrack'+ci] = '';
window['localTrack'+ci] = new localTrackModel();
window['localTrack'+ci].local_id = context_identifier+Math.floor(Math.random()*1000);
window['localTrack'+ci].event_type = 'initAfterSameSessionComplete';
window['localTrack'+ci].filename = vid;
window['localTrack'+ci].tracking_source = trsrc;
window['localTrack'+ci].context_identifier = context_identifier;
window['localTrack'+ci].last_position = 0;
window['localTrack'+ci].current_position = 0;
window['localTrack'+ci].total_time = 0;
window['localTrack'+ci].iterator = 0
}).onTime(function(event){
window['localTrack'+ci].reportJWTimedTracking(event);
}).onError(function(event){
//console.log('onError', 'message=='+escape(event.message));
window['localTrack'+ci].raiseJWError(event);
}).onPlaylist(function(event){
console.log('onPlaylist',event.playlist);

//window['localTrack'+ci].is_playlist = true;

window['localTrack'+ci].reportJWStaticTracking('onPlaylist',event);
}).onPlaylistItem(function(event){
console.log('onPlaylistItem',event.index);
playlist_id = window['localTrack'+ci].local_id;
event='';
window['localTrack'+ci] = '';
window['localTrack'+ci] = new localTrackModel();
window['localTrack'+ci].local_id = context_identifier+Math.floor(Math.random()*1000);
window['localTrack'+ci].event_type = 'onPlaylistItem';
window['localTrack'+ci].filename = vid;
window['localTrack'+ci].tracking_source = trsrc;
window['localTrack'+ci].context_identifier = context_identifier;
window['localTrack'+ci].last_position = 0;
window['localTrack'+ci].current_position = 0;
window['localTrack'+ci].total_time = 0;
window['localTrack'+ci].iterator = 0
window['localTrack'+ci].playlist_id = playlist_id;

window['localTrack'+ci].reportJWStaticTracking('onPlaylistItem',event);
});

}
catch(err){
alert(err);
}


}



JW Player

User  
0 rated :

Okay, so I've ruled out flash cache as the issue. Not only am I being ridiculous with cache hacks, but just to be sure I adjust my global flash settings so that the site has 0 storage and "never ask again" even though I am certain that it is downloading the files everytime....same result.

Just to be clear about procedure:
1. Load page
2. click button to load video
- video plays, api events are fired -
3. either click the reload / refresh button, open a second tab to the same page, or navigate away and return to the page.
4. click button to load video

- video plays, NO API EVENTS are fired -

5. either clear browser cache or close browser, repoen and repeat steps 1-2.

- video plays, api events ARE fired -

I'm just a little lost on this one.

JW Player

User  
0 rated :

Events can be blocked by the player security model. Set the player global security to 'allow' for the source URL.

This question has received the maximum number of answers.