Skip to content

Video sources

Use one of these three ways to give the player its video.

OptionUse it when
srcYou have one file.
src-webm, src-mp4, src-oggYou have the same video in several formats and want the browser to pick.
responsive-srcYou have the same video in several sizes. See Quality & responsive files.
<vega-player src="/video.mp4" poster="/poster.jpg"></vega-player>

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.

preload works like on <video>. The default is none: nothing is downloaded until the viewer presses play, which keeps pages with many players light.

ValueBehaviour
none (default)Downloads nothing until play. The duration is unknown until then.
metadataDownloads only the duration and dimensions. Needed to show the duration or seek preview before playing.
autoLets the browser buffer ahead.
<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 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>

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.

A missing file, on purpose.
<vega-player src="/missing.mp4" error-title="Video unavailable" error-retry-text="Try again"></vega-player>

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