joshwcomeau / use-sound

A React Hook for playing sound effects
MIT License
2.76k stars 98 forks source link

Add support for multiple sources (proxy to Howl) #52

Closed TamoshaytisV closed 3 years ago

TamoshaytisV commented 3 years ago

Issue: https://github.com/joshwcomeau/use-sound/issues/17

Description: This PR allows passing multiple source files to the Howl constructor (see howler.src)

Usage:

import soundfile1 from './assets/sounds/test.ogg';
import soundfile2 from './assets/sounds/test.mp3';

const Player = () => {
  const [play] = useSound([soundfile1, soundfile2]);

  return <div onClick={() => play()}>Play</div>;
};

...

<Player />

Old behavior stays and prev codebase should not be affected

const [play] = useSound(soundfile1);
cmcurran commented 3 years ago

@joshwcomeau please review

joshwcomeau commented 3 years ago

Thanks @TamoshaytisV!

joshwcomeau commented 3 years ago

Shipped in 2.1.0, though I haven't added anything to the docs about it. Debating if it's worth mentioning (are there reasons besides browser support that someone would want to do this? I believe mp3s are widely-enough supported that it feels too niche to be worth prime real-estate in the README, but maybe there are other reasons to do this?)

0xdevalias commented 3 years ago

MP3’s are widely supported, but the way I would use MP3’s with this is as the last resort fallback option.

The way howler suggests using it is putting the more ‘unique’/highly compressed/etc version forst, then having MP3/similar as your ‘legacy browser’ fallback.

Not sure if it needs to be in the README directly, but documented would definitely be useful.