Playback
Session
const session = useSession(url, (s) => s.connect()); // setup runs once per sessionSession:id,url,state,connect(targetLatencyMs?)(default 200 ms),disconnect(),addListener('stateChange', ...).SessionState:'idle' | 'connecting' | 'connected' | 'closed' | 'error:${string}'.- No auto-connect — call
connect()insetupor on user action.urlis read atconnect()time — changing it doesn't recreate the session, it applies on the nextconnect().
Discovering broadcasts
const broadcasts = useBroadcasts(session, 'live'); // prefix; '' matches all- Returns
BroadcastInfo[]:{ sessionId, path, videoTracks, audioTracks, player }—playeris the broadcast's sharedPlayerHandle, whichuseVideoPlayer/createVideoPlayerwrap. Empty untilstate === 'connected', repopulates on reconnect,[]on disconnect. pathis relative to the prefix: broadcastlive/test→path: 'test'under prefix'live',''under prefix'live/test'.- Track metadata:
VideoTrackInfo { name, codec, width?, height?, framerate?, bitrate? },AudioTrackInfo { name, codec, sampleRate, channelCount?, bitrate? }. - Overlapping prefixes matching the same broadcast are unsupported.
Video playback
const player = useVideoPlayer(broadcast, (p) => p.play());
return <VideoView player={player} style={{ width: '100%', aspectRatio: 16 / 9 }} />;Player API:
- State:
isPlaying,playbackStats(null until first update),currentVideoTrackName,currentAudioTrackName,volume(0–1, default 1). - Methods:
play(),pause(),stop(),setVolume(v),updateTargetLatency(ms),switchVideoTrack(name),switchAudioTrack(name). - Events:
playingChange(deduped),trackSwitched({ trackKind, trackName }),trackStopped,statsUpdate(periodic).
<VideoView player={player} style={...} />:
- No children — the Android native view is not a ViewGroup. Overlays (captions, badges) go in absolutely-positioned sibling views.
- Size it yourself (e.g.
aspectRatio); the native surface fills the view.
Audio-only playback
const player = useAudioPlayer(broadcast, (p) => p.play());AudioPlayer=Playerminus video fields. Uses a separate native player (never subscribes the video track) — cheaper than a hidden<VideoView>.- Type error by design if passed to
<VideoView>/<VideoPlayerView>.
Choosing an audio API:
- Just hear it →
useAudioPlayer. - Process/visualize/transcribe in JS →
useAudioChunks(see custom-tracks.md).
Rendition switching & latency
broadcast.videoTracks.map((t) => t.name); // e.g. ['hd', 'sd']
player.switchVideoTrack('sd');
player.updateTargetLatency(500); // higher = more buffer, fewer stallsStats
PlaybackStats: videoLatencyMs, audioLatencyMs, videoBitrateKbps, audioBitrateKbps, videoFps, videoJitterBufferMs, audioRingBufferMs, timeToFirstVideoFrameMs, timeToFirstAudioFrameMs, videoFramesDropped, audioFramesDropped, videoStalls / audioStalls ({ count, totalDurationMs, rebufferingRatio }). All optional.
Events without re-rendering
const state = useEvent(session, 'stateChange', { state: session.state }); // re-renders
useEventListener(player, 'statsUpdate', (stats) => log(stats)); // side effect only; listener kept in a ref
const sub = player.addListener('playingChange', cb); sub.remove(); // manualreact-native-moq-ui
<VideoPlayerView player={player} videoAspectRatio={16 / 9}>
{/* children render as an overlay */}
</VideoPlayerView>VideoPlayerViewprops:player(required),videoAspectRatio(default 16/9 — pass it on Android, fullscreenSurfaceViewstretches otherwise),controls/miniControls(boolean | ReactNode, default true),onFullscreenEnter/Exit. Ref:enterFullscreen(),exitFullscreen().- Custom chrome: render your own node as
controlsand useuseFullscreenControls()→{ player, exit, show, visible }(fullscreen) oruseMiniPlayerControls()→{ player, enterFullscreen, show, visible }(inline). Both throw outside their context. - Extras:
<VolumeSlider player={...} width? theme?>(works withAudioPlayertoo),<SpeakerGlyph size? volume? color?>.
Troubleshooting
useBroadcastsempty → session notconnected, or nothing published under that prefix.- Listed but won't play / relay reset
code=13(NotFound) → path/prefix mismatch; subscribe with the exact published sub-path or prefix''. - Stretched fullscreen video on Android → missing
videoAspectRatio.