How to play an audio file in response mode? Primarily in android

I am trying very hard to play an audio file from my interoperable application. I am currently trying to use this package:

react-native-sound

But I can’t get it to work correctly, I get this error: It is not possible to read the IsAndroid undefined property, which it tries to do in the sound.js 4 line of the action-native-sound package:

var RNSound = require('react-native').NativeModules.RNSound; var IsAndroid = RNSound.IsAndroid;

Perhaps this means that the RNSound object is registered incorrectly.

In any case, it seems that the package is no longer supported with 33 problems and 8 pull requests, and the last commit was 4 months ago.

So how do you guys add audio to your projects? I am using React Native 0.37 btw.

+4
source share
1 answer

Ok, so based on Nirar Ranpar's comment and the link he provided:
https://github.com/zmxv/react-native-sound/issues/36

This is a step to get it working in android using React Native 0.37

1. Edit the android / settings.gradle file to declare the project directory:

include ':RNSound', ':app'
project(':RNSound').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-sound/android')

2. Modify android / app / build.gradle to declare the project dependency:

   dependencies {
     ...
     compile project(':RNSound')
   }

3. Modify the file android / app / src / main / java /.../ MainApplication.java to register your own module:

NOTE: MainApplication.java is not MainActivity.java

...
import com.zmxv.RNSound.RNSoundPackage;
...

...
@Override
protected List<ReactPackage> getPackages() {
  return Arrays.<ReactPackage>asList(
      new MainReactPackage(), // don't forget your comma
      new RNSoundPackage() // insert this line
  );
}
...

4. :

import { default as Sound } from 'react-native-sound';

:

// wrong
var Sound = require('react-native-sound');

// also wrong
import {Sound} from 'react-native-sound';

. 1 2 , 3 4 .

+3

Source: https://habr.com/ru/post/1661519/


All Articles