Search code examples
javascripthtmlvideo.js

VideoJs manual initialization failed


I am using the videojs version 5.17.0. I have setup the videojs using the video tag and added two video source. If Webm video source is not working so it should fallback to MP4 video which is working If don't use the javascript to manually initialize videojs player.

<video id = "my-player" class="video-js">
<source id="webm" src="https://media.w3.org/2010/05/sintel/trailer.webm" type='video/webm'>
<source id="mp4" src="https://media.w3.org/2010/05/sintel/trailer.mp4"  type='video/mp4'>   
</video>

Also, I need to get the videojs object using java-script and include the ads and keep track of video using the java-script.

Now the problem is if the webm video source is not working then it's crashed on initializing videojs player object in javascript.

var myPlayer = videojs("my-player"));  //this is where error happen

myPlayer.play();

Solution

  • Initializing the videoJS in onDocumentReeady() method solved the issue. However, this is the ideal way to handle this but still need to better handle this issue.