Methods & properties
const player = document.querySelector('vega-player');Playback
Section titled “Playback”| Method | Description |
|---|---|
play() | Starts playback. Falls back to muted if the browser blocks sound. |
pause() | Pauses. May open the call-to-action modal. |
pause({ silent: true }) | Pauses without opening the modal (this pause only). |
stop() | Pauses and rewinds to 0. |
setTime(seconds) | Seeks, clamped between 0 and the duration. |
setPlaybackRate(rate) | Sets the speed (0.25–2). Kept across quality changes. |
setQuality(src) | Switches file keeping position, play/pause state and speed. |
Volume
Section titled “Volume”| Method | Description |
|---|---|
setVolume(value) | 0 to 1. 0 also mutes. |
getVolume() | Returns the current volume. |
Display
Section titled “Display”| Method | Description |
|---|---|
toggleFullscreen() | Fullscreen on/off (native video fullscreen on iPhone). |
togglePictureInPicture() | Async. Picture-in-Picture on/off. |
toggleCaptions() | Shows/hides captions. |
toggleChromecast() | Starts or ends a Cast session. |
| Member | Description |
|---|---|
showModal() | Opens the modal and moves focus inside. |
hideModal() | Closes it and restores focus. |
isModalVisible | true while the modal is open (read-only in practice). |
While casting, play(), pause(), setTime() and setVolume() act on the Cast device.
Properties
Section titled “Properties”Every attribute is also a settable property in camelCase that reflects to the attribute:
player.src = '/video-720.mp4';player.muted = true; // boolean attributes take booleansplayer.controlsVisible = false; // "true"/"false" attributes tooplayer.colorPrimary = '#ff6a2b';player.qualities = [{ label: '720p', src: '/video-720.mp4' }]; // arrays are stored as JSONplayer.poster = null; // null/undefined/'' removes the attributeStatic settings
Section titled “Static settings”Set these on the class, before players are created:
import VegaPlayer from './vega-player.js';
VegaPlayer.RELEASE_DELAY = 120000; // ms paused before the video is unloaded (0 = never)VegaPlayer.i18n = { ...VegaPlayer.i18n, play: 'Reproducir' }; // interface textsSee Translating the UI for every text key.