我该如何收听"timeupdate"消息?我的video.js播放器播放事件? [英] How can I listen for the "timeupdate" event from my video.js player?
本文介绍了我该如何收听"timeupdate"消息?我的video.js播放器播放事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
虽然我可以使用普通的HTML5播放器收听"timeupdate"事件,但似乎无法使其与video.js一起使用.
While I have been able to listen for the "timeupdate" event with a vanilla HTML5 player, I can't seem to get it to work with video.js.
这是我的代码:
<!DOCTYPE html>
<html>
<head>
<link href="video-js.css" rel="stylesheet">
<script src="video.js"></script>
<script src="jquery.min.js"></script>
</head>
<body>
<video id="testvid" class="video-js vjs-default-skin" controls width="640" height="480" data-setup='{}'>
<source src="testvideo.mp4" type="video/mp4">
</video>
</body>
</html>
<script>
videojs('testvid').ready(function(){
var myPlayer = this;
$(myPlayer).bind('timeupdate', function(){
console.log('the time was updated to: ' + this.currentTime);
});
});
</script>
我是否误解了video.js的基本运行方式?
Am I misunderstanding a basic way that video.js operates?
推荐答案
我必须在视频加载之前添加事件监听器.我通过将脚本更改为以下方式解决了该问题:
I have to add the event listener before the video loads. I solved the problem by changing the script to:
<script>
$('#testvid').on('timeupdate', function(){
console.log('the time was updated to: ' + this.currentTime);
});
videojs('testvid').ready(function(){
var myPlayer = this;
});
</script>
这篇关于我该如何收听"timeupdate"消息?我的video.js播放器播放事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文