zmxv / react-native-sound

React Native module for playing sound clips
MIT License
2.79k stars 748 forks source link

Fail to play a short sound #602

Open earlquadra8 opened 5 years ago

earlquadra8 commented 5 years ago

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

Are you using...

Which versions are you using?

Does the problem occur on...

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

paulmelnikow commented 5 years ago

Hi! Could you post your code, please?

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

QShengW commented 5 years ago

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

paulmelnikow commented 5 years ago

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

deavial commented 5 years ago

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

MariusCatanoiu commented 4 years ago

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.

alz10 commented 2 years ago

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

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