Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

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.

like image 907
a--m Avatar asked May 02 '13 09:05

a--m


1 Answers

Looking at the code, it doesn't seem possible to remove an event listener: a callback is pushed onto an array when you call onTime (or any of the other methods to setup event handlers), so calling it a second time doesn't overwrite a previous listener but just adds a new listener to the array.

Perhaps an alternative could be to set a flag once your listener doesn't have to perform its task anymore:

onTimeHandler : function() {
  if (! this.handleOnTimeEvents)
    return;
  ...
}
like image 174
robertklep Avatar answered Nov 07 '22 05:11

robertklep