Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions docs/packages/player.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ Set `autoplay muted` only when playback should start without a user gesture.

| Attribute | Type | Default | Description |
| --------------- | ------- | ------- | --------------------------------------------------------- |
| `src` | string | — | URL or relative path to composition HTML |
| `src` | string | — | URL or relative path to composition HTML, or to a video file with `type` |
| `type` | string | — | A `video/...` type (e.g. `video/mp4`) plays `src` as a video file |
| `srcdoc` | string | — | Composition HTML already available as a string |
| `width` | number | 1920 | Native composition width used for aspect ratio |
| `height` | number | 1080 | Native composition height used for aspect ratio |
Expand All @@ -68,6 +69,10 @@ Player also accepts `shader-capture-scale` and `shader-loading` for previewing
projects that use shader transitions. These are preview controls, not composition
authoring attributes.

With a `video/...` `type`, `src` plays in a `<video>` behind the same playback API and
events. `scenes`, `setRuntimeData()`, `setColorGrading()`, `iframeElement` and `stopMedia()`
are composition-only, and `srcdoc` wins over a video `src`, as it does in an iframe.

## JavaScript API

The main API follows familiar media-player behavior:
Expand Down Expand Up @@ -113,7 +118,8 @@ player.addEventListener("timeupdate", (event) => {
| `ratechange` | — | Playback rate changed |
| `volumechange` | — | Volume or muted state changed |
| `scenes` | `{ scenes }` | The runtime reported its scene list |
| `error` | `{ message }` | Load or runtime error |
| `error` | `{ message }` | Load or runtime error; a video adds its `MediaError` `code` |
| `playbackerror` | `{ source, error }` | The browser blocked playback, for example unmuted autoplay |

## Advanced: iframe access

Expand Down
19 changes: 17 additions & 2 deletions packages/player/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,19 @@ import "@hyperframes/player";
// Vue: <hyperframes-player :src="url" controls />
```

### Video files

Set `type` to a video type and the player plays `src` in a `<video playsinline>` instead of loading it as a composition. The same API and events apply: `play()`, `pause()`, `seek()`, `currentTime`, `duration`, `ready`, `timeupdate`, `play`, `pause`, `ended`, `durationchange` and `resize`, with the video's own size as `compositionWidth`/`compositionHeight`. A video that fails to load fires `error` at once with `{ message, code }`, where `code` is the `MediaError` code. A `play()` the browser blocks (for example, unmuted autoplay) fires `playbackerror` with `{ source: "video" }` and leaves the player paused. `poster`, `controls`, `loop`, `muted`, `volume`, `playback-rate` and `autoplay` work as they do for a composition. `scenes`, `setRuntimeData()`, `setColorGrading()`, `iframeElement` and `stopMedia()` are composition-only: a video has no scenes or runtime, its iframe stays blank, and `stopMedia()` does not stop the video. `srcdoc` wins over a video `src`, as it does in an iframe.

```html
<hyperframes-player
type="video/mp4"
src="./render.mp4"
poster="./poster.jpg"
controls
></hyperframes-player>
```

### Poster image

Show a static image before playback starts:
Expand All @@ -54,7 +67,8 @@ Show a static image before playback starts:

| Attribute | Type | Default | Description |
| ----------------------- | ------------------------------- | ------------- | --------------------------------------------------------------------------- |
| `src` | string | — | URL to the composition HTML file |
| `src` | string | — | URL to the composition HTML file, or to a video file with `type` |
| `type` | string | — | A `video/...` type (e.g. `video/mp4`) plays `src` as a video file |
| `audio-src` | string | — | Audio URL for parent-frame playback (mobile) |
| `width` | number | 1920 | Composition width in pixels (aspect ratio) |
| `height` | number | 1080 | Composition height in pixels (aspect ratio) |
Expand Down Expand Up @@ -236,7 +250,8 @@ function StudioPreview({ src }: { src: string }) {
| `pause` | — | Playback paused |
| `timeupdate` | `{ currentTime }` | Playback position changed (~10 fps) |
| `ended` | — | Reached the end (when not looping) |
| `error` | `{ message }` | Composition failed to load |
| `error` | `{ message }` (video mode: `{ message, code }`) | Composition or video failed to load |
| `playbackerror` | `{ source, error }` | The browser blocked playback |
| `shadertransitionstate` | `{ compositionId, state }` | Shader transition cache/capture progress |

```js
Expand Down
Loading
Loading