- 安装
- github地址:https://github.com/zmxv/react-native-sound
- 项目根目录
npm install react-native-sound --save
然后
react-native link react-native-sound
如果该步骤发生错误则
-
npm install -g react-native-cli
按照官方文档执行到这安装就完成了但是在项目中引入后发生报错
undefined is not an object (evaluating 'RNSound.IsAndroid')
这个时候需要进入ios文件夹运行pod install
cd ios pod install
2. 使用
-
创建sound.js文件
-
import Sound from 'react-native-sound' export function player (url) { // Enable playback in silence mode Sound.setCategory('Playback') // Load the sound file 'whoosh.mp3' from the app bundle // S