RNSound.IsAndroid error (React Native)
Am getting this error- undefined is not an object(evaluating RNSound.IsAndroid)
I have already used this- react-native link react-native-sound
my index.android.js code is-
import React from 'react';
import { TouchableWithoutFeedback, Text } from 'react-native';
import Sound from 'react-native-sound';
class MyComponent extends Component {
playSound() {
const mySound = new Sound('x.mp3', Sound.MAIN_BUNDLE, (e) => {
if (e) {
console.log('error', e);
} else {
console.log('duration', mySound.getDuration());
mySound.play();
}
});
}
render() {
return (
<TouchableWithoutFeedback onPress={this.playSound.bind(this)}>
<Text>Play Sound!</Text>
</TouchableWithoutFeedback>
);
}
}
Most of the time this error means the package was not linked correctly.
To confirm if this is the case:-
- Go to
android/app/src/main/java/.../MainApplication.java
- Ensure you have this import at this file
import com.zmxv.RNSound.RNSoundPackage;
Ensure this method has this call
new RNSoundPackage()
as illustrated below.@Override protected List<ReactPackage> getPackages() { return Arrays.<ReactPackage>asList( new MainReactPackage(), new RNSoundPackage() // <-- New ); }
If this doesn't work follow the manual process described in this wiki here: https://github.com/zmxv/react-native-sound/wiki/Installation
I resolved this by stopping react packager, run following commands:
rm -rf node_modules/
npm install
react-native link react-native-sound
rn-nodeify --install --hack
clean project and re-build application. rn-nodeify
was created for non-react native packages, but in my case this works for react-native-sound
.
Solved it:
- Delete node_modules folder of your project.
Update the react-native-sound dependency in the package.json file as :
"react-native-sound": "git+ssh://git@github.com:zmxv/react-native-sound.git#HEAD"
fire
npm install
.
Comments
Post a Comment