Saltar al contenido
DS

Componentes · Contenido

Vídeo <Video>

Vídeo de fondo o con controles, con su botón de pausa accesible.

import Video from '@vivla-cms/ds/primitives/Video.astro'

Ejemplos

Vídeo de fondo con sus controles

Modo decorative (por defecto): bucle silencioso sobre una foto fija (<Media aspect="fill"> debajo). Con reveal aparece sobre la foto solo cuando ya se reproduce, así que sin JS, con movimiento reducido o con ahorro de datos se ve la foto. Se reproduce solo mientras está a la vista. Un bucle de más de 5 s necesita su <VideoToggle action="pause"> (WCAG 2.2.2); sound activa el sonido. Nunca abajo a la derecha: ahí flota el botón de cookies.

Vídeo con sonido (playable)

mode="playable": entrevistas y testimonios. Muestra el póster con un botón de reproducir abajo a la izquierda; al pulsarlo suena y pasa a los controles nativos. Nunca empieza solo ni hace bucle, y al empezar uno se pausa cualquier otro de la página. captions añade subtítulos (el del idioma de la página activo). track / trackComplete envían los eventos de analítica.

Entrevistas VIVLA Studio

Proporción del reproductor

En playable, aspect es la caja (por defecto 16/9). auto respeta la proporción del archivo sin recortar (lo que el bloque media llama «natural»): pasa width y height si los conoces para reservar el hueco.

Props

<Video>

Props de Video
Prop Valores Por defecto Para qué
mode decorativeplayable 'decorative' decorative (muted in-view loop, default) · playable (click to play with sound).
src * string — Already-transformed video URL (desktop / fallback).
srcMobile string — Portrait / lighter cut for viewports under 48rem.
poster string — Poster frame URL (shown by the element before the first frame).
id * string — Target of <VideoToggle for={id}> (and the element id).
label string — Accessible name; omit for a purely decorative video (aria-hidden).
loop boolean true Default true; a non-looping video fades back to the still when it ends. Decorative only.
reveal boolean true Fade in over the still once playing (default true). Decorative only.
firstFrame boolean false Decorative, no still under it (a video picked in a photo field, 10/11): no fade-in (nothing to fade from), and the still is the video's own. With a poster (the CMS's first-frame «Portada del vídeo», or Cloudinary's so_0) that image shows at once and the file waits (preload="none"); without one, preload="metadata" and a #t=0.001 fragment make the browser paint the first frame as the poster — for reduced-motion and Save-Data visitors too, who never see it move.
sizing fillauto 'fill' Decorative: fill (default) covers its box; auto keeps the file's own ratio.
fit covercontain 'cover' —
aspect | '16/9' | '4/3' | '3/2' | '1/1' | '4/5' | '3/4' | '2/3' | '21/9' | 'auto' | 'fill' '16/9' Playable: box ratio (default 16/9); auto keeps the asset's ratio (CMS natural); fill stretches to a parent with a height.
width number — Playable, aspect="auto": intrinsic size of the asset, reserves its ratio before the poster loads.
height number — —
captions CaptionTrack[] — Playable: WebVTT caption tracks.
crossorigin anonymoususe-credentials — Playable: CORS mode, needed when the VTT lives on another origin.
labelledby string — Playable: id of the visible title that names the video (wins over label).
title string — Playable: what is played, appended to the play Button name.
playText string — Playable: visible play Button text (default uiLabel('videoPlay')).
track string — Playable: dataLayer event pushed on the first play, e.g. video_play.
trackComplete string — Playable: dataLayer event pushed when the video ends, e.g. video_complete.
trackLabel string — Playable: track_label param of both events.

<VideoToggle>

Props de VideoToggle
Prop Valores Por defecto Para qué
for * string — id of the <Video> this button controls (becomes aria-controls).
action soundpause 'sound' sound (default) mutes / unmutes; pause pauses / plays.
label * string — Fixed accessible name, e.g. uiLabel('videoSound', locale).
variant glasssolid 'glass' glass (default, the hero) or solid (white disc, the interview).
track string — Analytics event name, emitted as data-track.

Notas del código

El comentario de cabecera de Video.astro, tal cual (en inglés, como el código): si cambia el código, cambia esto.

two modes.

decorative (default): background / loop video (hero, full-bleed media). The caller layers the still image underneath (a <Media aspect="fill">) and this video on top: with reveal it stays transparent and fades in over the still once it is actually playing, so no-JS, reduced-motion and Save-Data visitors only ever see the still.

<div class="relative h-svh">
  <Media {...still} alt="" aspect="fill" radius="none" loading="eager" />
  <Video id="hero-video" src={mp4} srcMobile={mp4Tall} class="absolute inset-0" />
  <VideoToggle for="hero-video" action="sound" label={uiLabel('videoSound', locale)} />
</div>

Accessibility: no pause button over a loop since 06/11/2026 (Jaime, design: «los pause de todos los vídeos los eliminamos») — the WCAG 2.2.2 pause control is dropped by design decision. What stays: the loop is muted and motion never starts on its own for reduced-motion or Save-Data users (no autoplay attribute, preload="none", so they keep the still); the bundled script plays it only while ≥ 25 % is in view, pauses it off-screen, and stops auto-playing if the visitor switches to reduced motion. An explicit click on the sound toggle (unmute) always plays. A loop that talks (the studio interview, 16/11/2026) can also carry a <VideoToggle action="pause">: a click on it pauses, the next one plays (whatever the motion settings), and a video the visitor paused is not resumed when it scrolls back into view. Without label the element is aria-hidden.

Loading (10/11/2026, web review: «lo paso tan rápido que no parece un vídeo»): a loop starts buffering when it comes within one screen of the viewport (preload goes from none to auto, after the page load or 2.5 s), so it is already playing when it scrolls in instead of starting then. A loop over a still plays once that still has loaded (or 2.5 s): the hero's loop never competes with the LCP photo under it. Reduced motion and Save-Data never buffer.

playable: content video with sound (interviews, Figma 340:4623). It owns its box (aspect, default 16/9, class goes on that box) and shows the poster with a play Button bottom-left (never bottom-right: the consent button floats there). A click plays it with sound and hands over to the native controls; it never autoplays, never loops, preload="none", and starting one pauses any other playable video on the page. captions render <track kind="captions"> (the one in the page language is on by default, unless a track sets default itself); VTT files on another origin need crossorigin and CORS on both files. Without JS the native controls are there from the start and the play Button stays hidden.

<Video mode="playable" id="studio-interview" src={mp4} poster={still}
       aspect="3/2" labelledby="studio-interview-title" title="Entrevistas"
       captions={[{ src: vttEs, srclang: 'es', label: 'Español' }]}
       track="video_play" trackComplete="video_complete" trackLabel="studio_interview" />

aspect="auto" (playable) keeps the asset's own ratio: no box ratio and no crop, the poster and then the video metadata set the height. It is what the media block's aspectRatio: 'natural' (its default) maps to, so talking heads and interviews are never cover-cropped (plan §1B #4). Pass the asset's width / height when known to reserve the space before the poster loads.

Name (plan D34): the play Button is «{uiLabel('videoPlay')}: {title}»; the <video> takes aria-labelledby (the block title) or label.

Analytics (GTM dataLayer, pushed by the script, not delegated clicks): track on the first play of that video, however it starts (play Button, poster click or the native controls), once per page view; trackComplete when it ends. Both carry track_label (trackLabel) when set: { event: 'video_play', track_label: 'studio_interview' }.

srcMobile is served below 48rem through <source media>; src is the fallback. MIME types are inferred from .mp4 / .webm / .mov and omitted otherwise (e.g. extension-less Cloudinary delivery URLs). The script runs once per page and binds every [data-ds-video], [data-ds-video-toggle] and [data-ds-video-player] present on load, idempotently (data-bound); it re-binds after view transitions, but elements injected later by other scripts are not picked up.

<VideoToggle>

VideoToggle — a SOUND or PAUSE button of a decorative <Video>, by id. It is server-rendered hidden and only revealed by the <Video> script once the controlled video exists, so no-JS visitors (who only get the still) never see a dead control.

<VideoToggle for="hero-video" action="sound" label={uiLabel('videoSound', locale)} />

State lives in aria-pressed, the accessible name stays fixed:

· sound — pressed = unmuted.
· pause — pressed = paused. A click on a paused video plays it, also for
  reduced-motion and Save-Data visitors (explicit intent), and a video the
  visitor paused stays paused when it scrolls back into view.

Labels come from uiLabel() in @vivla-cms/ds/i18n (videoSound, videoPause). Keep the buttons out of the bottom-right corner, where the cookie consent button floats. Size is the 44 px touch target (size-11).

Two looks:

· `glass` (default) — its own `bg-surface/60` disc with `text-on-surface`,
  inverting on keyboard focus, so it reads over any footage; put it inside
  a `data-theme="dark"` section over photos. The icon shows the STATE
  (`sound-off` while muted). The hero's sound button.
· `solid` — the white disc of the studio interview (Figma "Web 2026"
  DCZJOXXl9SZG4C0ByXRSew · 00_VIVLA STUDIO 1161:1836, Jaime 16/11/2026):
  56 px from `lg` (44 on phones), white (`k-0`) with the warm-black icon,
  whatever the section theme. The icon shows the ACTION, as drawn: the
  muted video shows `sound-on`, the playing one `pause`.

Pause is opt-in. Since 06/11/2026 (Jaime, design: «los pause de todos los vídeos los eliminamos») ambient loops carry no pause button and the WCAG 2.2.2 pause control is dropped by design decision; on 16/11 Jaime brought it back for the one loop that talks — the interview that now autoplays — and only a caller that asks for it (the media block's «Botones de pausa y sonido») renders one.

Dónde se usa

12 veces en 7 archivos de la web y los bloques del CMS.

Ver los archivos
esc