react-h5-audio-player icon indicating copy to clipboard operation
react-h5-audio-player copied to clipboard

Setting src attribute to null/undefined does not stop playback (but an empty string does)

Open Dooblr opened this issue 1 year ago • 2 comments

Setting src on AudioPlayer to undefined does not stop playback as expected. However, this does work to pause and clear the src:

const audioPlayerRef = useRef<AudioPlayer>(null)

useEffect(() => {
  if (isLoading) {
    if (audioPlayerRef.current && audioPlayerRef.current.audio.current) {
      audioPlayerRef.current.audio.current.pause()
      audioPlayerRef.current.audio.current.src = ''
    }
  }
}, [isLoading])
... 
// in the render
<AudioPlayer
  ref={audioPlayerRef}
  src={footerAudioURL}
  autoPlayAfterSrcChange={true}
/>

Environment

Package version: 3.9.1 React version: 18.2.0 Browser and its version: 121.0.6167.160 (Official Build) (arm64) OS and its version: macOS Sonoma 14.1.2

Dooblr avatar Feb 14 '24 19:02 Dooblr