jQuery 结束事件 videojs 不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16573974/
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
ended event videojs not working
提问by Jason Schot
I would like to trigger a simple event when my video is finished. I've placed this directly bellow my video tag.
我想在我的视频完成后触发一个简单的事件。我把它直接放在我的视频标签下面。
<script type="text/javascript">
var myPlayer = videojs("session_video");
videojs("session_video").ready(function(){
this.addEvent("ended", function(){
alert('Here I am');
});
});
</script>
However I get: TypeError: this.addEvent is not a function and I can't find why.
但是我得到: TypeError: this.addEvent is not a function,我找不到原因。
You can see it live here: 78.47.121.50 (stackoverflow won't allow to make that a link) enter code 01-01-01-2012 to bring up the video.
您可以在此处实时查看:78.47.121.50(stackoverflow 不允许将其设为链接)输入代码 01-01-01-2012 以显示视频。
Any insight is much apricaited!
任何见解都非常受欢迎!
Kind regards, Jason.
亲切的问候,杰森。
回答by Lyn Headley
"addEvent" and "removeEvent" were replaced by "on" and "off"
“addEvent”和“removeEvent”被“on”和“off”取代
try:
尝试:
this.on("ended", function(){
回答by khichar.anil
The endedevent will not fire if end user intentionally seek the video to end keeping video as paused. I was able to get it work as:
在结束事件不会火,如果最终用户有意寻求视频作为暂停结束保持视频。我能够让它工作:
<script type="text/javascript">
var player = videojs('my_video', {}, function() {});
player.ready(function(){
var duration_time = Math.floor(this.duration());
this.on('timeupdate', function() {
var current_time = Math.floor(this.currentTime());
if ( current_time > 0 && ( current_time == duration_time ) ){
$('#continue_button').removeAttr("disabled");
}
});
});
</script>
回答by Dziamid
For those who still have problems with ended events in some browsers you can resort to this fix:
对于那些在某些浏览器中仍然遇到结束事件问题的人,您可以使用此修复程序:
player.ready(function() {
var myPlayer = this;
playerInstance.on("timeupdate", function(event) { //chrome fix
if (event.currentTarget.currentTime == event.currentTarget.duration) {
console.log('video ended');
}
});
});
回答by BeatingBytes
On Stackoverflow i find one part of solution the otherpart find it from Lyn Headley top answer.
在 Stackoverflow 上,我找到了解决方案的一部分,另一部分从 Lyn Headley 的最佳答案中找到。
<script type="text/javascript">
//rename subtitle button
videojs.addLanguage('de', {
"captions off": "Untertitel aus",
});
videojs(document.querySelector('video') /* or selector string */, {
techOrder: ['html5', 'flash'],
controls: true,
autoplay: false,
preload: 'false',
language: 'de',
flash: {
swf: 'video-js.swf'
}
}, function(){
// Player (this) is initialized and ready.
this.on('ended', function(){
alert('ended');
});
this.on('firstplay', function(){
alert('firstplay');
});
});
</script>
this will alert you on the end of video. place it under the code of your video and it should works.
这将在视频结束时提醒您。将它放在您的视频代码下,它应该可以工作。