zmxv / react-native-sound

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

Android: setNumberOfLoops(1) never stops #641

Open scarlac opened 4 years ago

scarlac commented 4 years ago

:beetle: What is the observed behavior?

Using sound.setNumberOfLoops(1) causes sound to never stop playing.

:beetle: What is the expected behavior?

Using sound.setNumberOfLoops(1) should play the sound once, then loop once. A total of 2 plays.

:beetle: Please post your code:

Sound.setCategory('Playback');
const sound = new Sound('tada.mp3', Sound.MAIN_BUNDLE, error => {
  sound.setNumberOfLoops(1); // This will cause infinite repetitions
  sound.play();
});

:bulb: Does the problem have a test case?

I don't have a public test case. It's clear why the issue occurs though, because the looping is claimed as supported by android in README file but in code it clearly isn't.

Native code in rn-sound repo that clearly doesn't support number of loops:

Sound.prototype.setNumberOfLoops = function(value) {
  this._numberOfLoops = value;
  if (this._loaded) {
    if (IsAndroid || IsWindows) {
      RNSound.setLooping(this._key, !!value);
    } else {
      RNSound.setNumberOfLoops(this._key, value);
    }
  }
  return this;
};

However docs say:

image

:bulb: Possible solution

Fix and Merge PR that makes Android support loops, or update documentation.

:bulb: Is there a workaround?

No workaround possible.

:bulb: If the bug is confirmed, would you be willing to create a pull request?

One already exists.

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?

amed commented 4 years ago

Same here: react-native: 0.61.5 react-native-sound: 0.11.0

I had to add a hacky solution, by start playing and pausing after mounting the player.

vrizawahyu22 commented 3 years ago

Same the issue

helrabelo commented 2 years ago

Also having this issue!

williamswebworks commented 2 years ago

was there any solution to this issue?

scarlac commented 2 years ago

@williamswebworks Sorry, I managed to work around it by manually stopping the sound.