React-native-sound: Sound does not work after playing more than 10 times

Created on 23 May 2019  路  2Comments  路  Source: zmxv/react-native-sound

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

question

Most helpful comment

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

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

All 2 comments

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

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

 if (this.lastTrack) {
      this.lastTrack.release();
      this.lastTrack = null;
    }
Was this page helpful?
0 / 5 - 0 ratings