pnpm dlx shadcn@latest add @audio-ui/use-play-switch
import { usePlaySwitch } from "@/hooks/use-play-switch";| Files | hooks/use-play-switch.ts |
|---|---|
| Depends on | use-audio-session |
| npm | Nothing |
| Used by | block-device-chain, block-mixer, piano-roll-playback-demo, spectrum-analyzer-demo, use-device-loop, use-noise-through-eq |
| Export | Kind | What it is |
|---|---|---|
usePlaySwitch | function | The 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.