npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

videojs-quality-picker

v0.0.3

Published

Adds quality picker menus to video.js which allows users to perform manual quality selection for multi-bitrate video, or multi-language audio / subtitles.

Downloads

116

Readme

Video.js quality picker

Adds quality picker menus to video.js which allows users to perform manual quality selection for multi-bitrate video, or multi-language audio / subtitles.

NOTE: In this project, quality can refer to:

  • a specific video / audio bitrate (or auto selection)
  • a specific audio / subtitle language (or disabled subtitles)

Installation

Plugin works with video.js 5.0 and newer.

Use grunt build̀to build the dist scripts.

Make a tech / source handler compatible

How it works

The plugin listens to the custom event loadedqualitydata fired by player's tech / source handler.

The tech must:

  • Get the quality list from the underlying playback technology
  • Format the quality list to the format given below
  • Implement a callback function for the click action on the quality picker
  • Trigger a custom tech event loadedqualitydata, with a payload which format is described below

Expected format

Here is expected payload structure:

{
  qualityData: {
    video: [ Quality ], // An array of Quality objects, as defined below
    audio: [ Quality ],
    subtitle: [ Quality ]
  },
  qualitySwitchCallback: Function // callback function used for quality switching, as defined below
}

NOTES:

  • In the following, track type refers to the enum: "video" | "audio" | "subtitle".
  • it's not mandatory to pass an array of Quality for every track type, it can be undefined. No quality picker button will be added for this track type.
  • If the length of a Quality array is <= 1, no quality picker button will be added for its track type.

qualitySwitchCallback

qualitySwitchCallback(qualityId, trackType)

This callback function will be called with the Quality id and the the track type as arguments. Its role is to effectively perform the quality change on the player

Quality

Examples
{
  id: -1,
  label: 'auto',
  selected: true
}
{
  id: { adaptationSetId: 0, representationId: 2},
  label: '720p',
  selected: false
}
Properties

property | type |description ------------|-------|----------------------------------- id | Any | Unique identifier for the quality. Can be an integer (level index for HLS), or an object ( {adaptationSetId: ..., representationId: ...} for Dash) . label | String | The text that will be displayed to identify this quality in the drop down menu selected | Boolean | Should be true for ONE quality ONLY: the one that is currently played by the player

Hls.js Example


    // hls.js init
    var hls = new Hls(config);
    hls.on(Hls.Events.MANIFEST_PARSED, onManifestParsed); // Listen to the event MANIFEST_PARSED, to get the quality list.

    hls.loadSource(url);
    hls.attachMedia(video);

    //...
    //...
    //...


    // Callback function
    function switchQuality(qualityId, trackType) {
        hls.nextLevel = qualityId; // Perform quality switch using hls.js API
    }

    function onManifestParsed(event, data) {
        // 1. Format payload
        var cleanTracklist = [];

        // Add an "auto" quality.
        if (data.levels.length > 1) {
            var autoLevel = {
                id: -1,
                label: "auto",
                selected: -1 === hls.manualLevel
            };
            cleanTracklist.push(autoLevel);
        }

        // Format each hls level into the expected "Quality" format
        data.levels.forEach(function(level, index) {
            var quality = {}; // Don't write in level (shared reference with Hls.js)
            quality.id = index;
            quality.selected = index === hls.manualLevel;
            quality.label = _levelLabel(level);

            cleanTracklist.push(quality);
        });

        var payload = {
            qualityData: {video: cleanTracklist},
            qualitySwitchCallback: switchQuality
        };

        // 2. Trigger custom event from tech
        tech.trigger('loadedqualitydata', payload);

        // Helper method used to format the Quality's label
        function _levelLabel(level) {
            if (level.height) return level.height + "p";
            else if (level.width) return Math.round(level.width * 9 / 16) + "p";
            else if (level.bitrate) return (level.bitrate / 1000) + "kbps";
            else return 0;
        }
    }