react-native-sound icon indicating copy to clipboard operation
react-native-sound copied to clipboard

🚨Sound keeps playing repeatedly, even when stopped🚨

Open iambigmarn opened this issue 1 month ago • 3 comments

Good day, Please I used the package in my react native project but on some devices the sound keeps playing repeatedly even when stopped. My Samsung A31 stops playing the sound when i stop it. But on my Nokia G20, the sound keeps playing repeatedly even when stopped.

const ringtoneRef = useRef<Sound | null>(null);

useEffect(() => { const ringtone = new Sound('sound.mp3', Sound.MAIN_BUNDLE, (error) => { if (error) { console.log('Failed to load ringtone', error); return; } // Play the sound in a loop ringtone.setNumberOfLoops(-1); // -1 means infinite loop ringtone.play((success) => { if (!success) { console.log('Playback failed'); } }); });

ringtoneRef.current = ringtone;

// Cleanup: stop and release the sound when component unmounts
return () => {
  if (ringtoneRef.current) {
    ringtoneRef.current.stop(() => {
      ringtoneRef.current?.release();
    });
  }
};

}, []);

const hangUp = async () => { // Stop ringtone before hanging up if (ringtoneRef.current) { ringtoneRef.current.stop(() => { ringtoneRef.current?.release(); }); } if (!call) return; await call.leave(); await call.endCall(); InCallManager.stop(); navigation.goBack(); };

Please help look into it.

iambigmarn avatar Dec 10 '25 19:12 iambigmarn