Data displayVideoMedia
Searchastronomic.dev# VideoMedia
For a short silent loop or a showreel still: a video in a fixed shape with its poster, a play button, and no autoplay for readers who ask for less motion.
Interactive: inline script.
## Usage
```astro
import VideoMedia from "@astronomic-dev/ui/components/VideoMedia.astro";
```
## Examples
### A poster until the file is in
With sources={[]} the poster shows as a still in the frame the video will fill, with label as its alt. List your files in sources (WebM before MP4) and it plays: muted, looped, and only when the reader allows motion.
```astro
---
import VideoMedia from "@astronomic-dev/ui/components/VideoMedia.astro";
// Your own poster image. Put your video files next to it and list them in sources, the smallest first:
// sources={[{ src: "/video/reel.webm", type: "video/webm" }, { src: "/video/reel.mp4", type: "video/mp4" }]}
import shelves from "../../photos/studio-shelves.webp";
---
<!-- No file yet: with sources={[]} the poster shows as a still, in the frame the video will fill. -->
<div class="mx-auto max-w-2xl">
<VideoMedia sources={[]} poster={shelves} label="Plates and bowls on the studio's white shelves" caption="The studio reel, coming soon. Until the file is in, the poster holds its place." />
</div>
```
### Media's shapes
The frame is Media's: shape="cut" with cutCorner, and shape="circle", with focalPoint to keep the subject in view.
```astro
---
import VideoMedia from "@astronomic-dev/ui/components/VideoMedia.astro";
// Your own poster images. With your files in sources, each frame plays its video in the same shape.
import desk from "../../photos/studio-desk.webp";
import sketch from "../../photos/sketching-wireframes.webp";
---
<!-- The same shapes as Media: a cut corner and a circle. -->
<div class="mx-auto grid max-w-xl grid-cols-2 items-start gap-cards">
<VideoMedia sources={[]} poster={desk} label="A laptop, a framed print and a cactus on a light wood desk" ratio="4/3" shape="cut" cutCorner="bottom-end" />
<VideoMedia sources={[]} poster={sketch} label="A hand sketching wireframes beside a mug" shape="circle" focalPoint="40% 50%" />
</div>
```
## Props
### VideoMedia
| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `sources` | `VideoSource[]` | None | Required. Your files as { src, type } with type "video/webm" or "video/mp4", the smallest first; the browser plays the first it can. With none, the poster shows as a still picture (label is its alt) and there is no button. |
| `poster` | `ImageSource` | None | Required. The still shown before the video plays, under reduced motion, and with no script: a URL or an imported image (its width and height keep the space). |
| `label` | `string` | None | Required. What the video shows. The play button is named "Play: " and this. |
| `autoplay` | `boolean` | `true` | Plays muted and looped by itself when the reader allows motion: no reduced motion, the theme not calm (data-motion="calm" on <html>) and the page not paused (MotionPause). Off: the poster and a play button. |
| `ratio` | `"16/9" \| "4/3" \| "1/1" \| "3/4"` | `"16/9"` | The frame's shape as width/height, as on Media; any other pair works too. The video fills it and is cropped. |
| `ratioClass` | `string` | None | Classes for the frame's shape in place of `ratio` (aspect-[4/3] md:aspect-video), as on Media. |
| `shape` | `"rect" \| "circle" \| "cut"` | `"rect"` | As on Media: a circle is always square; a cut slices one corner off. The button sits at the bottom-end, in the middle of a circle, and at the bottom-start when the cut takes the bottom-end. |
| `cutCorner` | `"top-start" \| "top-end" \| "bottom-start" \| "bottom-end"` | None | With `shape="cut"`: the corner to cut, in the writing direction. Default: top-end. |
| `focalPoint` | `string` | None | The point to keep in view when the frame crops the video, as on Media ("50% 20%", "top"). |
| `caption` | `string` | None | A short line under the video, in muted text. The whole becomes a `<figure>`. |
| `preload` | `"none" \| "metadata"` | `"metadata"` | metadata loads the length and the first frame; none loads nothing until play, for a video far down the page. |
| `transitionName` | `string` | None | A view-transition-name for the frame (a work card that grows into the case study's hero), set only when motion is allowed. A CSS name; one element per page. Your theme opts into view transitions with @view-transition. |
| `class` | `string` | None | More classes, merged with cn(), so yours win on conflicts. |
| Slot | Description |
| --- | --- |
| `caption` | Your own caption content, in place of caption (for a link or a credit). |
Any other attribute goes on the outer <figure> or <div>.
## Accessibility
| Key | Action |
| --- | --- |
| Tab | Moves to the play and pause button (with the script; without it, to the browser's own controls). |
| Enter or Space | Plays or pauses the video. |
- It never plays by itself for a reader who asks for reduced motion, under the theme's calm setting, or after the page's Pause motion button; it stops at once when any of those turns on, even mid-play.
- The video has no sound (muted) and no autoplay attribute: the script starts it, so with no script the reader gets the poster and the browser's own controls.
- The play and pause button is one toggle: its name stays "Play: " and your label, and aria-pressed says whether it is playing. It is 44px on touch screens.
- A press always works: a reader who asks for less motion can still play a video.
- It pauses when it leaves the screen and goes on when it comes back.
- Decorative loops have no captions. For a video with speech or sound, link to a full player with captions instead.
VideoMedia
FreeFor a short silent loop or a showreel still: a video in a fixed shape with its poster, a play button, and no autoplay for readers who ask for less motion.
- File
- VideoMedia.astro
- Group
- Data display
- Kind
- Interactive: inline script
- Examples
- 2
Examples
Drag the orange handle to set the width. Frames get real breakpoints.
- Static
- Interactive
- Framed
A poster until the file is in
With sources={[]} the poster shows as a still in the frame the video will fill, with label as its alt. List your files in sources (WebM before MP4) and it plays: muted, looped, and only when the reader allows motion.
This preview did not load.
main.astro
examples/videomedia/main.astro
---
import VideoMedia from "@astronomic-dev/ui/components/VideoMedia.astro";
// Your own poster image. Put your video files next to it and list them in sources, the smallest first:
// sources={[{ src: "/video/reel.webm", type: "video/webm" }, { src: "/video/reel.mp4", type: "video/mp4" }]}
import shelves from "../../photos/studio-shelves.webp";
---
<!-- No file yet: with sources={[]} the poster shows as a still, in the frame the video will fill. -->
<div class="mx-auto max-w-2xl">
<VideoMedia sources={[]} poster={shelves} label="Plates and bowls on the studio's white shelves" caption="The studio reel, coming soon. Until the file is in, the poster holds its place." />
</div>Media's shapes
The frame is Media's: shape="cut" with cutCorner, and shape="circle", with focalPoint to keep the subject in view.
This preview did not load.
cut.astro
examples/videomedia/cut.astro
---
import VideoMedia from "@astronomic-dev/ui/components/VideoMedia.astro";
// Your own poster images. With your files in sources, each frame plays its video in the same shape.
import desk from "../../photos/studio-desk.webp";
import sketch from "../../photos/sketching-wireframes.webp";
---
<!-- The same shapes as Media: a cut corner and a circle. -->
<div class="mx-auto grid max-w-xl grid-cols-2 items-start gap-cards">
<VideoMedia sources={[]} poster={desk} label="A laptop, a framed print and a cactus on a light wood desk" ratio="4/3" shape="cut" cutCorner="bottom-end" />
<VideoMedia sources={[]} poster={sketch} label="A hand sketching wireframes beside a mug" shape="circle" focalPoint="40% 50%" />
</div>Minimal · Light