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

Loop not working for the first play

Open Kerumen opened this issue 10 years ago • 3 comments

I have a weird issue, the same as described here.

The loop parameter is not taken in consideration until the first play, even though the numberOfLoops property is correct (I logged it just before the play).

The temporary workaround I found JS side (without touching the library) is:

const sound = new Sound('alert.m4a', Sound.MAIN_BUNDLE, () => {
  sound.setNumberOfLoops(-1);
  sound.play(() => {
    sound.play();
  });
});

The second play take into account the numberOfLoops property. On the SO post, the OP found a native workaround by replacing the player. Maybe it's worth looking into this.

Kerumen avatar Apr 29 '16 13:04 Kerumen

Replacing the player sounds more hacky than your JS workaround.

zmxv avatar Apr 29 '16 18:04 zmxv

Hi there,

I have got the same issue. Did you find a way to fix this issue ?

The workaround I found for now is to play the sound with no volume inside the constructor callback and set the volume back to normal when play ends.

Cheers

tuxtux00 avatar Sep 06 '16 20:09 tuxtux00

I added a test to react-native-sound demo, and it worked as intended on iOS and Android https://github.com/zmxv/react-native-sound-demo/pull/5.

benvium avatar Mar 03 '17 10:03 benvium