React-native-sound: Rnsound.prepare crash on Android

Created on 26 Jun 2017  路  3Comments  路  Source: zmxv/react-native-sound

RNSound.prepare got 3 arguments, expected 4

This is my code

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

Version 10.0.1
How can i solve this issue ?

Most helpful comment

Okay my memory is kind of fuzzy here but I had this same issue when I was using this module on Ubuntu. The way I fixed it was to go into /node_modules/rn-sound/android/src/main/java/com/zmxv/RNSound/RNSoundModule.java and find the prepare method there.
You'll see
public void prepare(final String fileName, final Integer key, final ReadableMap options, final Callback callback)
I changed this to
public void prepare(final String fileName, final Integer key, final Callback callback)
removing the ReadableMap options. I also removed whatever code in this method used this variable.
I believe this is what fixed it for me there.
Ironically on Windows I'm now having the opposite problem...

Edit:
Another piece to look at is
/node_modules/rn-sound/lib/sound.js
Check out the call to "prepare" there. Count the number of arguments and match them up with what you find in RNSoundModule.java.
You may need to pass options into your new Sound()

P.S. I'm using rn-sound which is the same thing as react-native-sound so if there's confusion here look for that..

tl;dr :
make sure these three have matching arguments:

  • your "new Sound()",
  • rn-sound's call to "prepare" in /lib/sound.js
  • rn-sound's method definition in /android/.../RNSoundModule.java

All 3 comments

Okay my memory is kind of fuzzy here but I had this same issue when I was using this module on Ubuntu. The way I fixed it was to go into /node_modules/rn-sound/android/src/main/java/com/zmxv/RNSound/RNSoundModule.java and find the prepare method there.
You'll see
public void prepare(final String fileName, final Integer key, final ReadableMap options, final Callback callback)
I changed this to
public void prepare(final String fileName, final Integer key, final Callback callback)
removing the ReadableMap options. I also removed whatever code in this method used this variable.
I believe this is what fixed it for me there.
Ironically on Windows I'm now having the opposite problem...

Edit:
Another piece to look at is
/node_modules/rn-sound/lib/sound.js
Check out the call to "prepare" there. Count the number of arguments and match them up with what you find in RNSoundModule.java.
You may need to pass options into your new Sound()

P.S. I'm using rn-sound which is the same thing as react-native-sound so if there's confusion here look for that..

tl;dr :
make sure these three have matching arguments:

  • your "new Sound()",
  • rn-sound's call to "prepare" in /lib/sound.js
  • rn-sound's method definition in /android/.../RNSoundModule.java

Is this still a problem? I can't reproduce this.

No, I did gwitwer's solution and i didn't found any crash. So i'll close this thing. Thanks

Was this page helpful?
0 / 5 - 0 ratings