Add support for audio recording interruptions with segmentation
This pull request enhances the react-native-audio-recorder-player library by adding support for handling audio recording interruptions, such as incoming calls, in a seamless way. Previously, when an interruption occurred, resuming the recording would overwrite the existing audio file because AVAudioRecorder’s record() method implicitly calls prepareToRecord(), creating a new file at the specified URL. This made it impossible to truly "resume" a recording with the existing API.
To address this issue, we’ve introduced a new approach:
- Segmented Recording: Instead of recording to a single file, the audio is now split into multiple segment files. Each time recording starts or resumes after an interruption, a new segment is created and tracked in an array.
- Interruption Handling: When an interruption begins, the current segment is saved and paused. Once the interruption ends, a new segment starts recording, preserving all previous audio.
- Merging Segments: Upon stopping the recording, all segments are combined into a single audio file using
AVMutableComposition, ensuring no audio is lost.
This solution ensures that recordings remain intact across interruptions, providing a smoother and more reliable experience for users. The changes are implemented in RNAudioRecorderPlayer.swift, with updates to key methods like startRecorder, resumeRecorder, and stopRecorder, along with new functions for segment management and merging.