E-Kuerschner / useAudioPlayer

React hooks for controlling audio on the web
MIT License
315 stars 35 forks source link

expose howl instance via the API #50

Closed pozymasika closed 3 years ago

pozymasika commented 3 years ago

Is your feature request related to a problem? Please describe.

I was trying to set the playback rate but there's no method to do this via the useAudioPosition / useAudioPlayer hooks. Howler.js exposes this method via .rate() method

Describe the solution you'd like

expose the howler player instance in the useAudioPlayer hook so it's easy to access all other methods i.e

const { player } = useAudioPlayer();
function onChangeRate(rate) {
   player.rate(rate);
}

alternatively, you can just add rate function:

const { rate } = useAudioPosition();
function onChangeRate(rate) {
   rate(rate);
}

Describe alternatives you've considered I had to get the howler instance via the global Howler._howls object:

function onChangeRate(rate) {
   const Howler = window.Howler;
   const howl = Howler._howls.find((h) => h._src === my_src);
   howl.rate(rate);
}

Additional context Add any other context or screenshots about the feature request here.

E-Kuerschner commented 3 years ago

@pozymasika thanks for the request! I think this problem will keep arising where developers request an unimplemented method from the underlying library. If I keep taking these up i will end up just copying the howler API one-to-one. I'm thinking this is evidence enough that we need an escape hatch to access the underlying howler object if needed. I'll add this to the next batch of changes I release.

pozymasika commented 3 years ago

@E-Kuerschner thanks for looking at this and adding the escape hatch! 👏

phemartin commented 1 year ago

@E-Kuerschner +1! - Looking forward for rate to be exposed globally! (: