zmxv / react-native-sound

React Native module for playing sound clips
MIT License
2.78k stars 748 forks source link

RNSound.play must not be null #746

Closed omerkok closed 2 years ago

omerkok commented 2 years ago

:beetle: Description

I am trying to play sound in ios simulator, but I am getting an error as RNSound must not be null. I will ask you to help, there are no problems for android only ios.

:beetle: What have you tried?

301 / 5000

-I did it with automatic linking at first, then I did the manual linking for ios. -I deleted my project folder in -x code->Derivered Data and rebuilt the project. -npm start -- --reset-cache -watchman watch-del-all -delete and rebuild the app but none produced results.

:beetle: Please post your code:

import Sound from 'react-native-sound';

const packageAudio = new Sound('audio1.mp3', Sound.MAIN_BUNDLE, (error) => { if (error) { console.log('failed to load the sound', error); return; } });

<TouchableOpacity
    onPress={() => packageAudio.play()}
    activeOpacity={0.6}
    style={[styles.exitButtonStyle, { backgroundColor: '#2c3e50' }]}>
    <IonIcon
      name='gift-outline'
      size={width * 0.06}
      style={{
        color: '#fafafa',
        alignSelf: 'center',
        marginRight: width * 0.02,
      }}
    />
    <Text style={styles.exitTextStyle}>control</Text>
  </TouchableOpacity>

:bulb: Possible solution

Is your issue with...

Are you using...

Which versions are you using?

Does the problem occur on...

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

omerkok commented 2 years ago

Simulator Screen Shot - iPhone 11 - 2021-09-04 at 18 05 32

omerkok commented 2 years ago

packageAudio.getDuration(), packageAudio.isPlaying() functions such as work only have a problem with play .

dimaischenko commented 2 years ago

@omerkok Did you solve the issue? I started getting these errors recently, although everything was fine before.

bezenson commented 2 years ago

The same of me. Added. Made pod install and added file, but it crashes with error described above

bezenson commented 2 years ago

Ah, ok. Typescript declaration is wrong.

It says that onEnd function is unnecessary: play(onEnd?: (success: boolean) => void): this

But for iOS you actually should define it: yourSound.play(() => {});

dimaischenko commented 2 years ago

Yeah, already figured that out, too. Thank you!