How do you () sound file in React Native?

I use https://github.com/zmxv/react-native-sound to play sounds in my iOS (and Android) application and I try to include sound files through the React Native asset system, but when I call:

var sound = require('./sound.mp3');

I get an error message:

Unable to resolve module. /sound.mp3 from [project] /index.ios.js: Invalid [project] /sound.mp3 directory

I have an MP3 file in the correct (root) directory of my project, the same path to the file that the error prints. I tried putting it in other directories.

According to this stream , it looks like the sound files can also be packed using the require () function?

Just run the test, requiring the image to work fine: var image = require('./image.png');

+6
source share
1 answer

The only thing that worked for us was to place the audio files that we want to send using the application to the assets directory, and then Xcode copy these files to the application package at build time. At this point, you can calculate the full path to the file using something like reaction-native-fs, and provide this for the reaction-native sound.

0
source

All Articles