Lab

usePlaySwitch

The play switch of the nearest session: a button in its bar flips it, every component inside the session that reads it follows. Holds no audio, so a demo can leave its play button to its host.

pnpm dlx shadcn@latest add @audio-ui/use-play-switch
import { usePlaySwitch } from "@/hooks/use-play-switch";
Fileshooks/use-play-switch.ts
Depends onuse-audio-session
npmNothing
Used byblock-device-chain, block-mixer, piano-roll-playback-demo, spectrum-analyzer-demo, use-device-loop, use-noise-through-eq
ExportKindWhat it is
usePlaySwitchfunctionThe play switch of the nearest session: a button in its bar flips it, and every component inside the session that reads it follows.

Usage

The play switch of the nearest session: a button in its bar flips it, and every component inside the session that reads it follows. It holds no audio, only whether the sound should be on, so a demo leaves its play button to its host.

import { usePlaySwitch } from "@/hooks/use-play-switch";

const { playing, toggle } = usePlaySwitch();

It returns playing, toggle, setPlaying, and attach, which a control calls to say it shows the switch (the switch turns off when the last one goes). Outside a session it stays off and does nothing. useDeviceLoop plays while it is on.

Built by Ouest Labs, the source code is available on GitHub.
RSS