Video sources
Use one of these three ways to give the player its video.
| Option | Use it when |
|---|---|
src | You have one file. |
src-webm, src-mp4, src-ogg | You have the same video in several formats and want the browser to pick. |
responsive-src | You have the same video in several sizes. See Quality & responsive files. |
A single file
Section titled “A single file”<vega-player src="/video.mp4" poster="/poster.jpg"></vega-player>Several formats
Section titled “Several formats”The browser plays the first format it supports, in this order: WebM, MP4, Ogg. If you change these attributes while a video is playing, the position and play state are kept.
<vega-player src-webm="/video.webm" src-mp4="/video.mp4" poster="/poster.jpg"></vega-player>If you also set src-*, they take priority over src.
Preloading
Section titled “Preloading”preload works like on <video>. The default is none: nothing is downloaded until the viewer
presses play, which keeps pages with many players light.
| Value | Behaviour |
|---|---|
none (default) | Downloads nothing until play. The duration is unknown until then. |
metadata | Downloads only the duration and dimensions. Needed to show the duration or seek preview before playing. |
auto | Lets the browser buffer ahead. |
Poster, loop, muted, autoplay
Section titled “Poster, loop, muted, autoplay”<vega-player src="/video.mp4" poster="/poster.jpg" loop muted autoplay></vega-player>autoplay falls back to muted playback if the browser blocks sound. It only runs when the page
loads (or when the autoplay attribute itself is added), never because another attribute changed.
Aspect ratio
Section titled “Aspect ratio”aspect-ratio reserves the right space before the video loads, so the page doesn’t jump.
Use any W:H or W/H value; the default is 16:9.
<vega-player src="/vertical.mp4" aspect-ratio="9:16"></vega-player>When a video fails
Section titled “When a video fails”If the video can’t load (missing file, network error, unsupported format) the player shows an error
screen with a Retry button, which retries from the same position, and fires
vega-player:error.
<vega-player src="/missing.mp4" error-title="Video unavailable" error-retry-text="Try again"></vega-player>Releasing memory after long pauses
Section titled “Releasing memory after long pauses”After 2 minutes paused, the player unloads the video to free memory. The last frame (or the poster)
stays on screen, nothing is released while the tab is hidden, and play() restores the source and the
position automatically. Change the delay globally, or set it to 0 to turn it off:
import VegaPlayer from './vega-player.js';VegaPlayer.RELEASE_DELAY = 0; // never release