Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Dooblr opened this issue Feb 14, 2024 · 2 comments
Assignees
Labels

Comments

@Dooblr
Copy link

Dooblr commented Feb 14, 2024

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
Copy link
Author

Dooblr commented Feb 14, 2024

Setting it as an empty string actually did work. I didn't think to try that until I posted this. Still, I feel like it should stop and reset playback if set to undefined or null as well.

@Dooblr Dooblr changed the title Setting src attribute to undefined does not stop playback (workaround included) Setting src attribute to null/undefined does not stop playback (but an empty string does) Feb 14, 2024
@lhz516
Copy link
Owner

lhz516 commented Feb 19, 2024

Yea that makes sense. Let me take a look

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants