Skip to content

Installation

Add this once per page:

<script type="module" src="https://vega-player.eduardovega.net/vega-player.min.js"></script>

and use the tag wherever you want a player:

<vega-player src="/video.mp4" poster="/poster.jpg"></vega-player>

Open source, MIT. The zip has the ready-to-use files, the source and the tests.

Download v2.4.0 (.zip)
vega-player-2.4.0/
├─ dist/ ready to use
│ ├─ vega-player.min.js ES module, minified (recommended)
│ ├─ vega-player.js ES module
│ ├─ vega-player.iife.min.js classic <script>, self-executing (window.VegaPlayer)
│ ├─ vega-player.iife.js
│ ├─ vega-player.umd.min.js UMD: AMD / RequireJS, CommonJS or global
│ ├─ vega-player.umd.js
│ ├─ vega-player.cjs CommonJS (require) for bundlers
│ ├─ vega-player.d.ts TypeScript declarations
│ └─ *.map source maps
├─ src/vega-player.js the source (one ES module)
├─ test/ 132 tests (Vitest, real Chromium)
├─ scripts/build.mjs builds dist/ from src/
├─ tools/generate-thumbnails.sh seek-preview thumbnails with ffmpeg
├─ package.json README.md CHANGELOG.md LICENSE
You use…Load
Plain HTML, modern browsers<script type="module" src="/js/vega-player.min.js"></script>
Plain HTML without modules (old CMS, inline scripts)<script src="/js/vega-player.iife.min.js"></script>
RequireJS / AMDrequire(['vega-player.umd.min'], (VegaPlayer) => …)
A bundler (Vite, webpack, Rollup, esbuild)import VegaPlayer from './lib/vega-player.js'
CommonJSconst VegaPlayer = require('./lib/vega-player.cjs')
TypeScriptthe same import; types come from vega-player.d.ts

Load one of them, once. That’s all.

  1. Download the package and copy the file you need from dist/ to your static files, for example /js/vega-player.min.js.

  2. Load it:

    <script type="module" src="/js/vega-player.min.js"></script>
  3. Use <vega-player> in your HTML.

Terminal window
npm install
npm run build # src/ → dist/ in every format
npm run setup # Chromium for the tests, once
npm test

The file’s default export is the VegaPlayer class. Importing it registers the element; importing it twice is safe.

import VegaPlayer from './vega-player.js';
await customElements.whenDefined('vega-player');
const player = document.querySelector('vega-player');

Any browser with Custom Elements and ES modules: current Chrome, Edge, Firefox and Safari 14.1+. Details in Browser support.