zmxv / react-native-sound

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

Sound doesn't stop playing #636

Closed tamagokun closed 4 years ago

tamagokun commented 4 years ago

:beetle: Description

After calling sound.play() the sound never stops, even have set number of loops to 0 and manually calling stop()

:beetle: What is the observed behavior?

The sound starts playing and continues to loop until I remove the component using it from memory.

:beetle: What is the expected behavior?

The sound defaults to numberOfLoops = 0 so it should stop the sound after playing if it once. If that isn't an option, should be able to at least stop it after it is done playing (i.e. sound.play(() => sound.stop());

:beetle: Please post your code:

// Please post your code
import * as React from "react";
import Sound from "react-native-sound";

export default class Screen extends React.Component {
  componentDidMount() {
    const sound = new Sound("beep.mp3", Sound.MAIN_BUNDLE, () => {
      sound.play();
    });
  }

  render() {
    return <View />;
  }
}

:bulb: Does the problem have a test case?

:bulb: **Possible solution**

:bulb: Is there a workaround?

Not that i'm aware of.

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

If it's in the js, sure, if it's in the native code, less sure.

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?

Have not tested on a device

tamagokun commented 4 years ago

😞 was able to pinpoint why this failed. I had tried playing audio using react-native-video, which worked perfectly, but I forgot to remove that code while testing react-native-sound. Disregard!