2017-04-30 159 views
0

我在运行videojs('vid')时无法使用video.js。我的目标是创建一个video.js对象,以便我可以读取当前时间(myPlayer.currentTime)。Video.js:设置视频后出错src

HTML:

<video id="vid" class="video-js" controls autoplay data-setup="{}"> 
    <source id="src1"> 
</video> 

的Javascript:

$(document).ready(function() { 

    videojs('vid').ready(function() { 
     var myPlayer = this; 
     myPlayer.src({ type: 'video/mp4', src: '/uploads/365.mp4' }); 
    }); 
}); 

这给了我一个错误:

VIDEOJS: ERROR: (CODE:4 MEDIA_ERR_SRC_NOT_SUPPORTED) The media could not be loaded, either because the server or network failed or because the format is not supported.

重要:当设置SRC不执行videojs('vid'),相同的视频工作正常。这就像运行videojs('vid')重置所有来源并且未能通过Javascript设置src

+0

为什么你无法从'

+0

那是不可能的。 –

+0

为什么?如果你真的想要这个,你可以在源代码中添加一个虚拟url,然后按照你喜欢的方式改变它。 ''。但我仍然认为'

回答

1

我自我解决了这个问题:https://example.com/uploads/365.mp4

0

您可以通过它的currentTime()函数获取currentTime的videojs。通过改变src: '/uploads/365.mp4'到一个完整的URL路径

var output = document.querySelector('output'); 
 
var player = videojs('vid'); 
 

 
requestAnimationFrame(updateTime); 
 

 
function updateTime() { 
 
    output.innerText = player.currentTime(); 
 
    requestAnimationFrame(updateTime); 
 
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/video.js/6.0.1/alt/video-js-cdn.min.css" rel="stylesheet"/> 
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/video.js/6.0.1/video.min.js"></script> 
 

 
<video id="vid" class="video-js" controls autoplay> 
 
    <source src="https://www.w3schools.com/html/mov_bbb.mp4"> 
 
</video> 
 

 
<output></output>