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

player-chrome

v0.0.3

Published

Custom elements (web components) for making audio and video player controls that look great in your website or app.

Downloads

10

Readme

<player-chrome>

Custom elements (web components) for building audio and video player controls.

From Mux and the creator of Video.js.

Why?

We often put a lot of effort into making our form buttons and navigation elements look uniquely beautiful, but then use generic, default media player controls...because it's hard not to.

  • Web browsers have built-in player controls that can't easily be customized and look different in every browser.
  • Social sites like Youtube, Vimeo, and SoundCloud only let you customize small details of the player, like primary button color.
  • Player controls are complex and hard to build from scratch. Open source players like Video.js and JW Player help, but require you to learn proprietary JS APIs, and can be difficult to use with popular Javascript frameworks.

It should be easier... <player-chrome> is an attempt at solving that.

Why now?

Web components. @heff spoke about the potential of web components for video at Demuxed 2015. They allow us to extend the browser's base HTML functionality, meaning we can now build player controls as simple HTML tags that:

  • Can be used like any native HTML tag in HTML, Javascript, and CSS (unleash your designer)
  • Are compatible by default with Javascript frameworks (React, Angular, Stencil)
  • Can be used across players when using multiple in the same site, e.g Youtube & <video>. (Could even be used by players as their own built-in controls)

Quick Demos

Adding controls to a player

Just HTML. No javascripting required.

Add controls to the player

Moving the progress bar above the controls

Simple HTML and CSS.

Moving the playback progress bar

Example players matching the website context

Installing <player-chrome> and other elements

<player-chrome> is packaged as a javascript module (es6) only, which is supported by all evergreen browsers and Node v12+. It includes all of the other player controls with it, like <player-play-button>.

Adding to your website/app using <script>

Load the module in the <head> of your HTML page. Note the type="module", that's important.

Modules are always loaded asynchronously by the browser, so it's ok to load them in the head :thumbsup:, and best for registering web components quickly.

<head>
  <script type="module" src="https://unpkg.com/player-chrome"></script>
</head>

Adding to your app via npm

npm install player-chrome --save

Or yarn

yarn add player-chrome

Include in your app javascript (e.g. src/App.js)

import 'player-chrome';

This will register the custom elements with the browser so they can be used as HTML.

Using in your HTML

Wrap your HTML media element in the <player-chrome> tag. Include the defaultControls attribute to turn on basic controls.

Add a slot="media" attribute to your media element and remove any controls attribute or you'll have double controls.

<player-chrome defaultControls>
  <video
    slot="media"
    src="https://file-examples.com/wp-content/uploads/2017/04/file_example_MP4_480_1_5MG.mp4"
  >
  </video>
</player-chrome>

Customizing the controls

To customize player-chrome, remove the defaultControls attribute and use the included control elements to add only the controls you want and in whatever order you want.

<player-chrome>
  <video
    slot="media"
    src="https://file-examples.com/wp-content/uploads/2017/04/file_example_MP4_480_1_5MG.mp4"
  ></video>
  <player-control-bar>
    <player-play-button>Play</player-play-button>
    <player-mute-button>Mute</player-mute-button>
    <player-volume-range>Volume</player-volume-range>
    <player-progress-range>Progress</player-progress-range>
    <player-pip-button>PIP</player-pip-button>
    <player-fullscreen-button>Fullscreen</player-fullscreen-button>
  </player-control-bar>
</player-chrome>

You can then use CSS to style the controls.

Using <player-chrome> with specific players

  • <video>
  • <audio>
  • HLS.js
  • Video.js
  • JW Player
  • Youtube

HLS.js

For HLS.js we've created a custom element that acts just like a <video> element but has HLS.js baked in.

  1. Load the HLS.js custom element before player-chrome, so that the tag is already defined when player-chrome loads.
<script type="module" src="./js/hls-video-element.js"></script>
<script type="module" src="./js/player-chrome.js"></script>
  1. Use <hls-video> in place of <video>, and use a m3u8(HLS) file as the source.
<player-chrome defaultControls>
  <hls-video
    slot="media"
    src="https://playertest.longtailvideo.com/adaptive/captions/playlist.m3u8"
  >
  </hls-video>
</player-chrome>

Using <player-chrome> with javascript frameworks

  • React...
  • View...
  • Angular...