Example of React Native Sound NPM Package | Play Sound Files

Hello guys, In today’s tutorial we would learn about React Native Sound NPM package. The react native sound package is used in react native to Play sound files. Using the sound package we can play MP3, AAC and WAV format audio files. The sound package gives us the functionality to Play, Pause, Stop, drag and drop and many functions. You can see the list of all functions comes with sound package here. The best thing of this package is that we can easily play sound files locally and online.

Contents in this project Example of React Native Sound NPM Package :-

1. First of all we have to install the React Native Sound package in our react native project. So open your project’s main Root directory in Command Prompt or Terminal and execute below command.

2. Now this step is only for iOS users, In our iOS RN project we have to install PODS to link the package with project. So execute the below command in iOS only.

3. Now we have to start coding for the app. So open your project’s main App.js file and import useEffect, View, StyleSheet, Platform, TouchableOpacity and Text component.

4. Import Sound from react native sound package.

5. Creating our main Export default App.

6. Now we have to create 2 local variables named as control_Local and control_Online. We would use each of them as Sound object to play local and online sound files.

7. Creating 1 variable named as localSound to hold the local sound file path.

8. Creating another variable named as onlineSound to hold online sound URL.

9. Creating useEffect() method which works as component did mount and here we would release the sound controller.

10. Creating 2 functions named as playSound_Local() and playSound_onLine() to play sound files.

11. Creating 2 more functions to STOP sound file from playing.

13. Creating return() block, Now here we would design our complete View.

14. Creating Style.

15. Complete Source Code for App.js file :-

Screenshot :-

Example of React Native Sound NPM Package | Play Sound Files