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

tplayer.js

v1.1.0

Published

Flexible and easy Dash/HLS/DRM integration for HTML5 video.

Downloads

13

Readme

tplayer logo

This project is made possible with Plyr, Hls.js, Dash.js.

Features 📑

  • HLS and DASH playback 🎥
  • Multi quality supported 🎬
  • Drm with custom header support (Widevine & Playready) 🔐
  • Customizable UI ⛏
  • Active development 🧱

Setup and Usage 📚

tplayer.js requires a video element in the DOM.

HTML

See example

  1. Put the tplayer.js script tag in the <head> of your HTML document.

    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/index.js"></script>
  2. Put the video element in the <body> of your HTML document.

    <video id="tplayer"></video>
  3. Add some JS to the <body> of your HTML document.

    <script>
      window.tplayer(options);
    </script>

NEXTJS

See example

You need to import tplayer.js into a component which will be dynamically imported (No SSR) to your root.

# Install tplayer.js
npm install tplayer.js
// component\player.jsx

import { useRef, useEffect } from "react";
import { tplayer, destroyPlayer } from "tplayer.js";

export default function Player({ config }) {
  const videoRef = useRef();

  useEffect(() => {
    tplayer({
      ...config,
      playerElem: videoRef.current,
    });

    return () => destroyPlayer({ id: config.id });
  }, []);

  return (
    <div>
      <video ref={videoRef}></video>
    </div>
  );
}
// pages\index.jsx

import dynamic from "next/dynamic";
const Player = dynamic(import("../component/player"), { ssr: false });

export default function Home() {
  return <Player config={options} />;
}

Options 📝

| Name | Description | Default / Requirement / Fallback | Example | | ------------------------ | ------------------------------------ | ---------------------------------------- | --------------------------------------------------------------------- | | id | This is the tplayer.js instance id | Default: tplayer | 'tplayerhtml' | | playerElem | Video element from DOM | Required | document.getElementById("tplayer") | | source | Source Object | At least one DASH or HLS URL is required | {dash:'some.mpd', hls: 'some.m3u8'} | | source.dash | MPD URL of your source file | Required if DRM enabled | https://some.mpd | | source.hls | M3U8 URL of your source file | Not required if Dash is provided | https://some.m3u8 | | sourceHeaders.dash | Additional XHR headers for Dash | Optional | {"some": "header"} | | sourceHeaders.hls | Additional XHR headers for hls | Optional | {"some": "header"} | | drm | DRM Object | Optional | {widevine: {url: '', headers: {}}, playready: {url: '', headers: {}}} | | drm.widevine | Widevine Object | Optional | widevine: {url: '', headers: {}} | | drm.widevine.url | Widevine license URL | Required | https://some/proxy | | drm.widevine.headers | Headers object for license requests | Optional | {"T-Header-One": "Hi", "T-Header-Two": "Hello"} | | drm.playready | Playready Object | Optional | playready: {url: '', headers: {}} | | drm.playready.url | Playready license URL | Required | https://some.asmx | | drm.playready.headers | Headers object for license requests | Optional | {"T-Header-One": "Hi", "T-Header-Two": "Hello"} | | ui | Extended UI Object | Optional | {mainColor: '#ff002b'} | | ui.mainColor | Main color | Optional | #ff002b | | captions | WebVTT Captions array | Optional | [{label: "", src: "", language: ""}] | | captions[index].label | Caption label | Optional | "English" | | captions[index].src | Caption source URL | Required | https://some.vtt | | captions[index].language | Caption language | Optional | "en" |

See this example

const options = {
  id: "tplayerhtml", // anything
  playerElem: document.getElementById("tplayer"), // grabbing the video element from the DOM
  source: {
    dash: "https://bitmovin-a.akamaihd.net/content/art-of-motion_drm/mpds/11331.mpd",
    hls: "https://bitmovin-a.akamaihd.net/content/art-of-motion_drm/m3u8s/11331.m3u8",
  },
  sourceHeaders: {
    dash: {
      // "T-Header": "You can send header like this",
    },
    hls: {
      // "T-Header": "You can send header like this",
    },
  },
  drm: {
    widevine: {
      url: "https://cwip-shaka-proxy.appspot.com/no_auth", // Widevine license URL
      headers: {
        // "T-Header": "You can send header like this",
      },
    },
    playready: {
      url: "https://playready.directtaps.net/pr/svc/rightsmanager.asmx?PlayRight=1&ContentKey=EAtsIJQPd5pFiRUrV9Layw==", // Playready license URL
      headers: {
        // "T-Header": "You can send header like this",
      },
    },
  },
  ui: {
    mainColor: "red",
  },
  captions: [
    {
      label: "English",
      src: "./test.vtt",
      language: "en",
    },
  ],
};

Methods 🔧

1. destroyPlayer({id: string})

It will destroy the player instance. Id will be same as the id of the player instance.

destroyPlayer({ id: "tplayer" });

2. getPlayer({id: string})

It will return the player instance. Id will be same as the id of the player instance. You can apply additional controls to the player instance.

let player = getPlayer({ id: "tplayer" });
player.pause();

Credits 💖

License 📝

tplayer.js is licensed under the MIT license

Crafted with 💖 by Tuhin Kanti Pal in 1 day.