Skip to content

Instantly share code, notes, and snippets.

@emanueleDiVizio
Created May 28, 2020 20:06
Show Gist options
  • Select an option

  • Save emanueleDiVizio/633226f920004c2c829ea126fbf8833e to your computer and use it in GitHub Desktop.

Select an option

Save emanueleDiVizio/633226f920004c2c829ea126fbf8833e to your computer and use it in GitHub Desktop.
const useAudioPlayer = (fileName) => {
const playerRef = useRef(null);
useEffect(() => {
playerRef.current = loadPlayer(fileName);
return () => {
playerRef.current.destroy();
};
}, []);
const play = (cb) => playerRef.current.play(cb);
const seek = (time, cb) => playerRef.current.seek(time, cb);
const stop = (cb) => playerRef.current.stop(cb);
return [play, seek, stop];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment