mirror of
https://github.com/remvze/moodist.git
synced 2025-12-19 18:04:13 +00:00
feat(audio): improve resource cleanup for Safari compatibility
This commit is contained in:
parent
81d9d7ca03
commit
608e9aa806
1 changed files with 16 additions and 5 deletions
|
|
@ -100,9 +100,22 @@ export function BinauralModal({ onClose, show }: BinauralProps) {
|
||||||
const stopSound = useCallback(() => {
|
const stopSound = useCallback(() => {
|
||||||
if (!isPlaying) return;
|
if (!isPlaying) return;
|
||||||
|
|
||||||
|
// Stop oscillators
|
||||||
leftOscillatorRef.current?.stop();
|
leftOscillatorRef.current?.stop();
|
||||||
rightOscillatorRef.current?.stop();
|
rightOscillatorRef.current?.stop();
|
||||||
audioContextRef.current?.close();
|
|
||||||
|
// Unload oscillators
|
||||||
|
leftOscillatorRef.current = null;
|
||||||
|
rightOscillatorRef.current = null;
|
||||||
|
|
||||||
|
// Close and unload AudioContext
|
||||||
|
if (audioContextRef.current) {
|
||||||
|
audioContextRef.current.close();
|
||||||
|
audioContextRef.current = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unload gain node
|
||||||
|
gainNodeRef.current = null;
|
||||||
|
|
||||||
setIsPlaying(false);
|
setIsPlaying(false);
|
||||||
}, [isPlaying]);
|
}, [isPlaying]);
|
||||||
|
|
@ -127,11 +140,9 @@ export function BinauralModal({ onClose, show }: BinauralProps) {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Cleanup when component unmounts
|
// Cleanup when component unmounts
|
||||||
return () => {
|
return () => {
|
||||||
if (isPlaying) {
|
|
||||||
stopSound();
|
stopSound();
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}, [isPlaying, stopSound]);
|
}, [stopSound]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Update frequencies when a preset is selected
|
// Update frequencies when a preset is selected
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue