-
Notifications
You must be signed in to change notification settings - Fork 748
Installation
First install the npm package from your app directory:
npm install react-native-sound --save
Then link it automatically using:
react-native link react-native-sound
This is not necessary if you have used react-native link
In XCode, right click Libraries. Click Add Files to "[Your project]". Navigate to node_modules/react-native-sound. Add the file RNSound.xcodeproj.
In the Project Navigator, select your project. Click the build target. Click Build Phases. Expand Link Binary With Libraries. Click the plus button and add libRNSound.a under Workspace.
Drag and drop sound files into Project Navigator to add them to the project. Verify that the files are packaged in the app bundle in either way:
- Select a sound file in the Project Navigator, tick the checkbox in the Target Membership list on the right.
- Alternatively, click the build target, click Build Phases, expand Copy Bundle Resources, add the file if it's not already listed.
Run your project (⌘+R).
This is not necessary if you have used react-native link
Edit android/settings.gradle
to declare the project directory:
include ':react-native-sound'
project(':react-native-sound').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-sound/android')
Edit android/app/build.gradle
to declare the project dependency:
dependencies {
...
compile project(':react-native-sound')
}
Edit android/app/src/main/java/.../MainApplication.java
to register the native module:
...
import com.zmxv.RNSound.RNSoundPackage; // <-- New
...
public class MainApplication extends Application implements ReactApplication {
...
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new RNSoundPackage() // <-- New
);
}
For older versions of React Native you need to edit MainActivity.java
instead:
...
import com.zmxv.RNSound.RNSoundPackage; // <-- New
...
public class MainActivity extends Activity implements DefaultHardwareBackBtnHandler {
...
@Override
protected void onCreate(Bundle savedInstanceState){
...
mReactInstanceManager = ReactInstanceManager.builder()
.setApplication(getApplication())
...
.addPackage(new MainReactPackage())
.addPackage(new RNSoundPackage()) // <-- New
...
}