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

How to avoid multiple playing sound in same time ?

Open jeremy-habit opened this issue 4 years ago • 1 comments

: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...

  • [ ] iOS
  • [ ] Android
  • [ ] Windows

Are you using...

  • [x] React Native CLI (e.g. react-native run-android)
  • [ ] Expo
  • [ ] Other: (please specify)

Which versions are you using?

  • React Native Sound:
  • React Native:
  • iOS:
  • Android:
  • Windows:

Does the problem occur on...

  • [ ] Simulator
  • [x] Device

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

  • Device:

jeremy-habit avatar Aug 02 '21 10:08 jeremy-habit

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);

}

};

nagarathna7777 avatar Jul 25 '23 07:07 nagarathna7777