问题描述
我正在用videojs做一些相当简单的事情。我只是想通过单击外部构建的UI(不是默认的搜索内容,而是一组像进度条一样的div)将时间设置为时间轴上的任意点。
所有文档和每篇文章似乎都表明将currentTime设置为object.currentTime(time)即可。但就我而言,事实并非如此。不在控制台中,不在任何地方。
这是我的代码:
function clearSetTimeBug(videoObj,timetoSetTo){
console.log('timetoSetTo:'+timetoSetTo);
console.log("-1."+videoObj.id()+" readyState(): "+videoObj.readyState());//returns 4 (loaded)
console.log("0."+videoObj.id()+" bufferedEnd(): "+videoObj.bufferedEnd());//returns about 2 seconds ahead of where the playhead is)
if(videoObj.bufferedEnd()>timetoSetTo){
console.log("1."+videoObj.id()+" currentTime(): "+videoObj.currentTime()); // returns a valid videojs object id and then shows the currentTime to be where the video's current timecode as a float.
videoObj.currentTime(timetoSetTo);//this should totally work!
console.log("2."+videoObj.id()+" currentTime(): "+videoObj.currentTime());// shows that the current time is 0!
}else{
//I added this to just go to as far as it's buffered,but this doesn't work either
console.log("3."+videoObj.id()+" currentTime(): "+videoObj.currentTime());
console.log("4. newTime: "+videoObj.bufferedEnd());
videoObj.currentTime(videoObj.bufferedEnd());
pageTime=videoObj.bufferedEnd();
console.log("5."+videoObj.id()+": "+videoObj.currentTime());// still shows that the current time is 0!
console.log("6. pageTime:"+pageTime);
}
}
播放器会像这样旋转:
function setUpPlayers(playerId,playlist,local_file,index){
let myAspectRatio=heightRatio+":1"
let videoTag="";
videoTag +="<video id='playerInstance"+index+"' class='video-js vjs-fluid' width='100%' height='100%'>\n";
videoTag +="\t<source src='"+playlist+"' type='video/mp4'>\n";
videoTag +="</video>\n"
$('#player'+index).html(videoTag);
window["vjplayer"+index]=videojs("playerInstance"+index,{"autoplay": false,"preload": "auto" });
}
Play()和pause()甚至currentTime()都可以获取当前时间。但是尝试设置它只会迫使玩家回到0。
我正在Mac上使用Chrome版本86.0.4240.80和Firefox开发人员版本71.0b1(64位)。这些都是本地文件,我正在从http:// localhost:8000 / index.PHP运行它。
解决方法
在video.js github频道中,我找到了这个问题的答案。我没有在服务器上对其进行检查,因此在本地运行页面会增加单击和设置currentTime的能力。实际上,这很奇怪。我仍然不确定为什么会这样。您可以在此处查看评论:https://github.com/videojs/video.js/issues/6900
这不是我最明智的举动,但希望这可能对将来的其他人有所帮助。