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:-
android/app/src/main/java/.../MainApplication.java
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
.
Fixed this bug on react-native 0.61.5: add in Podfile
pod 'RNSound', :path => '../node_modules/react-native-sound'
pod install
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With