punarinta / react-native-sound-level

A package to dynamically measure sound input level in React Native applications. Can be used to help user to adjust microphone sensitivity.
MIT License
79 stars 45 forks source link

iOS: Conflict with other AVAudio player/recorder applications #30

Open ncstc1 opened 1 year ago

ncstc1 commented 1 year ago

Hi, I have two questions/comments on iOS:

Conflicts between AVAudio callers

It looks like AVAudioRecorder processing will stop (isRecording becomes false) if another application starts playing music.

Is there a way to avoid that? (by tweaking the current code or using another API? I am not sure another API returns metering information/averagePowerForChannel).

Making the timer collection more robust

When the application resumes after the previous problem, the metering processing should resume too (isRecording should become true again).

I am unsure about the right fix (hence no PR :)) but I considered something like:

(void)sendProgressUpdate {
  if (!_audioRecorder || !_audioRecorder.isRecording) {
    if (!_audioRecorder.isRecording) {
      // Restart the timer if the recording stopped for some reason
      [self stop];
      [self start:_progressUpdateInterval];
    }
    return;
  }
  (...)

What do you think?