[英]How to remove a event handler from JWPlayer instance?
I'm the using JWPlayer . 我是使用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: 设置播放器之后我需要为某些事件添加监听器,举个例子我听
events.JWPLAYER_MEDIA_TIME
如下:
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. 过了一会儿我需要删除这个事件监听器 ,阅读文档我找不到任何解决方案。
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. 查看代码 ,似乎无法删除事件侦听器:当您调用
onTime
(或任何其他方法来设置事件处理程序)时,回调被推送到数组,因此第二次调用它不会覆盖以前的侦听器,但只是向该数组添加一个新的侦听器。
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;
...
}
Here is how I handled it. 这是我处理它的方式。 create a pseudo function whose sole purpose is to be a pointer.
创建一个伪函数,其唯一目的是成为一个指针。 I was concerned with the onComplete event, so I wrote the code like so below:
我关心的是onComplete事件,所以我编写了如下代码:
function createJWPlayer(surl, stitle, autos, pw, ph) {
jwplayer("videocontainer").setup({
file: surl,
title: stitle,
width: pw,
height: ph,
autostart: autos,
stretching: "uniform",
skin: "/Scripts/JWPlayer/six.xml"
});
jwplayer().onComplete(function (e) {
jwcompleteevent(e);
});
}
function jwcompleteevent(e) {
// method to remain empty, sole purpose is to provide a pointer for the handler
}
Then in the function where I created it, I wrote this: 然后在我创建它的函数中,我写了这个:
var mcomplete = (selobj.HasQ == false) ? InterActNoTimeAutoS : jwpCompleteInterA;
createJWPlayer(selobj.Upath, ti.TestTitle, true, "100%", "100%");
jwcompleteevent = mcomplete;
If I needed to load another video, I would do this 如果我需要加载另一个视频,我会这样做
mcomplete = (selobj.HasQ == false) ? InterActNoTimeAutoS : jwpCompleteInterA;
jwcompleteevent = mcomplete;
loadJwPlayerUrl(selobj.Upath, true);
If anyone sees a problem with this, please tell me, it seems to be working as needed in the development environment 如果有人发现这个问题,请告诉我,它似乎在开发环境中按需工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.