react-native-sound does not work on ios emulator

1.2k Views Asked by At

the below code works fine on android and the sound is played....however on ios simulator it does not. Ive added my sound file to Xcode project, and no error is caught.....when I step through code, it runs this.sound.play() successfully and callback function is called...however you dont hear any sound.

import Sound from 'react-native-sound';

sound = new Sound('sound.mp3');
try {
    this.sound.setCategory('Playback');
    this.sound.play(() => {
       this.sound.stop();
       this.sound.release();
    });
    } catch (e) {
       console.log('cannot play the sound file', e);
    }
2

There are 2 best solutions below

1
On

If you have the newest Xcode 11.6, did you try messing around with the settings in

Simulator > I/O > Audio Output

(if it's an older xcode, maybe Simulator > Hardware > Audio Output)?

0
On

Where you have put the sound file, please note that the sound clip files should be placed under the directory android/app/src/main/res/raw for android and For iOS, Add your sounds to Resources in Xcode project