[英]JWplayer multiple player in one page and event handler
I have multiple players in the same page.我在同一页面中有多个玩家。 Each instance loads a different video.
每个实例加载不同的视频。 I need to handle similar events for every instance.
我需要为每个实例处理类似的事件。
If I just declare the events on a general function – like this jwplayer().on('play', handler)
– the handler affects only the first player of the page.如果我只是在一个通用函数上声明事件——像这样
jwplayer().on('play', handler)
- 处理程序只影响页面的第一个播放器。
If I declare the player's id
the console returns:如果我声明玩家的
id
,控制台将返回:
Uncaught TypeError: jwplayer("text").on is not a function(anonymous function)
未捕获的类型错误:jwplayer("text").on 不是函数(匿名函数)
When you first create JW Player, you can get an object back and store it in a variable.当您第一次创建 JW Player 时,您可以取回一个对象并将其存储在一个变量中。
var myJwPlayerInstance = jwplayer("JWPlayerDiv").setup({ ... });
...
myJwPlayerInstance.on("play", function () { ... });
You can do this for each JW Player instance you have, using separate variables or an array.您可以使用单独的变量或数组为您拥有的每个 JW Player 实例执行此操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.