Video.js HTTP Source Selector Plugin
raw JSON →This Video.js plugin, currently at version 1.1.6, provides a user interface for manual quality level selection in adaptive HTTP streams (HLS/DASH). It is built upon and explicitly requires the `videojs-contrib-quality-levels` plugin to parse and manage the stream's available quality levels. The plugin dynamically generates labels for these levels, prioritizing stream `height` metadata and falling back to `bitrate` when height is unavailable. It is compatible with Video.js versions 7 and higher. While the project appears to be in a maintenance state with no recent releases or significant code commits in the past few years, it remains functional for its intended purpose within compatible Video.js environments. Its primary utility is to offer a direct, user-friendly way to switch stream qualities, enhancing user control over adaptive streaming playback.
Common errors
error TypeError: player.httpSourceSelector is not a function ↓
video.js, videojs-contrib-quality-levels, and then videojs-http-source-selector are loaded in the correct sequence. For module bundlers, verify the require() or import order. For <script> tags, confirm their placement in the HTML. error Uncaught ReferenceError: videojs is not defined ↓
video.js is loaded and globally accessible before any Video.js plugins. Check your <script> tag order or module bundling configuration to ensure video.js is the first dependency. error Uncaught TypeError: Cannot read properties of undefined (reading 'qualityLevels') ↓
videojs-contrib-quality-levels is installed and loaded *before* videojs-http-source-selector. Ensure that the qualityLevels() method is callable on your videojs player instance before the http source selector tries to use it. Warnings
breaking This plugin is officially compatible only with Video.js version 7 and above. Using it with older versions of Video.js (prior to v7) may lead to API incompatibilities, unexpected behavior, or runtime errors. ↓
gotcha This plugin has a mandatory peer dependency on `videojs-contrib-quality-levels`. If `videojs-contrib-quality-levels` is not installed and loaded *before* `videojs-http-source-selector`, the plugin will fail to initialize correctly and the source selector UI will not appear. ↓
gotcha Quality level labels displayed in the selector menu are primarily generated from the `height` metadata available in the stream's `QualityLevels` sources. If `height` information is missing from your stream's manifest, labels will default to using `bitrate` values, which might be less intuitive for end-users. ↓
gotcha The `default` option (`'auto'`, `'low'`, `'high'`) within the `httpSourceSelector` plugin settings dictates the initial quality selection. If `default: 'auto'` is used, the player typically starts at the highest available quality then adapts, which may not be desired for all use cases. Misunderstanding this behavior can lead to unexpected initial playback quality. ↓
Install
npm install videojs-http-source-selector yarn add videojs-http-source-selector pnpm add videojs-http-source-selector Imports
- videojs wrong
const videojs = require('video.js/dist/video.min.js');correctimport videojs from 'video.js'; - videojs-http-source-selector wrong
import { httpSourceSelector } from 'videojs-http-source-selector';correctrequire('videojs-http-source-selector'); - Player#httpSourceSelector()
player.httpSourceSelector(options);
Quickstart
<!-- HTML structure for the video player -->
<video id="my-video-element-id" class="video-js vjs-default-skin" controls preload="auto" width="640" height="360">
<!-- Replace with an actual HLS/DASH stream -->
<source src="https://example.com/path/to/my-hls-stream.m3u8" type="application/x-mpegURL">
</video>
<script src="https://unpkg.com/video.js@7/dist/video.min.js"></script>
<script src="https://unpkg.com/videojs-contrib-quality-levels/dist/videojs-contrib-quality-levels.min.js"></script>
<script src="https://unpkg.com/videojs-http-source-selector/dist/videojs-http-source-selector.min.js"></script>
<script type="text/javascript">
// Initialize a Video.js player with the httpSourceSelector plugin options
const player = videojs('my-video-element-id', {
controls: true,
autoplay: false,
preload: 'auto',
// Configure the httpSourceSelector plugin with a default option
plugins: {
httpSourceSelector: {
default: 'auto' // Options: 'auto', 'low', 'high'
}
}
});
// Explicitly initialize the plugin on the player instance.
// This step is often implicitly handled if configured in 'plugins' during player init.
player.httpSourceSelector();
player.on('ready', function() {
console.log('Video.js player is ready with HTTP Source Selector!');
// You can programmatically access quality levels if needed
// const qualityLevels = player.qualityLevels();
// console.log('Available quality levels:', qualityLevels.levels);
});
player.on('error', function() {
console.error('Video.js player error:', player.error());
});
</script>