-
Notifications
You must be signed in to change notification settings - Fork 98
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
Can't stop the audio when the component unmounts. #140
Comments
This is an issue even when using a cleanup on useEffect |
(2024) same; I think this might be an issue at the Howler.js level; For some reason it feels like JS loses reference to the sound |
Same issue here |
Same issue, I decided not to use this lib but instead make very simple react component. "use client";
import { useEffect, useRef } from "react";
/**
* How to gain autoplay access.
* https://championcr.com/topic/enable-auto-play/#:~:text=Mac%2C%20and%20Firefox.-,Google%20Chrome,)%E2%80%9D%20to%20%E2%80%9CAllow%E2%80%9C
*/
export function AudioAutoPlayer({
src,
enabled,
loop = true,
}: {
src: string;
enabled: boolean;
loop?: boolean;
}) {
const audioRef = useRef<HTMLAudioElement>(null);
useEffect(() => {
if (audioRef.current) {
if (enabled) {
audioRef.current.play();
} else {
audioRef.current.pause();
}
}
return () => {
if (audioRef.current) audioRef.current.pause();
};
}, [enabled]);
return <audio ref={audioRef} src={src} autoPlay={enabled} loop={loop} />;
} Above code works just as much as I need. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm using use-sound in Vite project.
Can't stop the Audio, when the component unmounts. Need help with this.
The text was updated successfully, but these errors were encountered: