zmxv / react-native-sound

React Native module for playing sound clips
MIT License
2.79k stars 747 forks source link

Linking is not working, it doesnt play without using metro and manual installing notes needs to update #771

Open osh91 opened 2 years ago

osh91 commented 2 years ago

:beetle: Description

There are three things that need to update.

react-native link doesn't work. It only linked to settings.gradle but the rest of it didn't work. Instead, I went to read Manual Installation Notes: https://github.com/zmxv/react-native-sound/wiki/Installation and found out that it didn't work it too.

The text about Mainapplication.java. Before it was ArrayList but now it is a List and I am not not really sure it should be like this....

  @Override
                protected List<ReactPackage> getPackages() {
                    @SuppressWarnings("UnnecessaryLocalVariable")
                    List<ReactPackage> packages = new PackageList(this).getPackages();
                    // Packages that cannot be autolinked yet can be added manually here, for example:
                    // packages.add(new MyReactNativePackage());
                     packages.add(new RNSoundPackage()); // <--- is this correct?!
                    return packages;
                }

In this way React Native crash because it doesn't like to

If I am doing without manual linking.

 Sound.setCategory('Playback');
const ding = new Sound(require("../../assets/music-ui/notify.mp3"), Sound.MAIN_BUNDLE, error => console.log(error + "something went wrong"));

 const App = () => {

  useEffect(() => {
    // ding.setVolume(1);
    // return () => {
      ding.release();
    // };
  }, []);

  const playPause = () => {
    ding.play(success => {
      if (success) {
        console.log('successfully finished playing');
      } else {
        console.log('playback failed due to audio decoding errors');
      }
    });
  };

It works but if I stop running metro and using the app it doesn't play anything. I am guessing because it didn't link properly. I can't find folder raw where the sound it (android/src/main/res/) nor anywhere

Are you using...

Which versions are you using?

Does the problem occur on...

If your problem is happening on a device, which device?

pe-johndpope commented 2 years ago

I think if you specify full path - you should use '' instead of Sound.MAIN_BUNDLE.