4.1.0 • Published 1 month ago

videojs-contrib-quality-levels v4.1.0

Weekly downloads
36,648
License
Apache-2.0
Repository
github
Last release
1 month ago

videojs-contrib-quality-levels

Build Status Greenkeeper badge Slack Status

NPM

A plugin that provides a framework of working with source quality levels.

Maintenance Status: Stable

Installation

Installation

npm install --save videojs-contrib-quality-levels

The npm installation is preferred, but Bower works, too.

bower install  --save videojs-contrib-quality-levels

Using

The list of QualityLevels can be accessed using qualityLevels() on the Player object. With this list, you can:

  • See which quality levels are available for the current source
  • Enable or disable specific quality levels to change which levels are selected by ABR
  • See which quality level is currently selected by ABR
  • Detect when the selected quality level changes

Example

let player = videojs('my-video');

let qualityLevels = player.qualityLevels();

// disable quality levels with less than 720 horizontal lines of resolution when added
// to the list.
qualityLevels.on('addqualitylevel', function(event) {
  let qualityLevel = event.qualityLevel;

  if (qualityLevel.height >= 720) {
    qualityLevel.enabled = true;
  } else {
    qualityLevel.enabled = false;
  }
});

// example function that will toggle quality levels between SD and HD, defining and HD
// quality as having 720 horizontal lines of resolution or more
let toggleQuality = (function() {
  let enable720 = true;

  return function() {
    for (let qualityLevel of qualityLevels) {
      if (qualityLevel.height >= 720) {
        qualityLevel.enabled = enable720;
      } else {
        qualityLevel.enabled = !enable720;
      }
    }
    enable720 = !enable720;
  };
})();

let currentSelectedQualityLevelIndex = qualityLevels.selectedIndex; // -1 if no level selected

// Listen to change events for when the player selects a new quality level
qualityLevels.on('change', function() {
  console.log('Quality Level changed!');
  console.log('New level:', qualityLevels[qualityLevels.selectedIndex]);
});

Supporting Quality Levels for your source

This project provides the framework for working with source quality levels. Just including this project alongside videojs does not necessarily mean that there will be levels available in the list or that any events will be triggered. Some projects within the videojs org supports this project and automatically populates the list and triggers change events when the selected quality level changes. See the Supported Projects section for a list of these projects.

If you are not using one of the supported projects, but still want to use quality levels with your source, you will have to implement your own plugin that populates the list and triggers change events when selected level changes. Implementing such a plugin is very specific to the source in question, so it is difficult to provide specific examples, but will most likely require a custom middleware, source handler, or tech.

Populating the list

Initially the list of quality levels will be empty. You can add quality levels to the list by using QualityLevelList.addQualityLevel for each quality level specific to your source. QualityLevelList.addQualityLevel takes in a Representation object (or generic object with the required properties). All properties are required except width, height and frameRate.

Example Representation

Representation {
  id: string,
  width: number,
  height: number,
  bitrate: number,
  frameRate: number,
  enabled: function
}

The enabled function should take an optional boolean to enable or disable the representation and return whether it is currently enabled.

You can also remove quality levels from the list using QualityLevelList.removeQualityLevel. Call this function with the reference to the QualityLevel object you wish to remove. The QualityLevelList.selectedIndex property will automatically be updated when a quality level is removed so that it still refers to the correct level. If the currently selected level is removed, the selectedIndex will be set to -1.

Triggering the 'change' event

When your playback plugin changes the selected quality for playback, you will also have to trigger the change event on the QualityLevelList and update the QualityLevelList.selectedIndex_, as it does not have knowledge of which quality is active in playback.

let player = videojs('my-video');

let qualityLevels = player.qualityLevels();

qualityLevels.selectedIndex_ = 0;
qualityLevels.trigger({ type: 'change', selectedIndex: 0 });

Supported Projects

The following projects have built-in support for videojs-contrib-quality-levels and will automatically populate the list with available levels and trigger change events when the quality level changes.

Including the Plugin

To include videojs-contrib-quality-levels on your website or web application, use any of the following methods.

<script> Tag

This is the simplest case. Get the script in whatever way you prefer and include the plugin after you include video.js, so that the videojs global is available.

<script src="//path/to/video.min.js"></script>
<script src="//path/to/videojs-contrib-quality-levels.min.js"></script>
<script>
  var player = videojs('my-video');

  player.qualityLevels();
</script>

Browserify

When using with Browserify, install videojs-contrib-quality-levels via npm and require the plugin as you would any other module.

var videojs = require('video.js');

// The actual plugin function is exported by this module, but it is also
// attached to the `Player.prototype`; so, there is no need to assign it
// to a variable.
require('videojs-contrib-quality-levels');

var player = videojs('my-video');

player.qualityLevels();

RequireJS/AMD

When using with RequireJS (or another AMD library), get the script in whatever way you prefer and require the plugin as you normally would:

require(['video.js', 'videojs-contrib-quality-levels'], function(videojs) {
  var player = videojs('my-video');

  player.qualityLevels();
});

License

Apache-2.0. Copyright (c) Brightcove, Inc.

@applicaster/zapp-react-dom-app@applicaster/zapp-react-native-default-player@mediafly/playback-componentanghamimediaengineloco-playerworkspace-appfarakav-hls-quality-selectorvideojs-dash-hls-bitrate-switcherreact-m3u8-playerbtv-video-player@infinitebrahmanuniverse/nolb-vide@everything-registry/sub-chunk-3053@nimeshjohri/webplayer-sdkdm-standard@mtonomy/videojs-source-selectorwebplayer-sdkhamrah-playeriztech-design-system-neovideojs-extra-buttonsvideojs-hls-source-selectorvideojs-hlsjs-quality-selectorvideojs-http-source-selectorvideojs-http-source-selector-2videojs-http-source-selector-8vvideojs-http-source-selector-mutevidibo-playervideojs-yt-stylevideo.jshoast360vooliom-playervideojs-selector-quality-hlsvideojs-quality-selector-hlsvideojs-quality-selector-hls-customm3u8-react-player@marketplace-co/react-application-element-video-player@marketplaces.inc-ui/dependency-video.js@litomore/videojs-hls-quality-selector@hartmflo86/videojs-hls-quality-selectorlhwplayerlion-playerlivepeer-player@mux/videojs-kit@mycujoo/mcls-player@mycujoo/videojs-hls-quality-selector@moltencloud/videojs-quality-selector@mtonomy/videojs-quality-selector@riversilica_narendra/videojs-contrib-quality-levels-2.2.1@riversilica_narendra/webapp@mlytics/p2sp-sdk@pulpo/components@eban5/videojs-hls-quality-selector@s3bubble/player@s3bubble/videojs-s3bubble-bitrate-switcher@s3bubble/videojs-s3bubble-settings-menu@filmgardi/aparat@filmgardi/phoenix-video-player@firescar96/videojs-quality-selector@samueleastdev/videojs-dash-hls-bitrate-switcher@samueleastdev/videojs-settings-menu@saooti/octopus-sdk@antmedia/web_player@applicaster/quick-brick-player@vipstorage/video.js@twogate/player-core@twogate/stencil-player-core@toth.adam.straxus/videojs-hls-quality-selector@shrijal/video.js@shashank8317/webapp-projectrobeeerto-videojs-hls-quality-selectoralm-video-player-testsunbird-video-player-appcomm-side-paneldraken-playertk-playerbccm-video-player@camtv/video-playerbelive-lib-testbelive-core-componentbelive-core-componentsbi-core-componentsbi-live-libsbi-live-libs-testbi-testing@cmarasani/videojs-hls-quality-selectortingtingan-videojs-hls-quality-selectordeepmovie
4.1.0

1 month ago

4.0.0

1 year ago

3.0.0

1 year ago

2.2.1

1 year ago

2.2.0

2 years ago

2.1.0

3 years ago

2.0.9

6 years ago

2.0.8

6 years ago

2.0.7

6 years ago

2.0.6

6 years ago

2.0.5

6 years ago

2.0.4

6 years ago

2.0.3

7 years ago

2.0.2

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.0.0

7 years ago