There is a library called the react-native-sound which we can use to play sound clips in both iOS and Android.
To run and install the library, follow the given steps:
- On the command prompt, run the install command npm install react-native-sound --save
- Now to link it to your existing project, run react-native link react-native-sound
To use the library you will have to create a helper file such as audio.js. This will import the library react-native-sound and you can export any method from the library to use different sound. The same library can be used to implement the 'pull to refresh' button in the app.
Note: For iOS development, make sure that you have added the Sound.setCategory('Ambient', true);. This is because, in iOS, the app will by default stop playing your sound if in case there is music playing in the background. If you add the given line of code, it will make sure that sound will play despite music playing.