UNPKG

@mrmartineau/use-sound

Version:

The web needs more (tasteful) sounds!

43 lines (39 loc) 910 B
import { Howl } from 'howler'; declare type SpriteMap = { [key: string]: [number, number]; }; declare type HookOptions<T = Record<string, unknown>> = T & { id?: string; volume?: number; playbackRate?: number; interrupt?: boolean; soundEnabled?: boolean; sprite?: SpriteMap; onload?: () => void; }; interface PlayOptions { id?: string; forceSoundEnabled?: boolean; playbackRate?: number; } declare type PlayFunction = (options?: PlayOptions) => void; interface ExposedData { sound: Howl | null; stop: (id?: string) => void; pause: (id?: string) => void; unlock: () => void; duration: number | null; } declare type ReturnedValue = [PlayFunction, ExposedData]; declare function useSound( src: string | string[], { volume, playbackRate, soundEnabled, interrupt, onload, ...delegated }?: HookOptions ): ReturnedValue; export { useSound as default };