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

How to remove a event handler from JWPlayer instance?


I'm the using JWPlayer. After setup the player I need to add listeners to some events, to give an example I listen to events.JWPLAYER_MEDIA_TIME like so:
bc.. jwplayer('video-container').onTime(this.onTimeHandler);



After a while I need to remove this event listener, reading the documentation I couldn't find any solution, but reading the source code I see there is a removeEventListener function, although I can't find it exposed on the player api.

I've read a answer in this forum that sugests to use an external variable to keep track of some condition, although this can work it's far from being a good solution.

14 Community Answers

Ethan Feldman

JW Player Support Agent  
0 rated :

Answered here :)

http://stackoverflow.com/questions/16334925/how-to-remove-a-event-handler-from-jwplayer-instance

JW Player

User  
0 rated :

wondering if this may be helpful for you

bc.. $('#myimage').click(function() { return false; }); // Adds another click event
$('#myimage').off('click');
$('#myimage').on('click.mynamespace', function() { /* Do stuff */ });
$('#myimage').off('click.mynamespace');




you would have to make changes to the code above to suit your needs etc.

off/on is preferred than using bind/unbind with respect to event listeners.

Ethan Feldman

JW Player Support Agent  
0 rated :

That may be.

JW Player

User  
0 rated :

Hi Ethan and Willie,
Thank you for your time. Ethan, I wrote the question on stackoverflow, and added a comment to the only answer, from my point of view you can say it works, but it won't solve the problem, as removing a event listener it's different from preventing the handler code from being executed.

Willien points out what I wish to achieve, but I couldn't bind the jquery events to the player, maybe I'm not targeting the target as I should, I used the following code:

bc.. $('#video-container').on('events.JWPLAYER_MEDIA_TIME', function(e){
console.log(e);
});


It doesn't output anything... any ideas?

JW Player

User  
0 rated :

I wonder if this may be of help for you. You would most likely have to change things to suit your needs in this example I am using *Ethan's Newsticker* to activate/deactivate the Newsticker based on the event time/position.

bc.. /* this function will determine the time for the display of the
Newsticker namely for the first 30s and for 30s before completing */
function timeHandler(evt)
{
var X = evt.duration - 30;
if ((evt.position < 30) || evt.position > X)
{
document.getElementById('newsticker1').style.visibility='visible';
} else{
document.getElementById('newsticker1').style.visibility='hidden';
}
}



Let me explain the above.

Since the onMeta in JWP6.4.3359 does not work and that the controlbar will indicate after the media begins to play the duration of the event(length of the media)

If for example the length of the media is 4:36 then the controlbar will indicate 4:36 and since the controlbar is event driven you can exploit this by using the code above; I use this in my JWP6 example section om my web site.

JW Player

User  
0 rated :

forgot....time for coffee ;-)

you would have to set under the events in your options

bc.. events:
{
onFullscreen: fullHandler,

}



In all of my events option for the JWPlayer, I use the following
for example:

bc.. events:
{
onFullscreen: fullHandler,
onBeforePlay: beforeHandler,
onTime: timeHandler,
onPlaylistItem: playlistHandler,
onPlay: playHandler,
onPause: pauseHandler,
onComplete: completeHandler
}

Ethan Feldman

JW Player Support Agent  
0 rated :

@am – Oh, I see. Do you have an example?

JW Player

User  
0 rated :

Hi Ethan, I've provided an example in my question, the question is really simple, once you have add a event handler you can't remove it, at least it's not documented how to do it.
I've checked the player code source, I see that there is some code to remove events, but I guess it's not exposed to the api.

I would like to know if there is any solution for this problem, as it seams to me a commun feature.

Thank you.

Ethan Feldman

JW Player Support Agent  
0 rated :

Sorry, I meant a link. Regarding not being able to remove events, I will ask.

JW Player

User  
0 rated :

Thank you Ethan, it looks like you are on different timezones (I'm in Europe/Spain) this will be difficult to keep a conversation here =P

I don't have a link, the code we are using is the same provided in the example above, as for the removing the event it is very similar to the answer in the stackoverflow link that you told.

JeroenW

JW Player Support Agent  
0 rated :

We indeed don’t yet have options to remove event listeners. People generally work around this by implementing a true/false flag for when they want to ignore events. Would that work in your case as well?

Ethan Feldman

JW Player Support Agent  
0 rated :

np am :P

JW Player

User  
0 rated :

Hi, JeroenW it works, but it's far but being a good solution, I can give you more details on the actual problem.
During the playback of the video we have several modules/section that show/hide, each one should be able to be created and latter destroyed, while they live (show) they listen to events of the video, make them dependent on that reference, when we call on destroy one section we are able to remove all references variables of that module with the exception of the handlers that where set to the video. This makes the modules dependent on the video till the video object is destroyed, at that moment the handlers / listeners are removed.
We wish it worked differently, being able to remove each handler would be a great feature.

Ethan Feldman

JW Player Support Agent  
0 rated :

We can look into this.

This question has received the maximum number of answers.