Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

addRecordBackListener not working when passing params in startRecorder function #598

Open
rsys-harsh-saini opened this issue Mar 15, 2024 · 3 comments

Comments

@rsys-harsh-saini
Copy link

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
Copy link

What android version are you using in the simulator?

@anatooly
Copy link

anatooly commented Jun 19, 2024

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,

func setAudioFileURL(path: String) {

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

@ecastago
Copy link

ecastago commented Jun 25, 2024

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,

func setAudioFileURL(path: String) {

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants