zmxv / react-native-sound

React Native module for playing sound clips
MIT License
2.8k stars 749 forks source link

How to avoid multiple playing sound in same time ? #738

Open jeremy-habit opened 3 years ago

jeremy-habit commented 3 years ago

:beetle: Description

I want to stop the current playing sound when i start playing an other one

:beetle: What have you tried?

:beetle: Please post your code:

// Please post your code

:bulb: Possible solution

Is your issue with...

Are you using...

Which versions are you using?

Does the problem occur on...

If your problem is happening on a device, which device?

nagarathna7777 commented 1 year ago

Iam unable to stop multiple audios,please help me out.

const onStartPlay = (uri) => { if (!soundPlayer) { const player = new Sound(uri, '', (error) => { if (error) { console.log('Error loading audio:', error); } else { player.play(() => { setIsPlaying(false); setPlayLottie(false) setSoundPlayer(null); }); } }); setIsPlaying(true); setPlayLottie(true); setSoundPlayer(player); } else { soundPlayer.pause() setIsPlaying(false); setPlayLottie(false) setSoundPlayer(null);

}

};