Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not working on RN 0.30 #57

Closed
caglarozen opened this issue Aug 4, 2016 · 14 comments
Closed

Not working on RN 0.30 #57

caglarozen opened this issue Aug 4, 2016 · 14 comments

Comments

@caglarozen
Copy link

Hi,
i tried install on android. It build successfully but i keep getting
"undefined is not an object (evaluating 'RNSound.IsAndroid') " error on emulator.
Can anyone help me with this issue?

@rowinf
Copy link

rowinf commented Aug 8, 2016

It's working for me in 0.30. I had the same error, but I found something wrong with my android project configuration. For me, I forgot my import statement in MainApplication.java and my compile project(':RNSound') was in the wrong place. Hope that helps someone!

@nycoliver
Copy link

I get this issue on ios with rnpm install react-native-sound but manual installation seems to work fine.

@jlsandri
Copy link

jlsandri commented Sep 6, 2016

@zmxv Also experiencing this bug on RN 0.30 >. Any word on a solution that doesn't involve subverting npm?

@nycoliver
Copy link

@kilgoremaskreplica
Try removing the library and reinstall with
npm install react-native-sound
rnpm link react-native-sound

@ghost
Copy link

ghost commented Sep 19, 2016

Working for me on RN 0.32. I solved this issue by manually linking, right this:

android/settings.gradle

include ':RNSound', ':app'
project(':RNSound').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-sound/android')

android/app/build.gradle

dependencies {
...
    compile project(':RNSound')
...

android/app/src/main/java/com/myApp/MainApplication.java

. . .
import com.zmxv.RNSound.RNSoundPackage;
. . .
protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
          new MainReactPackage(),
          . . .
          new RNSoundPackage()
      );
}

@2ducanhpham
Copy link

react native 0.34 not working

@BenjaminPaap
Copy link

At least for iOS I can confirm that this library is working on react native 0.34.1

@2ducanhpham
Copy link

i try. IOS is working, but Android not working

@cindybinle2
Copy link

@snsekar
Copy link

snsekar commented Dec 11, 2016

I am also facing same issue. No solutions described above working for me

@tsanthosh
Copy link

@chachachacha @rowinf @nycoliver @kilgoremaskreplica @cavilaho

Had the same issue on iOS & Android and was able to fix it.

iOS: My fault I did not choose my target correctly i.e. under built target I had myProjectTests selected rather than myProject. Once I fixed this I did not receive any error on iOS.

Android: According to RN docs RNSound package should be added to getPackages() method of MainApplication.java rather than MainActivity.java. Once I changed this the error went away.

I am using RN version 0.39.2.

Hope this helps.

@bntzio
Copy link

bntzio commented Dec 13, 2016

I was able to fix the issue undefined is not an object (evaluating 'RNSound.IsAndroid') on iOS 💥.

What I did was just to reinstall react-native-sound npm install react-native-sound --save and instead of linking it to xcode/android manually, I used react-native link react-native-sound to link it automatically, after that the error disappeared.


Just for reference, to play a sound just open xcode, and drag-drop your sound file into the root of the xcode project library:

--AppName
----Libraries
----AppNameTests
----Products
----Resources
----SoundFile.wav

Then tick Copy items if needed, Create folder references and in add to targets select your AppName, then click finish to add it to your project.

Now go to your Project Build Phases and make sure your sound file is listed on Copy Bundle Resources, if it's not in there, add it by drag-drop your sound file.

Now everything should be ready, just don't forget to run your app in xcode to build it.

Here's a sample code I'm using in my React Native app:

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('tap.wav', 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>
    );
  }
}

And now it's 100% working, I tried it on iOS only, but the original error should be gone on both platforms.

Just don't forget to run the project with xcode, then you can use react-native run-ios, that's all!

Hope this is helpful! 😊

@peternann
Copy link

peternann commented Jan 31, 2017

If you followed the READMe accurately, you might have added the getPackages method into MainActivity.java

The README is wrong (at the time of typing).
The correct class to add to is MainApplication.java

I think this is the reason that react-native link react-native-sound works - It mods the correct file.

Please correct the README ASAP. Shitty trap for new users...

@benvium
Copy link
Collaborator

benvium commented Feb 10, 2017

Thanks for this. The readme has been updated now. It's now recommended to use react-native link react-native-sound which means you don't need to manually perform the install steps any more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests