Playback, seeking, and captions
These browser previews play the small media files bundled with the Hozo showcase. They do not autoplay or fetch media from a third party. See Video & Audio for installation and the Native dependencies.
Seek and switch video captions
Section titled “Seek and switch video captions”Play the silent animation, or leave it paused and move the Video position slider. The captions describe a purple square moving to the right. Tab to the slider and use the arrow keys, or select a point on the track. Choose English, 日本語, or Captions off to change the caption without restarting playback.
import { Video, VideoControls, type VideoHandle, type VideoStatus } from '@hozo/media'import { MediaCaptionSelector, MediaCaptions } from '@hozo/media/captions'import { useMediaSeek } from '@hozo/media/seek'import { parsePlainTextWebVTT } from '@hozo/media/webvtt'import { Slider } from '@hozo/patterns'import { useRef, useState } from 'react'const tracks = { en: parsePlainTextWebVTT(`WEBVTT00:00.000 --> 00:02.000The purple square moves toward the center.00:02.000 --> 00:04.000The purple square continues toward the right.`), ja: parsePlainTextWebVTT(`WEBVTT00:00.000 --> 00:02.000紫の四角が中央に向かって動きます。00:02.000 --> 00:04.000紫の四角が右に向かって動き続けます。`),}const captions = [ { id: 'en', label: 'English' }, { id: 'ja', label: '日本語' },]export function CaptionedVideo({ src }: { src: string }) { const player = useRef<VideoHandle>(null) const [status, setStatus] = useState<VideoStatus | null>(null) const [language, setLanguage] = useState<string | null>('en') const seek = useMediaSeek({ player, status, accessibilityLabel: 'Video position' }) const cues = language === 'ja' ? tracks.ja : tracks.en return ( <> <Video ref={player} src={src} accessibilityLabel="Moving square, silent video" controls={false} muted onStatusChange={setStatus} style={{ width: '100%', height: 168, backgroundColor: '#0f172a' }} /> <MediaCaptions src={src} status={status} cues={cues} enabled={language !== null} accessibilityLabel="Animation captions" /> <VideoControls player={player} status={status} seekStep={1} /> {seek.slider && ( <Slider key={seek.key} {...seek.slider} style={{ position: 'relative', height: 44, width: '100%', backgroundColor: '#e2e8f0' }} thumbStyle={{ position: 'absolute', top: 0, width: 24, height: 44, backgroundColor: '#4338ca', }} /> )} <MediaCaptionSelector options={captions} value={language} onValueChange={setLanguage} accessibilityLabel="Caption language" offLabel="Captions off" /> </> )}The slider reads the player’s actual status. A seek requests a new position; the player reports the result. The captions take the same status and select the cue for that time. Here both cue lists are parsed from bundled WebVTT text; see the captions reference if your tracks are separate URLs.
Play audio without a video element
Section titled “Play audio without a video element”This file contains three short rising tones. Try Play audio, or use the seek buttons to move by one second. Audio uses its own entry point and decoder; it does not require a hidden video player.
import { Audio, AudioControls, type AudioHandle, type AudioStatus } from '@hozo/media/audio'import { useRef, useState } from 'react'export function TonePlayer({ src }: { src: string }) { const player = useRef<AudioHandle>(null) const [status, setStatus] = useState<AudioStatus | null>(null) return ( <> <Audio ref={player} src={src} accessibilityLabel="Three rising tones" controls={false} onStatusChange={setStatus} /> <AudioControls player={player} status={status} seekStep={1} /> </> )}Each example takes a src so you can supply your own media. For Native
bundled files, use the Metro asset example to resolve
the asset ID first. The previews here are browser examples, not Native
playback evidence.