Simple audio recorder component for android
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
Add the dependecy
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation 'com.github.melow2:AudioRecordButton:Tag'
}
<com.khs.audiorecorder.AudioRecordButton
android:id="@+id/audio_record_button"
android:layout_centerInParent="true"
android:layout_width="250dp"
android:layout_height="wrap_content">
</com.khs.audiorecorder.AudioRecordButton>
- recorder_image_size: size to image micro voice
- remove_image_size: size to image cancel audio
- recorder_image: drawable to image voice
- remove_image: drawable to image voice
- remove_position: left or right (Todo)
private AudioRecordButton audioRecordButton;
audioRecordButton = (AudioRecordButton) findViewById(R.id.audio_record_button);
Starting audio record
audioRecordButton.setOnAudioListener(new AudioListener() {
@Override
public void onStop(RecordingItem recordingItem) {
Toast.makeText(getBaseContext(), "Audio...", Toast.LENGTH_SHORT).show();
}
@Override
public void onCancel() {
Toast.makeText(getBaseContext(), "Cancel", Toast.LENGTH_SHORT).show();
}
@Override
public void onError(Exception e) {
Log.d("MainActivity", "Error: " + e.getMessage());
}
});
If you prefer to execute the sound after the audio capture, just call the play()
method inside onStop()
@Override
public void onStop(RecordingItem recordingItem) {
Toast.makeText(getBaseContext(), "Audio...", Toast.LENGTH_SHORT).show();
new AudioRecording(getBaseContext()).play(recordingItem);
}