BakeNative is under active development. APIs may change.
Skip to Content
BakeNative

Video

The built-in <video> element, laid out by the core as Chrome does and played by the platform player.

Write <video> the way you would on the web. On native targets the core owns the element: its size, its poster, object-fit / object-position, rounded corners and its events. Only playback is the platform's (hardware decoding): Media Foundation on Windows, MediaPlayer on Android and AVPlayer on iOS and macOS. On the web it is the browser's own <video>.

import { useRef, useState } from 'octane';

export function Clip() @{
  const video = useRef(null);
  const [time, setTime] = useState(0);
  <video ref={video} class="clip" src="./media/intro.mp4" poster="./media/intro.jpg"
         muted playsInline preload="metadata"
         onLoadedMetadata={(e) => console.log(e.target.duration, e.target.videoWidth, e.target.videoHeight)}
         onTimeUpdate={(e) => setTime(e.target.currentTime)}
         onEnded={() => console.log('done')} />
  <button onClick={() => video.current.play()}>{'Play'}</button>
  <button onClick={() => video.current.pause()}>{'Pause'}</button>
  <button onClick={() => { video.current.currentTime = 0; }}>{'Restart'}</button>
  <p>{time.toFixed(1) + ' s'}</p>
  <style>
    .clip { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 12px; }
  </style>
}

Sources

  • Bundle assets: a relative src in markup (src="./media/intro.mp4") or an import (import clip from './intro.mp4') is copied into the bundle with a content hash, like an image. MP4 / M4V / MOV (H.264 or HEVC video, AAC audio) play on every platform; other formats (WebM, Ogg, ...) are a build error (video-format).
  • https: URLs, opened by the platform player (it streams them itself).
  • poster goes through the image pipeline: bundle assets, data: and http(s) URLs, with the same cache.

Size and drawing

The box is a replaced element, sized as Chrome sizes it:

  1. CSS width / height and the width / height attributes;
  2. else the video's natural size once its metadata is in (loadedmetadata), before that the poster's (each with its aspect ratio);
  3. else 300 × 150. That default has no aspect ratio: <video width="400"> without media is 400 × 150, as in Chrome.

The poster is drawn by the core, with object-fit / object-position (contain by default, as Chrome's user agent style says) and clipped to the content box with its rounded corners, until playback first starts; after that the video's frames show, also while paused. Without a poster the box is empty until the first frame is decoded. The picture rect of the frames is the core's object-fit / object-position result too: the platform player only draws into it.

Hydration

The baked first screen shows the poster, or the empty box. Native players attach after hydration (JS's first commit), so playback, autoplay included, never starts before the app runs.

Attributes, events and the ref

Attributessrc, poster, width, height, autoplay, muted, loop, playsInline, preload (auto, metadata, none: none opens the source on the first play())
EventsonLoadedMetadata, onPlay, onPause, onEnded, onTimeUpdate (at most every 250 ms; the last position always arrives), onError
event.targetcurrentTime, duration, paused, ended, videoWidth, videoHeight, error ({ code, message })
Refplay() (a Promise), pause(), currentTime (read, or set to seek), and the same fields

At the end without loop, pause fires, then ended, as in the browser.

Not supported (build errors)

  • controls (attribute-controls): each platform player has its own controls and none matches Chrome's, so the same markup would look different on every target. Draw your own buttons with play(), pause() and currentTime.
  • <source> (element-source) and <track> (element-track): native players open src only, and text tracks are not rendered.
  • <audio> (element-audio).
  • The former Video native view has been replaced by the built-in <video> element. A legacy video import is a build error (view-video-removed) that points here.

Picture-in-picture, fullscreen and other platform features are not part of <video>; they will come as small add-on modules.

On this page