react-native-sound: RNSound.IsAndroid bug

React Native - 0.42.0 React Native Sound - 0.9.1

I have only this snippet of code, nothing special:

const whoosh = new Sound(requireAudio, (error) => {
            if (error) {
                console.log('error', error);
            } else {
                whoosh.setSpeed(1);
                console.log('duration', whoosh.getDuration());
                whoosh.play(() => whoosh.release());
            }
        });

but the error is shown when it’s trying to import the module, not on execution screen shot 2017-03-07 at 1 41 09 pm

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 1
  • Comments: 16 (2 by maintainers)

Most upvoted comments

Manually adding libRNSound to ‘Linked Farmeworks…’ in XCode resolved for me screen shot 2018-02-20 at 10 14 25 pm

For anyone stuck at this, you are probably forgetting rebuilding. ie: Uninstalling the APK and running react-native run-android to build and deploy apk again.

Native android libraries that you just linked need to be deployed. They can’t be hot-reloaded.

I had this problem and found that react-native link react-native-sound had missed adding a line to the getPackages() method in MainApplication.java (deeply nested under the android directory of the RN project):

+       new RNSoundPackage()

This obviously prevented the native module from loading, causing it to be undefined in the JS. I’m guessing there are myriad ways the link command could fail. I figured out this specific problem by going through the Android native module docs here:

http://facebook.github.io/react-native/docs/native-modules-android.html

as @radik said just drag your react-native-sound project to <your-project>.xcworkspace in libraries after that from root project file select linked frameworks and libraries add libRNSound.a file rebuild your project run your project
it’s not bad also check this repo

Are you using create-react-native-app? If so, your whole project needs to be pure JavaScript, and it won’t work with react-native-sound.

What are the limitations of Create React Native App?

The main limitation of a Create React Native App project is that it must be written in pure JavaScript and not have any dependencies which rely on custom native code (i.e. ones which require running react-native link to work). This allows the projects to load directly on a phone without native compilation, and also means that it’s not necessary to install or use Android Studio or Xcode.

https://github.com/react-community/create-react-native-app#what-are-the-limitations-of-create-react-native-app

Yes, I did. Hese is the output:

react-native link react-native-sound
Scanning 665 folders for symlinks in /Users/user/Workspace/MyApp/node_modules (5ms)
rnpm-install info Linking react-native-sound android dependency 
rnpm-install info Android module react-native-sound has been successfully linked 
rnpm-install info Linking react-native-sound ios dependency 
rnpm-install info iOS module react-native-sound has been successfully linked 
rnpm-install info Linking assets to ios project 
rnpm-install info Linking assets to android project 
rnpm-install info Assets have been successfully linked to your project 

I rebuild the project and again linking:

rnpm-install info Android module react-native-sound is already linked 
rnpm-install info iOS module react-native-sound is already linked 

And again I have the same error.

I created a new app in React Native 0.60 and I encountered this issue once. To fix the issue I ran rm -rf ios/build and then react-native run-ios, which fixed it.

If you’re still experiencing this issue, please open a new issue with steps to reproduce. If you have a universal solution, please open a pull request with a documentation update.

I’m running it on IOS simulator and getting this error. Linked the files and re-build the app, the error shows up when I import the library

在安卓上还是报一样的错,我已经link了,这该怎么解决呢?

This suggests the library isn’t linked. Have you run react-native link and re-built the application?