useStartAudio
function useStartAudio(options): {
mergedProps: ButtonHTMLAttributes<HTMLButtonElement> & {
className: string;
onClick: () => void;
style: {
display: string;
};
};
canPlayAudio: boolean;
};Defined in: packages/react/src/hooks/device/useStartAudio.ts:35
Note. This feature is experimental and may change or be removed based on developer feedback and real-world usage. In some browsers to start audio playback, the user must perform a user-initiated event such as clicking a button.
Parameters
| Parameter | Type |
|---|---|
options | UseStartAudioOptions |
Returns
{
mergedProps: ButtonHTMLAttributes<HTMLButtonElement> & {
className: string;
onClick: () => void;
style: {
display: string;
};
};
canPlayAudio: boolean;
}mergedProps
mergedProps: ButtonHTMLAttributes<HTMLButtonElement> & {
className: string;
onClick: () => void;
style: {
display: string;
};
};Type Declaration
className
className: string;onClick
onClick: () => void;Returns
void
style
style: {
display: string;
};style.display
display: string;canPlayAudio
canPlayAudio: boolean;Example
// Basic — merge start-audio behavior into a button.
const { mergedProps, canPlayAudio } = useStartAudio({ props: { children: "Start audio" } });
// Advanced — resume local audio from a user gesture.
function StartAudioButton() {
const { mergedProps, canPlayAudio } = useStartAudio({
props: { className: "lk-button", children: "Start audio" },
});
return !canPlayAudio ? <button {...mergedProps} /> : <span>Audio ready</span>;
}