admin管理员组文章数量:1434838
I am trying really hard to play an audio file from my react-native app. Currenty I am trying to use this package:
react-native-sound
But can not get it to work properly, I get this error: Cannot read property IsAndroid of undefined, which it tries to do in sound.js line 4 of the react-native-sound package:
var RNSound = require('react-native').NativeModules.RNSound;
var IsAndroid = RNSound.IsAndroid;
Probably this means that the RNSound object is not registered correctly.
Anyways, it seems the package is not being maintained anymore with 33 issues and 8 pull request, and last mit was 4 months ago.
So, how do you guys add audio to your projects? I am using React Native 0.37 btw.
I am trying really hard to play an audio file from my react-native app. Currenty I am trying to use this package:
react-native-sound
But can not get it to work properly, I get this error: Cannot read property IsAndroid of undefined, which it tries to do in sound.js line 4 of the react-native-sound package:
var RNSound = require('react-native').NativeModules.RNSound;
var IsAndroid = RNSound.IsAndroid;
Probably this means that the RNSound object is not registered correctly.
Anyways, it seems the package is not being maintained anymore with 33 issues and 8 pull request, and last mit was 4 months ago.
So, how do you guys add audio to your projects? I am using React Native 0.37 btw.
Share Improve this question asked Nov 22, 2016 at 1:40 abooayoobabooayoob 912 silver badges7 bronze badges 2- This may help github./zmxv/react-native-sound/issues/36 – Nirav Ranpara Commented Nov 22, 2016 at 1:43
- Thanks, that thread helped alot! I will write an answer to my own question, based on that thread. – abooayoob Commented Nov 23, 2016 at 13:03
1 Answer
Reset to default 4Ok, so based on Nirav Ranpara's
ment and the link he provided:
https://github./zmxv/react-native-sound/issues/36
These are the stepsto take to make it work in android using React Native 0.37
1. Edit android/settings.gradle to declare the project directory:
include ':RNSound', ':app'
project(':RNSound').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-sound/android')
2. Edit android/app/build.gradle to declare the project dependency:
dependencies {
...
pile project(':RNSound')
}
3. Edit android/app/src/main/java/.../MainApplication.java to register the native module:
NOTE: MainApplication.java not MainActivity.java
...
import .zmxv.RNSound.RNSoundPackage;
...
...
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(), // don't forget your ma
new RNSoundPackage() // insert this line
);
}
...
4. Import in your application like this:
import { default as Sound } from 'react-native-sound';
NOTE don't do this:
// wrong
var Sound = require('react-native-sound');
// also wrong
import {Sound} from 'react-native-sound';
NOTE: Step 1 and 2 are same as the documentation, while 3 and 4 differ.
本文标签: javascriptHow to play audio file in reactnative Primarily in androidStack Overflow
版权声明:本文标题:javascript - How to play audio file in react-native? Primarily in android - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745626296a2666992.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论