zmxv / react-native-sound

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

Sound does not work after playing more than 10 times #574

Open IWTBCAdeveloper opened 5 years ago

IWTBCAdeveloper commented 5 years ago

I follow this issue https://github.com/zmxv/react-native-sound/issues/565 but it still doesn't work. What should I do now. Please help

environment: react-native: 0.51.0 android 7 react-native-sound: 0.10.12

function* handleLoadSound() {
  Sound.setCategory('Playback');
}

function* handlePlaySound(action) {
  const { name } = action.payload;
  const filename = `${name}.mp3`;
  Sound.setCategory('Playback');

  let sound = new Sound(filename, Sound.MAIN_BUNDLE, (error) => {
    if (error) {
      console.log('failed to load the sound', error);
      return;
    }

    sound.play((success) => {
      if (success) {
        console.log('successfully finished playing');
        sound.release()
      }
    });
  });
}

Thanks a lot

maitrungduc1410 commented 5 years ago

I'm testing it with remote URL and it works fine, I test with about 30 times.

Here is my code (quite short, you should read)

Hope this help

samad324 commented 5 years ago

use .release() method before starting new audio track! like

 if (this.lastTrack) {
      this.lastTrack.release();
      this.lastTrack = null;
    }