我需要在视频JS中创建一个自定义事件,在播放期间的某个时刻触发。
例如:
player.on('timeupdate',function(){
if(player.currentTime> 50){
// trigger some custom event like 'played50Second'
}
});
然后我想做:
player.on('played50Second',function(evt){
console.log('Great Job, you played 50 second of the video!!!')
});
我怎样才能做到这一点?
答案 0 :(得分:4)
player.trigger('played50Second');
您可能希望确保只触发一次,而不是每次currentTime()
大于50时。currentTime
是video.js API中的一个函数,因此player.currentTime() > 50
。
var player = videojs('my_player');
var timeCheck = function() {
if (player.currentTime() > 50) {
player.off('timeupdate', timeCheck);
player.trigger('played50Second');
}
};
player.on('played50Second', function(){
console.log('...');
});
player.on('timeupdate', timeCheck);