Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

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

License

NotificationsYou must be signed in to change notification settings

tuhinpal/tplayer.js

Repository files navigation

Supported By

tplayer logo

This project is made possible withPlyr,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 avideo element in the DOM.

HTML

See example

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

    <scriptsrc="https://cdn.jsdelivr.net/npm/tplayer.js@1.1.0/dist/index.js"></script>
  2. Put the video element in the<body> of your HTML document.

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

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

NEXTJS

See example

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

# Install tplayer.jsnpm install tplayer.js
// component\player.jsximport{useRef,useEffect}from"react";import{tplayer,destroyPlayer}from"tplayer.js";exportdefaultfunctionPlayer({ config}){constvideoRef=useRef();useEffect(()=>{tplayer({      ...config,playerElem:videoRef.current,});return()=>destroyPlayer({id:config.id});},[]);return(<div><videoref={videoRef}></video></div>);}
// pages\index.jsximportdynamicfrom"next/dynamic";constPlayer=dynamic(import("../component/player"),{ssr:false});exportdefaultfunctionHome(){return<Playerconfig={options}/>;}

Options 📝

NameDescriptionDefault / Requirement / FallbackExample
idThis is thetplayer.js instance idDefault: tplayer'tplayerhtml'
playerElemVideo element from DOMRequireddocument.getElementById("tplayer")
sourceSource ObjectAt least one DASH or HLS URL is required{dash:'some.mpd', hls: 'some.m3u8'}
source.dashMPD URL of your source fileRequired if DRM enabledhttps://some.mpd
source.hlsM3U8 URL of your source fileNot required if Dash is providedhttps://some.m3u8
sourceHeaders.dashAdditional XHR headers for DashOptional{"some": "header"}
sourceHeaders.hlsAdditional XHR headers for hlsOptional{"some": "header"}
drmDRM ObjectOptional{widevine: {url: '', headers: {}}, playready: {url: '', headers: {}}}
drm.widevineWidevine ObjectOptionalwidevine: {url: '', headers: {}}
drm.widevine.urlWidevine license URLRequiredhttps://some/proxy
drm.widevine.headersHeaders object for license requestsOptional{"T-Header-One": "Hi", "T-Header-Two": "Hello"}
drm.playreadyPlayready ObjectOptionalplayready: {url: '', headers: {}}
drm.playready.urlPlayready license URLRequiredhttps://some.asmx
drm.playready.headersHeaders object for license requestsOptional{"T-Header-One": "Hi", "T-Header-Two": "Hello"}
uiExtended UI ObjectOptional{mainColor: '#ff002b'}
ui.mainColorMain colorOptional#ff002b
captionsWebVTT Captions arrayOptional[{label: "", src: "", language: ""}]
captions[index].labelCaption labelOptional"English"
captions[index].srcCaption source URLRequiredhttps://some.vtt
captions[index].languageCaption languageOptional"en"

See this example

constoptions={id:"tplayerhtml",// anythingplayerElem:document.getElementById("tplayer"),// grabbing the video element from the DOMsource:{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 URLheaders:{// "T-Header": "You can send header like this",},},playready:{url:"https://playready.directtaps.net/pr/svc/rightsmanager.asmx?PlayRight=1&ContentKey=EAtsIJQPd5pFiRUrV9Layw==",// Playready license URLheaders:{// "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.

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

Credits 💖

License 📝

tplayer.js is licensed under theMIT license

Crafted with 💖 byTuhin Kanti Pal in 1 day.


[8]ページ先頭

©2009-2025 Movatter.jp