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

Fail to play a short sound

Open earlquadra8 opened this issue 6 years ago • 7 comments

:beetle: Description

I want it to play a sfx, which shorter than a second, whenever I click a button. I wonder if the sound clip length have a lower limit.

:beetle: What have you tried?

When I try to use the play() with a .mp3 length longer than 1 sec, it works fine, but when I try to use a shorter .mp3 length shorter than 1 sec, the play() success callback return false.

Is your issue with...

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

Are you using...

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

Which versions are you using?

  • React Native Sound: "^0.11.0"
  • React Native: "0.59.5"
  • iOS:
  • Android: 6.0.1
  • Windows:

Does the problem occur on...

  • [ ] Simulator
  • [ v ] Device

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

  • Device:

earlquadra8 avatar Jul 23 '19 04:07 earlquadra8

Hi! Could you post your code, please?

There is not a lower limit on the duration of a sound file.

paulmelnikow avatar Jul 23 '19 17:07 paulmelnikow

const thisPlay = new Sound("http://image.mypays.cn/data/lsy/sound/aa_bb.mp3",null, e => { if (e) { console.log(e) return }; thisPlay.play(() => thisPlay.release()); });

{extra: -2147483648, what: 1}

React Native Sound:“^ 0.11.0” React Native:“0.59.9” Android Problem

QShengW avatar Aug 02 '19 08:08 QShengW

@QShengW Could you post a new issue and fill out the full template, please?

paulmelnikow avatar Aug 02 '19 15:08 paulmelnikow

@earlquadra8 I had this issue as well (loaded from the raw directory). Exact same error. After a very long investigation on this I found the issue is with Android not with this package. I used a mp3 validator and found out that if an mp3 doesn't have at least 5 mpeg frames it is invalid. iOS and macOS don't care, but Android does and won't load it. I had to switch my 1 second mp3's that had 1 - 2 mpeg frames out with wav versions and it works great.

deavial avatar Aug 08 '19 10:08 deavial

same issue here.

let's say you have a multiple flip effect with a delay of 400ms between the flips. flip = new Sound('flip.wav', Sound.MAIN_BUNDLE);

flip.play(); setTimeout(() => { flip.play(); }, 400);

the sound will work just for the first play. but not for the one inside the timeout. but if the timeout is > 1000ms, it works fine.

ios and android are having the same behaviour in this case.

MariusCatanoiu avatar Jan 10 '20 13:01 MariusCatanoiu

Here's how i achieve it using a pop sound effect

onPress={() => {
   popSFX.stop();
   popSFX.play();
}}

alz10 avatar Apr 13 '22 09:04 alz10

Same here

priami93 avatar Oct 26 '24 11:10 priami93