我尝试使用以下条件创建videojs函数
到目前为止,除了禁止搜索未观看的视频部分外,一切工作都很顺利。
发生的事情是,用户转发第一次成功回到当前时间。但是当第二次完成前进搜寻时
以下是我的代码
var video = videojs('#my-video').ready(function(){
var player = this;
if(player.tagAttributes['data-completed'] == "true"){
//if video is tagged as completed. user has free control of the seekbar
}
else{
//starts where user left off
$.ajax({
url: base + "site/get_currentTime",
type:'POST',
dataType: 'json',
success: function(result){
player.currentTime(result.currentTime);
},
error: function(ts) { }
});
//returns the video to the time before seeking happened
player.on("seeking", function(event) {
$.ajax({
url: base + "site/get_currentTime",
type:'POST',
dataType: 'json',
success: function(result){
//result.currentTime is the time saved in the database
if (result.currentTime < player.currentTime()) {
player.currentTime(result.currentTime-1);
}
},
error: function(ts) { }
});
});
//save to database the current time of the video
player.on("timeupdate", function(event) {
var seek_status = player.seeking();
if(seek_status == false){
$.ajax({
url:player.tagAttributes['data-url'] + "/" + player.currentTime(),
type:'POST',
dataType: 'json',
success: function(result){
},
error: function(ts) { console.log(ts)}
});
}
});
//sets the video to completed
player.on('ended', function() {
$.ajax({
url:player.tagAttributes['data-url'],
type:'POST',
dataType: 'json',
success: function(result){
console.log(result);
},
error: function(ts) { }
});
});
}
});
我认为发生的事情是,即使发生搜索事件,timeupdate事件仍在运行。是否有任何解决方法可以防止这种情况发生?