hyochan / react-native-audio-recorder-player

react-native native module for audio recorder and player.
MIT License
681 stars 203 forks source link

addRecordBackListener not working when passing params in startRecorder function #598

Open HarshSteyn opened 3 months ago

HarshSteyn commented 3 months ago

The addRecorderBackListener stops working when we pass params in startRecorder function const onStartRecord = async () => { const path = 'hello.m4a'; // Set the path for the audio file const audioSet = { AudioEncoderAndroid: AudioEncoderAndroidType.AAC, AudioSourceAndroid: AudioSourceAndroidType.MIC, AVEncoderAudioQualityKeyIOS: AVEncoderAudioQualityIOSType.high, AVNumberOfChannelsKeyIOS: 2, AVFormatIDKeyIOS: AVEncodingOption.aac, }; const meteringEnabled = true;

const result = await audioRecorderPlayer.startRecorder(
  path,
  audioSet,
  meteringEnabled,
);
audioRecorderPlayer.addRecordBackListener((e) => {
  setRecordSeconds(e.currentPosition);
  setMetering(e.currentMetering);
  // console.log('metering==', e.currentMetering, e.currentPosition);
});
console.log('res==', result, metering, recordSeconds);

};

"react-native-audio-recorder-player": "^3.6.6",

"react-native": "^0.72.7",

issue on both platforms

the console log statement in the listener should work

the console log statement in the listener doesnt work

ecastago commented 2 weeks ago

What android version are you using in the simulator?

anatooly commented 2 weeks ago

iOS callback addRecordBackListener not working too when use path prop.

Example success work:

const result = await audioRecorderPlayer.current.startRecorder()

{"e": {"currentMetering": 0, "currentPosition": 529.297052154195, "isRecording": true}, "state": {"recordSecs": 529.297052154195, "recordTime": "00:00:52"}}

Not working:

const uri = `${RNFS.CachesDirectoryPath}/sound.aac`

const result = await audioRecorderPlayer.current.startRecorder(uri)
// const result = await audioRecorderPlayer.current.startRecorder(uri, audioSet)

May be problem is directory path, if use only name it work, https://github.com/hyochan/react-native-audio-recorder-player/blob/2816abab9b049b104ff29b2c8ac1792a8e19822b/ios/RNAudioRecorderPlayer.swift#L46

    const result = await audioRecorderPlayer.current.startRecorder(
      'sound.aac',
      audioSet,
      meteringEnabled,
    )
ecastago commented 1 week ago

iOS callback addRecordBackListener not working too when use path prop.

Example success work:

const result = await audioRecorderPlayer.current.startRecorder()

{"e": {"currentMetering": 0, "currentPosition": 529.297052154195, "isRecording": true}, "state": {"recordSecs": 529.297052154195, "recordTime": "00:00:52"}}

Not working:

const uri = `${RNFS.CachesDirectoryPath}/sound.aac`

const result = await audioRecorderPlayer.current.startRecorder(uri)
// const result = await audioRecorderPlayer.current.startRecorder(uri, audioSet)

May be problem is directory path, if use only name it work,

https://github.com/hyochan/react-native-audio-recorder-player/blob/2816abab9b049b104ff29b2c8ac1792a8e19822b/ios/RNAudioRecorderPlayer.swift#L46

    const result = await audioRecorderPlayer.current.startRecorder(
      'sound.aac',
      audioSet,
      meteringEnabled,
    )

Thank you for your solution. This worked perfectly.

In Android Version > 12 you can't ask for external storage permissions only record audio. So if you put a path in the startRecorder() this wouldn't work.