summit-kit
Version:
A React component library for building modern web applications with an earthy and outdoorsy flair.
50 lines (49 loc) • 1.85 kB
TypeScript
interface UseAudioOptions {
src: string;
volume?: number;
loop?: boolean;
preload?: boolean;
autoplay?: boolean;
stereo?: number;
fadeInDuration?: number;
}
interface UseAudioReturn {
play: () => void;
pause: () => void;
stop: () => void;
seek: (seek: number) => void;
isPlaying: boolean;
currentTime: number;
volume?: number;
setVolume: (volume: number) => void;
setStereo: (pan: number) => void;
}
/**
* React hook for managing audio playback using the Web Audio API.
*
* @param {UseAudioOptions} options - Configuration options for the audio instance.
* @param {string} options.src - The source URL of the audio file.
* @param {number} [options.volume=1] - Initial volume (0.0 to 1.0).
* @param {boolean} [options.loop=false] - Whether the audio should loop.
* @param {boolean} [options.preload=true] - Whether to preload the audio.
* @param {boolean} [options.autoplay=false] - Whether to autoplay the audio on load.
* @param {number} [options.stereo=0] - Initial stereo pan (-1.0 left to 1.0 right).
* @param {number} [options.fadeInDuration] - Fade in duration in seconds.
*
* @returns {UseAudioReturn} An object containing playback controls and state:
* - `play`: Function to start playback.
* - `pause`: Function to pause playback.
* - `stop`: Function to stop playback.
* - `seek`: Function to set the current playback position.
* - `isPlaying`: Boolean indicating if audio is currently playing.
* - `currentTime`: Current playback time in seconds.
* - `setVolume`: Function to set the volume.
* - `setStereo`: Function to set the stereo pan.
*
* @example
* ```tsx
* const { play, pause, isPlaying } = useAudio({ src: 'audio.mp3', volume: 0.5 });
* ```
*/
export declare const useAudio: ({ src, ...options }: UseAudioOptions) => UseAudioReturn;
export {};