kevinresol / react-native-sound-recorder

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

setAudioSource failed #45

Closed tirthasourav closed 4 years ago

tirthasourav commented 4 years ago

Screenshot 2020-07-30 at 1 07 26 PM Using react native 0.63.0. Getting 'setAudioSource failed' issue on android on Start recording

upsilon-dev commented 4 years ago

Just experienced the same issue but resolved it after adding requesting for runtime permissions. https://reactnativecode.com/react-native-runtime-permissionsandroid/

kevinresol commented 4 years ago

Assume missing permission. Closing.

mohammad6vakili commented 1 year ago

You need to check the RECORD_AUDIO permission before start recording.

try {
      const grants = await PermissionsAndroid.request(
        PermissionsAndroid.PERMISSIONS.RECORD_AUDIO,
      );
      console.log('record audio', grants);
      if (grants === PermissionsAndroid.RESULTS.GRANTED) {
        SoundRecorder.start(SoundRecorder.PATH_CACHE + '/test.mp4').then(
          function () {
            console.log('started recording');
          },
        );
      } else {
         console.log('All required permissions not granted')
        return;
      }
    } catch (err) {
      console.warn(err);
      return;
    }