Video.js: Error after setting video src

Koby Douek Source

I'm having trouble using video.js when running videojs('vid'). My goal is to create a video.js object so I can read the current time (myPlayer.currentTime).


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


$(document).ready(function () {

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

This gives me an error:

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.

important: When Setting the src without performing videojs('vid'), the same video works fine. It's like running videojs('vid') resets all sources and fails to set the src via Javascript.



answered 1 year ago undefined #1

You can get the currentTime in videojs with it's currentTime() function.

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


function updateTime() {
  output.innerText = player.currentTime();
<link href="" rel="stylesheet"/>
<script src=""></script>

<video id="vid" class="video-js" controls autoplay>
  <source src="">


answered 1 year ago Koby Douek #2

I self-solved the problem by changing the src: '/uploads/365.mp4' to a full URL path:

comments powered by Disqus