HLS library for video.js
[![Build Status][travis-icon]][travis-link] [![Slack Status][slack-icon]][slack-link] [![Greenkeeper badge][greenkeeper-icon]][greenkeeper-link]
Play back HLS with video.js, even where it's not natively supported.
Maintenance Status: Deprecated
Table of Contents generated with DocToc
To install videojs-contrib-hls with npm run
npm install --save videojs-contrib-hlsSelect a version of HLS from cdnjs or jsDelivr
Download a release of videojs-contrib-hls
Download a copy of this git repository and then follow the steps in Building
See CONTRIBUTING.md
Drop by our slack channel (#playback) on the [Video.js slack][slack-link].
Get a copy of videojs-contrib-hls and include it in your page along with video.js:
<video id=example-video width=600 height=300 class="video-js vjs-default-skin" controls>
<source
src="https://example.com/index.m3u8"
type="application/x-mpegURL">
</video>
<script src="video.js"></script>
<script src="videojs-contrib-hls.min.js"></script>
<script>
var player = videojs('example-video');
player.play();
</script>Check out our live example if you're having trouble.
With Video.js 6, by default there is no flash support. Instead, flash support is provided through the videojs-flash plugin. If you are trying to use Video.js version 6 and want to include flash support, you must include videojs-flash on your page before including videojs-contrib-hls
<script src="https://unpkg.com/videojs-flash/dist/videojs-flash.js"></script>
<script src="https://unpkg.com/videojs-contrib-hls/dist/videojs-contrib-hls.js"></script>Flash, and the videojs-flash plugin, are not required, but are recommended as a fallback option for browsers that don't have a native HLS player or support for Media Source Extensions.
HTTP Live Streaming (HLS) has become a de-facto standard for streaming video on mobile devices thanks to its native support on iOS and Android. There are a number of reasons independent of platform to recommend the format, though:
Unfortunately, all the major desktop browsers except for Safari are missing HLS support. That leaves web developers in the unfortunate position of having to maintain alternate renditions of the same video and potentially having to forego HTML-based video entirely to provide the best desktop viewing experience.
This project addresses that situation by providing a polyfill for HLS on browsers that have support for Media Source Extensions, or failing that, support Flash. You can deploy a single HLS stream, code against the regular HTML5 video APIs, and create a fast, high-quality video experience across all the big web device categories.
Check out the full documentation for details on how HLS works and advanced configuration. A description of the adaptive switching behavior is available, too.
videojs-contrib-hls supports a bunch of HLS features. Here are some highlights:
You may pass in an options object to the hls source handler at player initialization. You can pass in options just like you would for other parts of video.js:
// html5 for html hls
videojs(video, {html5: {
hls: {
withCredentials: true
}
}});
// or
// flash for flash hls
videojs(video, {flash: {
hls: {
withCredentials: true
}
}});
// or
var options = {hls: {
withCredentials: true
}};
videojs(video, {flash: options, html5: options});
Some options, such as withCredentials can be passed in to hls during
player.src
var player = videojs('some-video-id');
player.src({
src: 'https://d2zihajmogu5jn.cloudfront.net/bipbop-advanced/bipbop_16x9_variant.m3u8',
type: 'application/x-mpegURL',
withCredentials: true
});booleanWhen the withCredentials property is set to true, all XHR requests for
manifests and segments would have withCredentials set to true as well. This
enables storing and passing cookies from the server that the manifests and
segments live on. This has some implications on CORS because when set, the
Access-Control-Allow-Origin header cannot be set to *, also, the response
headers require the addition of Access-Control-Allow-Credentials header which
is set to true.
See html5rocks's article
for more info.
booleanfalseWhen the handleManifestRedirects property is set to true, manifest requests
which are redirected will have their URL updated to the new URL for future
requests.
booleanWhen the useCueTags property is set to true, a text track is created with
label 'ad-cues' and kind 'metadata'. The track is then added to
player.textTracks(). Changes in active cue may be
tracked by following the Video.js cue points API for text tracks. For example:
let textTracks = player.textTracks();
let cuesTrack;
for (let i = 0; i < textTracks.length; i++) {
if (textTracks[i].label === 'ad-cues') {
cuesTrack = textTracks[i];
}
}
cuesTrack.addEventListener('cuechange', function() {
let activeCues = cuesTrack.activeCues;
for (let i = 0; i < activeCues.length; i++) {
let activeCue = activeCues[i];
console.log('Cue runs from ' + activeCue.startTime +
' to ' + activeCue.endTime);
}
});booleanTry to use videojs-contrib-hls even on platforms that provide some
level of HLS support natively. There are a number of platforms that
technically play back HLS content but aren't very reliable or are
missing features like CEA-608 captions support. When overrideNative
is true, if the platform supports Media Source Extensions
videojs-contrib-hls will take over HLS playback to provide a more
consistent experience.
NOTE: If you use this option, you must also set
videojs.options.html5.nativeAudioTracks and
videojs.options.html5.nativeVideoTracks to
false. videojs-contrib-hls relies on audio and video tracks to play
streams with alternate audio and requires additional capabilities only
supported by non-native tracks in video.js.
numberWhen the blacklistDuration property is set to a time duration in seconds,
if a playlist is blacklisted, it will be blacklisted for a period of that
customized duration. This enables the blacklist duration to be configured
by the user.
numberWhen the bandwidth property is set (bits per second), it will be used in
the calculation for initial playlist selection, before more bandwidth
information is seen by the player.
booleanWhen enableLowInitialPlaylist is set to true, it will be used to select
the lowest bitrate playlist initially. This helps to decrease playback start time.
This setting is false by default.
Runtime properties are attached to the tech object when HLS is in use. You can get a reference to the HLS source handler like this:
var hls = player.tech({ IWillNotUseThisInPlugins: true }).hls;If you were thinking about modifying runtime properties in a video.js plugin, we'd recommend you avoid it. Your plugin won't work with videos that don't use videojs-contrib-hls and the best plugins work across all the media types that video.js supports. If you're deploying videojs-contrib-hls on your own website and want to make a couple tweaks though, go for it!
Type: object
An object representing the parsed master playlist. If a media playlist is loaded directly, a master playlist with only one entry will be created.
Type: `functi
No open issues yet, or sync has not completed.