javascript jwplayer 6 安装程序不再支持事件回调。如果我无法在设置中指定 onReady 回调,如何判断播放器何时准备就绪?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13961608/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jwplayer 6 setup no longer supports event callbacks. how to tell when player is ready if I cannot specify onReady callback within setup?
提问by moondog
I am trying to migrate from jw5 to jw6. In jw5, I included event callbacks within the player setup. For example:
我正在尝试从 jw5 迁移到 jw6。在 jw5 中,我在播放器设置中包含了事件回调。例如:
var myplayer = jwplayer('container').setup({
flashplayer: /my/player.swf',
height: '100%',
width: '100%',
events: {
'onReady': function(event) {
alert ("on ready");
},
'onPlay': function(event) {
alert ("on play");
},
}
});
According to the jw5-to-jw6 migration documentation, it seems I can no longer include event callbacks within the player setup:
根据 jw5-to-jw6 迁移文档,似乎我不能再在播放器设置中包含事件回调:
Removed: the events configuration block This way of adding event listeners is fully redundant with adding listeners outside the setup, both in terms of features and amount of code required.
删除:事件配置块这种添加事件侦听器的方式在设置之外添加侦听器是完全多余的,无论是在功能还是所需的代码量方面。
If I understand correctly, I am supposed to specify the event callbacks this way:
如果我理解正确,我应该以这种方式指定事件回调:
myplayer.onReady( function(event){
alert('on ready');
});
myplayer.onPlay( function(event){
alert('on play');
});
My Question:
我的问题:
It seems to me I need to wait for the myplayer object to be ready, before I can define these myplayer event callbacks. True? How do I know when myplayer is ready, if I cannot specify the onReady event callback within the setup?
在我看来,我需要等待 myplayer 对象准备好,然后才能定义这些 myplayer 事件回调。真的?如果无法在设置中指定 onReady 事件回调,我如何知道 myplayer 何时准备就绪?
回答by Inferpse
In JWPlayer6 you can add onReady
event handler the same way you add others. This works for me:
在 JWPlayer6 中,您可以像添加其他onReady
事件处理程序一样添加事件处理程序。这对我有用:
var playerInstance = jwplayer("myElement").setup({
file: "test.mp4"
});
playerInstance.onReady(function() {
console.log('ready');
playerInstance.onPlay(function() {
console.log('playing');
});
playerInstance.play();
});
回答by andi1984
The first issue is, that you have a typo in your last code block: it should be myplayer.onReady()
;-)
第一个问题是,您在最后一个代码块中有一个错字:应该是myplayer.onReady()
;-)
Furthermore the event handlers get hooked up to the corresponding objects as soon as they are proceeded.
此外,事件处理程序一开始就连接到相应的对象。
So I think you should simply put your jwplayer setup and onReady
& onPlay
events into $(document).ready()
.
所以我认为你应该简单地将你的 jwplayer 设置和onReady
&onPlay
事件放入$(document).ready()
.
I think this should work as expected.
我认为这应该按预期工作。