Skip to main content
The CometChatMediaRecorder is a custom Android component that provides a user interface for recording audio and playing back the recorded audio. It is designed to be easily integrated into chat applications or other projects where audio messaging is required. Audio Recording: The component allows users to start recording audio from the device’s microphone by clicking on the “Record” button. It captures audio in MPEG-4 format with AAC audio encoding. Visualizer: While recording audio, the component displays a visualizer that represents the amplitude of the audio being captured. The visualizer provides a real-time visualization of the audio recording. Playback: After recording audio, the component displays a playback UI, allowing users to listen to the recorded audio. It provides “Play” and “Pause” buttons to control audio playback. SeekBar: The component includes a seek bar that indicates the progress of audio playback. Users can seek to different positions in the recorded audio using the seek bar. Timer: The component displays two timers: one for the duration of the recorded audio and the other for the current recording time. Customizable Icons and Styles: The icons used for buttons (play, pause, stop, etc.) are customizable, and their tint color can be adjusted to match the app’s theme. Additionally, the component supports custom styles to change the visual appearance, such as colors, background, border, and corner radius. Permission Handling: The component handles runtime permission requests for recording audio, read/write storage, and microphone access. It requests the necessary permissions before starting the recording process. Deletion of Recorded Audio: Users can delete the recorded audio using the “Delete” button, which removes the audio file from the device’s storage. Callbacks: The component allows developers to set callback listeners for events like clicking on the “Submit” button to send the recorded audio and clicking on the “Close” button to close the component.

How to integrate CometChatMediaRecorder?

Since CometChatMediaRecorder is a Widget, it can be added directly to the layout file as shown below.
The CometChatMediaRecorder is responsible for managing runtime permissions. To ensure the ActivityResultLauncher is properly initialized, its object should be created in the the onCreate state of an activity. To ensure that the Media Recorder is loaded within the fragment, it is important to make sure that the fragment is loaded in the onCreate state of the activity.

Methods

MediaRecorderStyle

This methods is used to customize the appearance of the CometChatMediaRecorder component.