🚨Sound keeps playing repeatedly, even when stopped🚨
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.