I want to stop the sound player whenever I move to next screen in app.
const [shallPlay, setPlay] = useState(true);
useEffect(() => {
if (shallPlay) {
try {
SoundPlayer.playSoundFile("om_namo`your text`_venkateshaya", ".mp3");
} catch (e) {
console.log(`cannot play the sound file`, e);
}
} else {
SoundPlayer.stop();
}
}, [shallPlay]);
<TouchableOpacity
onPress={() => {
setPlay(!shallPlay);
}}
>
I am new to react native. Unable to find the solution