Reputation: 285
I am trying to create a javascript video application,i have added video js to my project and started using it.Now in my onload I'm trying to access videojs programatically and it is throwing Uncaught referenceError:videojs is not defined. I'm new to javascript . Attaching the code which I tried
<head>
<link href="https://vjs.zencdn.net/7.11.4/video-js.css" rel="stylesheet" />
<!-- If you'd like to support IE8 (for Video.js versions prior to v7) -->
<!-- <script src="https://vjs.zencdn.net/ie8/1.1.2/videojs-ie8.min.js"></script> --
>
</head>
<body onLoad='getVersion()'>
<video
id="my-video"
class="video-js"
controls
preload="auto"
width="640"
height="264"
poster="MY_VIDEO_POSTER.jpg"
data-setup="{}"
>
<source src="MY_VIDEO.mp4" type="video/mp4" />
<source src="MY_VIDEO.webm" type="video/webm" />
<p class="vjs-no-js">
To view this video please enable JavaScript, and consider upgrading to a
web browser that
<a href="https://videojs.com/html5-video-support/" target="_blank"
>supports HTML5 video</a
>
</p>
<script>
function getVersion(){
console.log("videojs version : " + videojs.VERSION);
var player = videojs('video');
// Play through the playlist automatically.
player.playlist.autoadvance(0);
}
</script>
</body>
In the above code when im trying to call var player = videojs('video'); I am getting the exception
Upvotes: 0
Views: 1983
Reputation: 4419
According to the documentation you need these two lines at the top of your file to import videojs
.
<link href="https://vjs.zencdn.net/7.11.4/video-js.css" rel="stylesheet"/>
<script src="https://vjs.zencdn.net/7.11.4/video.min.js"></script>
console.log(videojs !== undefined)
console.log({"version": videojs.VERSION})
<head>
<link href="https://vjs.zencdn.net/7.11.4/video-js.css" rel="stylesheet" />
<script src="https://vjs.zencdn.net/7.11.4/video.min.js"></script>
</head>
Upvotes: 1