video.js HLS Source Handler
Adds HLS playback support to video.js 5.0+ using hls.js library.
Installation
A pre-built version is available: https://cdn.streamroot.io/videojs-hlsjs-plugin/1/stable/videojs-hlsjs-plugin.js
Manually build the plugin
Clone the repository.
Install the dependcies npm install
.
Use npm run build
to build the dist scripts.
Usage
CDN
Include video.js and videojs-hlsjs-plugin.js in your page:
There are several ways of getting video.js files, you can read about them in official documentation and choose the one that match your needs best.
NPM
const videojs = ;const videojsHlsjsSourceHandler = ; videojsHlsjsSourceHandler;
Passing configuration options to hls.js
Define hlsjsConfig
property in html5
field of video.js options object and pass it as second param to videojs constructor. List of available hls.js options is here:
<script> var options = html5: hlsjsConfig: debug: true ; var player = ;</script>
Initialization Hook
Sometimes you may need to extend hls.js, or have access to the hls.js before playback starts. For these cases, you can register a function to the beforeinitialize
hook, which will be called right after hls.js instance is created.
Your function should have two parameters:
- The video.js Player instance
- The hls.js instance
var { // do something}; videojsHtml5Hlsjs;
You can remove the hook by:
videojsHtml5Hlsjs;
You can add as many beforeinitialize
hooks as necessary by calling videojs.Html5Hlsjs.addHook
several times.