hyochan / react-native-audio-recorder-player

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

Best way to handle audio interruptions? #624

Open joshmohrer opened 2 months ago

joshmohrer commented 2 months ago

Please fill the template to help you out. Also, please try the Example project compare before submiting the issue when you have certain issue with your project setup.

Version of react-native-audio-recorder-player

3.6.7 and 3.6.10

I suddenly have started receiving pings from users indicating interruptions are deleting their recordings. This seems to be happening all at once so either something changed in my app (most likely) or perhaps in iOS?

I was wondering if anyone could share how they handle interruptions on the react native side. As it stands, interruptions seem to restart the recording and discard the audio up to that point. Could anyone share an example of how they handle this?

Version of React Native

Platforms you faced the error (IOS or Android or both?)

Expected behavior

Actual behavior

Steps to reproduce the behabior

tinkon commented 1 month ago

I am facing the same problem.

joshmohrer commented 1 month ago

For now ive moved to expo-av which has gotten better with Expo 51 and handled interruptions a little more elegantly.

tinkon commented 1 month ago

According to this commit, this issue should not have been there. I'm not sure what we are doing wrong.

https://github.com/hyochan/react-native-audio-recorder-player/pull/601/commits/a2800802032aac214ef4e98a273ed4de8212eb02

tinkon commented 1 month ago

I messed with the code a bit. It calls to pause and resume based on the interrupt event beginning and end. The problem is, in some cases, you would just want to stop the player and save the file recorded so far. It seems that if you call stopRecorder while it is in the paused stage, you lose the file.

zeRonaldo commented 1 month ago

I was Having the Exact same issue,

so I had to put on higher stakes:

codecomeon commented 1 month ago

I was Having the Exact same issue,

  • I downgraded the lib to before the fix 3.6.6 -I had to make a module on my native side to handle system audio alert interruptions this rippled a trigger on my ReactNative side, which then paused the recording; BUT and there's a big one, the issue was on IOS;

so I had to put on higher stakes:

  • the bug is a normal behavior on audio implementation dictionary that can be seen here it calls the prepareRecord function that zeroes our current audio;
  • I altered the implementation to keep 2 separate stages, 1 for paused/interrupted audios inside an easily accessible folder; and one for stopped audios (or consolidated);
  • this worked, but I still had audio pieces and not a complete audio, So I stitched them together after hitting stop, using native code;

I did the same, i use ffmpeg-kit to merge all the pieces.

awallish commented 1 week ago

Downgrading from 3.6.10 to 3.6.7 fixed this for me.