, options?: VideoOptions): VideoReturn;
```
### `createVideoPlayer`
Extends `createVideo` with the full control surface: volume, muted, playback rate, loop, buffering state, and dimensions. Accepts all `VideoOptions` plus `volume` and `playbackRate` initial values.
```tsx repl
import { render } from "@solidjs/web";
import { createVideoPlayer } from "@solid-primitives/video";
const SRC = "https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.mp4";
function Demo() {
const video = createVideoPlayer(SRC, { volume: 0.5 });
video.player.controls = true;
video.player.width = 320;
return (
<>
{video.player}
video.setVolume(e.currentTarget.valueAsNumber)}
/>
volume {Math.round(video.volume() * 100)}% · readyState {video.readyState()} ·{" "}
{video.videoWidth()}×{video.videoHeight()}
>
);
}
render(() => , document.getElementById("app")!);
```
```ts
const video = createVideoPlayer("clip.mp4", {
muted: true,
volume: 0.8,
playbackRate: 1,
});
// All fields from createVideo, plus:
video.volume(); // 0–1
video.setVolume(0.5);
video.muted(); // boolean
video.setMuted(true);
video.playbackRate(); // number
video.setPlaybackRate(1.5);
video.loop(); // boolean
video.setLoop(true);
video.buffered(); // TimeRanges | undefined
video.readyState(); // 0–4
video.videoWidth(); // intrinsic pixel width
video.videoHeight(); // intrinsic pixel height
```
> **Fullscreen** is intentionally omitted — use the dedicated `@solid-primitives/fullscreen` primitive to manage fullscreen state and attach it to `video.player`.
```ts
function createVideoPlayer(
src: VideoSource | Accessor,
options?: VideoControlsOptions,
): VideoControlsReturn;
```
### `makeVideoFrameCallback`
Wraps [`HTMLVideoElement.requestVideoFrameCallback`](https://wicg.github.io/video-rvfc/), which fires once per displayed video frame instead of once per display refresh — it stops naturally while the video is paused, and the `metadata` argument (`mediaTime`, `presentedFrames`, etc.) lets you sync work to actual playback instead of wall-clock time. No Solid owner required.
```tsx repl
import { render } from "@solidjs/web";
import { createSignal, onCleanup } from "solid-js";
import { makeVideo, makeVideoFrameCallback } from "@solid-primitives/video";
const SRC = "https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.mp4";
function Demo() {
const supported = "requestVideoFrameCallback" in HTMLVideoElement.prototype;
const [mediaTime, setMediaTime] = createSignal(0);
const [player, cleanup] = makeVideo(SRC, {}, { muted: true, loop: true, autoPlay: true });
const [, start, stop] = makeVideoFrameCallback(player, (_, meta) => setMediaTime(meta.mediaTime));
onCleanup(() => {
stop();
cleanup();
});
player.controls = true;
player.width = 320;
if (supported) start();
return (
<>
{player}
{supported
? `frame mediaTime: ${mediaTime().toFixed(3)}s`
: "requestVideoFrameCallback is not supported in this browser"}
>
);
}
render(() => , document.getElementById("app")!);
```
```ts
const [player, cleanup] = makeVideo("clip.mp4");
const [running, start, stop] = makeVideoFrameCallback(player, (now, metadata) => {
draw(metadata.mediaTime);
});
start();
stop();
cleanup();
```
```ts
function makeVideoFrameCallback(
video: HTMLVideoElement,
callback: VideoFrameRequestCallback,
): [running: () => boolean, start: VoidFunction, stop: VoidFunction];
```
### `createVideoFrameCallback`
Reactive version of `makeVideoFrameCallback` — takes an accessor for the video element, so it re-attaches whenever the element changes and stops cleanly when it becomes `undefined`. `running` is a Solid signal, and playback is automatically stopped `onCleanup`.
```tsx repl
import { render } from "@solidjs/web";
import { createSignal } from "solid-js";
import { createVideo, createVideoFrameCallback } from "@solid-primitives/video";
const SRC = "https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.mp4";
function Demo() {
const supported = "requestVideoFrameCallback" in HTMLVideoElement.prototype;
const [frames, setFrames] = createSignal(0);
const video = createVideo(SRC, { muted: true, loop: true });
const [running, start, stop] = createVideoFrameCallback(
() => video.player,
(_, meta) => setFrames(meta.presentedFrames),
);
video.player.controls = true;
video.player.width = 320;
if (supported) start();
return (
<>
{video.player}
{supported
? `presented frames: ${frames()} (play the video to count)`
: "requestVideoFrameCallback is not supported in this browser"}
>
);
}
render(() => , document.getElementById("app")!);
```
```ts
const video = createVideo("clip.mp4");
const [running, start, stop] = createVideoFrameCallback(
() => video.player,
(now, metadata) => {
console.log(metadata.presentedFrames);
},
);
start();
```
```ts
function createVideoFrameCallback(
el: Accessor,
callback: VideoFrameRequestCallback,
): [running: Accessor, start: VoidFunction, stop: VoidFunction];
```
## Types
```ts
type VideoSource = string | undefined | MediaProvider;
type VideoOptions = {
autoPlay?: boolean;
loop?: boolean;
muted?: boolean;
preload?: "" | "none" | "metadata" | "auto";
};
type VideoControlsOptions = VideoOptions & {
volume?: number;
playbackRate?: number;
};
type VideoReturn = {
player: HTMLVideoElement;
playing: Accessor;
setPlaying: (v: boolean) => void;
currentTime: Accessor;
seek: (time: number) => void;
ended: Accessor;
seeking: Accessor;
error: Accessor;
duration: Accessor; // throws NotReadyError until loaded
};
type VideoControlsReturn = VideoReturn & {
volume: Accessor;
setVolume: (v: number) => void;
muted: Accessor;
setMuted: (v: boolean) => void;
playbackRate: Accessor;
setPlaybackRate: (rate: number) => void;
loop: Accessor;
setLoop: (v: boolean) => void;
buffered: Accessor;
readyState: Accessor;
videoWidth: Accessor;
videoHeight: Accessor;
};
```
## Changelog
See [CHANGELOG.md](./CHANGELOG.md)