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

@mux/videojs-kit

v0.12.0

Published

The Video.js you know and love but optimized for using with Mux. The base is slimmed down a bit, then there are a few plugins included, namely Mux Data, and uses hls.js as the HLS playback engine. This is due to some issues we've seen with the default Vid

Downloads

19,763

Readme

Video.js + Mux Kit

The Video.js you know and love but optimized for using with Mux. The base is slimmed down a bit, then there are a few plugins included, namely Mux Data, and uses hls.js as the HLS playback engine. This is due to some issues we've seen with the default Video.js playback engine and Mux streams.

This project is now also set up to allow usage with Video.js's playback engine VHS (Video.js HTTP Streaming). See how to include that in your project below.

Installation

// npm
npm install @mux/videojs-kit

// yarn
yarn add @mux/videojs-kit

If you don't use a package manager such as NPM, there are hosted versions provided by unpkg.com too.

Including videojs-mux-kit in your project

Importing

If you use a package manager such as NPM, import the JavaScript and CSS in your application like this:

Default (hls.js)

// include the video.js kit javascript and css
import videojs from '@mux/videojs-kit';
import '@mux/videojs-kit/dist/index.css';  

VHS

// include the video.js kit javascript and css
import videojs from '@mux/videojs-kit/dist/index.vhs.js';
import '@mux/videojs-kit/dist/index.css';

<script> tags

If you'd rather use the hosted versions, include this in your HTML page:

Default (hls.js)

// script tags
<script src="https://unpkg.com/@mux/[email protected]/dist/index.js"></script>
<link rel="stylesheet" href="https://unpkg.com/@mux/[email protected]/dist/index.css">

VHS

// script tags
<script src="https://unpkg.com/@mux/[email protected]/dist/index.vhs.js"></script>
<link rel="stylesheet" href="https://unpkg.com/@mux/[email protected]/dist/index.css">

Usage

In the below examples, replace the src attribute example to reflect the playback ID of your choosing.

Then, on your page include a <video> element where you want to add your player.

<video
  id="mux-default"
  class="video-js vjs-16-9"
  controls
  preload="auto"
  width="100%"
  poster="https://image.mux.com/DS00Spx1CV902MCtPj5WknGlR102V5HFkDe/thumbnail.jpg"
  data-setup='{
    "timelineHoverPreviews": true,
    "plugins": {
      "mux": {
        "data": {
          "env_key": "ENV_KEY",
          "video_title": "My Great Video"
        }
      }
    }
  }'
>
  <source src="DS00Spx1CV902MCtPj5WknGlR102V5HFkDe" type="video/mux" />
</video>

Of course, you can also initialize all of this via JS as well:

<video
  id="mux-default"
  class="video-js vjs-16-9"
  controls
  preload="auto"
  width="100%"
  poster="https://image.mux.com/DS00Spx1CV902MCtPj5WknGlR102V5HFkDe/thumbnail.jpg"
/>

<script type="text/javascript">
  const player = videojs('mux-default', {
    "timelineHoverPreviews": true,
    "plugins": {
      "mux": {
        "data": {
          "env_key": "ENV_KEY",
          "video_title": "My Great Video"
        }
      }
    }
  });

  player.src({ type: 'video/mux', src: 'DS00Spx1CV902MCtPj5WknGlR102V5HFkDe' });
</script>

Quality Levels

A plugin for a quality levels menu is now included by default, however, it is not enabled by default. To enable quality levels, you'll want to either specify it in the plugins object, like above, or call the method directly on the player:

<video
  id="mux-default"
  class="video-js vjs-16-9"
  controls
  preload="auto"
  width="100%"
  poster="https://image.mux.com/DS00Spx1CV902MCtPj5WknGlR102V5HFkDe/thumbnail.jpg"
  data-setup='{
    "timelineHoverPreviews": true,
    "plugins": {
      "mux": {
        "data": {
          "env_key": "ENV_KEY",
          "video_title": "My Great Video"
        }
      },
      "httpSourceSelector": {}
    }
  }'
>
  <source src="DS00Spx1CV902MCtPj5WknGlR102V5HFkDe" type="video/mux" />
</video>
const player = videojs.getPlayer('mux-default');
player.httpSourceSelector();

Custom Domains

By default, all Mux Video assets will be hosted on mux.com. This includes things like posters, storyboards, and media sources.

Custom Domains, is a feature which allows you to stream these assets from a domain of your choice.

Once you have your custom domain set up, provide it via the customDomain property. If your custom domain is media.example.com then internally videojs-mux-kit will take that value and expand it to image.media.example.com for images and stream.media.example.com for video. The only exception is the poster property in which you will need to provide the fully qualified url.

Example with the HTML element:

<video id="mux-custom-domain" class="video-js vjs-16-9" controls preload="auto"
  poster="https://image.media.heymux.com/Kn00wAAUmt3MPOeFlmuAeS4qSIW41v5Ixg5fQ00YuCX400/thumbnail.jpg" data-setup='{
    "customDomain": "media.heymux.com",
    "timelineHoverPreviews": true
  }'
>
  <source src="Kn00wAAUmt3MPOeFlmuAeS4qSIW41v5Ixg5fQ00YuCX400" type="video/mux" />
</video>

I'm importing another plugin but it isn't available when I test in the browser

This is because most Video.js plugins depend directly on Video.js but by default Video.js Mux Kit uses hls.js by default and to maintain a smaller file-size we use Video.js's core build which excludes VHS. You shouldn't need to do this if you're using the VHS build

This means that the Video.js that is used by Video.js Mux Kit references video.js/core instead of video.js. To get plugins to work, you'll need to make sure that plugins are also loading in video.js/core instead of only video.js. Most bundlers have some way of configuring these type of aliases.

For webpack, you can use the resolve configuration option:

config.resolve = {
  alias: {
    'video.js': 'video.js/core',
  }
};

This is how Video.js Mux Kit builds out the hls.js and VHS builds internally, see our webpack config.

For rollup, you'll want to grab their alias plugin, and then configure it into the plugins array like so:

module.exports = {
  input: 'src/index.js',
  output: {
    dir: 'output',
    format: 'cjs'
  },
  plugins: [
    alias({
      entries: [
        { find: 'video.js', replacement: require.resolve('video.js/core') }
      ]
    })
  ]
};

Demos

Also, the demos are a great place to more references! In general, you can expect this to work almost exactly like Video.js + Mux Data with a few extra niceties. Mux streams can be specified by simply including the playback ID as the src, and video/mux as the type.

To run the demos, you can run npm run dev or npm run dev:vhs for running with VHS. Once the dev server is running, open http://localhost:8080/{file} with {file} being one the demos like basic.html or data.html.