lhz516 / react-h5-audio-player

React audio player component with UI. It provides time indicator on both desktop and mobile devices.
https://codepen.io/lhz516/pen/dyGpmgP
MIT License
587 stars 91 forks source link

"onPlayError" gets called before "onPlay" if src is empty #192

Closed matteomontipo closed 1 year ago

matteomontipo commented 1 year ago

Hi, so I just found out that if the src is empty, the function i'm calling within the onPlay parameter doesn't fire at all, found out that's because it goes into the onPlayError and stops there.

My case: I play the audio with some custom logic throughout a function, which is called within onPlay as onPlay={() => handlePlay()} and I'd like to decide what happens if the user clicks it when the app just loaded and no mp3 src has been set yet.

It'd be nice to have more control of what happens when the Play button is clicked.

lhz516 commented 1 year ago

onPlay listens to exactly the play event which means the event fires when playback has begun, not when clicking the play button. Using onPlayError to capture empty src is fine. Is there any other use cases that cannot be covered by these two events?