Installation
Script tag
Section titled “Script tag”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>Download
Section titled “Download”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 LICENSEWhich file?
Section titled “Which file?”| 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 / AMD | require(['vega-player.umd.min'], (VegaPlayer) => …) |
| A bundler (Vite, webpack, Rollup, esbuild) | import VegaPlayer from './lib/vega-player.js' |
| CommonJS | const VegaPlayer = require('./lib/vega-player.cjs') |
| TypeScript | the same import; types come from vega-player.d.ts |
Load one of them, once. That’s all.
Self-hosting
Section titled “Self-hosting”-
Download the package and copy the file you need from
dist/to your static files, for example/js/vega-player.min.js. -
Load it:
<script type="module" src="/js/vega-player.min.js"></script> -
Use
<vega-player>in your HTML.
Building from source
Section titled “Building from source”npm installnpm run build # src/ → dist/ in every formatnpm run setup # Chromium for the tests, oncenpm testAs an ES module
Section titled “As an ES module”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');// Copy vega-player.js into your source folder, then:import VegaPlayer from './lib/vega-player.js';
// Optional global settings, before players are createdVegaPlayer.i18n = { ...VegaPlayer.i18n, play: 'Reproducir' };Requirements
Section titled “Requirements”Any browser with Custom Elements and ES modules: current Chrome, Edge, Firefox and Safari 14.1+. Details in Browser support.