Overview
TheAMRAudioRecorder class provides a simple interface for recording AMR (Adaptive Multi-Rate) audio on Android with support for pause and resume functionality. Since Android’s native MediaRecorder doesn’t support pausing AMR recordings, this library handles the complexity of managing multiple recording segments and merging them into a single output file.
Key features
- Pause and resume: Pause and resume AMR audio recording seamlessly
- Automatic file merging: Automatically merges multiple recording segments into a single AMR file
- Simple API: Clean, intuitive methods for controlling the recording lifecycle
- File management: Built-in methods for accessing the final audio file path and clearing recordings
Constructor
The directory path where audio files will be stored. The directory must exist before instantiation. The constructor automatically appends a trailing slash if not provided.
Throws
IllegalArgumentException- Thrown during recording preparation if the provided directory doesn’t exist or is not a valid directory
Example
State management
The recorder maintains an internal state that tracks whether it’s currently recording. You can query this state using theisRecording() method and retrieve the final audio file path using getAudioFilePath().
Recording lifecycle
- Initialize: Create a new
AMRAudioRecorderinstance with a valid directory path - Start: Call
start()to begin recording - Pause (optional): Call
pause()to temporarily stop recording - Resume (optional): Call
resume()to continue recording after pausing - Stop: Call
stop()to finalize the recording and merge segments - Clear (optional): Call
clear()to discard the recording
When you pause and resume a recording, the library creates multiple AMR file segments. When you call
stop(), these segments are automatically merged into a single file with the AMR headers properly handled.