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

Overview

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

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://widevine-proxy.appspot.com/proxy", // 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",
  },
};

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.

You might also like...

A Node JS Express/Serverless demo application that creates a slideshow video using the Pexels image library and Shotstack video editing API.

Shotstack Pexels Slideshow Video Demo This project demonstrates how to use the Shotstack cloud video editing API to create a video using an HTML form

Dec 9, 2022

A Chrome extension to help you inspect Mp4 video content and find irregularities in video streams.

A Chrome extension to help you inspect Mp4 video content and find irregularities in video streams.

MP4Inspector A Chrome extension to help you inspect Mp4 video content and find irregularities in video streams. Installation In chrome navigate to chr

Nov 28, 2022

A lightweight, easy-to-use jQuery plugin for fluid width video embeds.

Introducing FitVids.js A lightweight, easy-to-use jQuery plugin for fluid width video embeds. FitVids automates the Intrinsic Ratio Method by Thierry

Dec 24, 2022

🚀 Blazing fast thread channels integration for all Discord.js versions

djs-threads 🚀 Blazing fast thread integration for all Discord.js versions 😃 THIS PROJECT IS ARCHIVED this project is archived because Discord will c

Feb 28, 2022

Easy and simple twitch bot in node.js.. very very easy..

Easy and simple twitch bot in node.js.. very very easy..

How It Works identity: { username: 'YOUR BOTS USERNAME', -- This is where you place the username that you gave the bot account password: '

Dec 18, 2021

A Javascript library for working with Audio. It provides a consistent API for loading and playing audio on different browsers and devices. Currently supports WebAudio, HTML5 Audio, Cordova / PhoneGap, and a Flash fallback.

SoundJS SoundJS is a library to make working with audio on the web easier. It provides a consistent API for playing audio in different browsers, inclu

Dec 31, 2022

A simple HTML5, YouTube and Vimeo player

A simple HTML5, YouTube and Vimeo player

Plyr is a simple, lightweight, accessible and customizable HTML5, YouTube and Vimeo media player that supports modern browsers. Checkout the demo - Do

Jan 3, 2023

A reimplementation of Winamp 2.9 in HTML5 and JavaScript with full skin support

A reimplementation of Winamp 2.9 in HTML5 and JavaScript with full skin support

A reimplementation of Winamp 2.9 in HTML5 and JavaScript with full skin support

Dec 31, 2022

Movie focused HTML5 Player

Movie focused HTML5 Player

Movie focused HTML5 Player

Dec 29, 2022
Releases(v.1.1.0)
HTML5

One file. Any browser. Same UI. Author: John Dyer http://j.hn/ Website: http://mediaelementjs.com/ License: MIT Meaning: Use everywhere, keep copyrigh

MediaElement.js 8k Jan 8, 2023
HLS.js is a JavaScript library that plays HLS in browsers with support for MSE.

HLS.js is a JavaScript library that implements an HTTP Live Streaming client. It relies on HTML5 video and MediaSource Extensions for playback. It wor

video-dev 12.3k Jan 2, 2023
SRS Player is a video streaming player, supports HLS/HTTP-FLV/WebRTC etc.

WordPress-Plugin-SrsPlayer SRS Player is a video streaming player, supports HLS/HTTP-FLV/WebRTC etc. Usage First, you should get your own video stream

ossrs 3 Jul 27, 2022
SRS Player is a video streaming player, supports HLS/HTTP-FLV/WebRTC etc.

SRS Player is a video streaming player, supports HLS/HTTP-FLV/WebRTC etc.

ossrs 12 Oct 15, 2022
Video.js - open source HTML5 & Flash video player

Video.js - HTML5 Video Player Video.js is a web video player built from the ground up for an HTML5 world. It supports HTML5 video and Media Source Ext

Video.js 34.8k Jan 5, 2023
tauOS 17 Jul 10, 2022
The HTML5 video player for the web

Flowplayer website | demos | docs For the impatient Download Flowplayer Unzip Drop the folder under your server Minimal setup <!DOCTYPE html> <head>

Flowplayer 1.9k Dec 30, 2022
A web video player built for the HTML5 world using React library.

video-react Video.React is a web video player built from the ground up for an HTML5 world using React library. Installation Install video-react and pe

null 2.4k Jan 6, 2023
jPlayer : HTML5 Audio & Video for jQuery

jPlayer : HTML5 Audio & Video for jQuery Gitter Support for Zepto 1.0+ compiled with the data module. What is jPlayer? jPlayer is a jQuery/Zepto plugi

jPlayer 4.6k Dec 27, 2022
Accessible HTML5 Video Player

Accessible HTML5 Video Player What is it? A lightweight HTML5 video player which includes support for captions and screen reader accessibility. For de

PayPal 2.4k Jan 5, 2023