kevinresol / react-native-sound-recorder

Simplest Sound Recorder for React Native
MIT License
119 stars 36 forks source link

setAudioSource Failed on SoundRecorder.stop() #10

Closed ameenmattar closed 6 years ago

ameenmattar commented 6 years ago

Thank you for this amazing library @kevinresol , but i am facing some problems: The app crashes when on SoundRecorder.stop() works fine on iOS but crashes on Android, i have included the android permission in the AndroidManifest as you mentioned : <uses-permission android:name="android.permission.RECORD_AUDIO" />

And here is the code for SoundRecorder.stop():

SoundRecorder.stop().then(function(result) {
      console.log("stopped recording, audio file saved at: ", result.path);
      this.onSendFile(result.path, "test.mp4", "audio/mpeg");
    });

The Error i get is described in the below image:

screen shot 2018-07-19 at 11 25 33 am

Thank you in advance

kevinresol commented 6 years ago

same as https://github.com/kevinresol/react-native-sound-recorder/issues/8?

well no, #8 crashes at start()

kevinresol commented 6 years ago

but that doesn't make sense. setAudioSource only happens in start()

kevinresol commented 6 years ago

did you request for the permission at runtime?

ameenmattar commented 6 years ago

@kevinresol Yes i have requested for the permission at runtime and added this permission to the AndroidManifest :

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

kevinresol commented 6 years ago

Can you show the code for the run time permission request?

ameenmattar commented 6 years ago

Here's my run time permission request code:

async function requestMicrophonePermission() {
  try {
    const granted = await PermissionsAndroid.request(
      PermissionsAndroid.PERMISSIONS.RECORD_AUDIO,
      {
        title: "Requesting Microphone Access",
        message: "App needs permission to access to your microphone "
      }
    );
    if (granted === PermissionsAndroid.RESULTS.GRANTED) {
      console.log("You can use the microphone");
    } else {
      console.log("Microphone permission denied");
      alert("Microphone permission denied");
    }
  } catch (err) {
    console.warn(err);
  }
}
kevinresol commented 6 years ago

but that doesn't make sense. setAudioSource only happens in start()

are you sure the crash happens at stop()?

kevinresol commented 6 years ago

What is your android version and phone model btw?

ameenmattar commented 6 years ago

Yes it seems to happen on stop(), and even if its on start() #8 didn't solve my problem because i have added the permission and nothing changed. The android version "27.0.3" The phone model : Samsung S8

kevinresol commented 6 years ago

Can you try <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> and request the permission at runtime too?

ameenmattar commented 6 years ago

I have already include these too

_ANDROID_STUDIO :_

screen shot 2018-07-20 at 5 43 06 pm

_JSCODE:

screen shot 2018-07-20 at 5 43 26 pm

And here is the Code for Recording:

async _onMicroPress() {
    await requestMicrophonePermission();
    await requestStoragePermission();
    SoundRecorder.start(SoundRecorder.PATH_CACHE + "/test.mp4").then(
      function() {
        console.log("started recording");
      }
    );
  }

  _onMicroRelease = () => {
    SoundRecorder.stop().then(function(result) {
      console.log("stopped recording, audio file saved at: ", result.path);
      this.onSendFile(result.path, "test.mp4", "audio/mpeg");
    });
  };
kevinresol commented 6 years ago

To be honest I don't have any idea at the moment

geniuscd commented 6 years ago

Hey, Thanks for the support. I found a fix for this issue. basically its something related to the android only and the "MediaRecorder" class. PR #11

kevinresol commented 6 years ago

@ameenmattar can you try again with v1.3.1 (merged #11)?

kevinresol commented 6 years ago

I assume it is fixed