Skip to content

melow2/AudioRecordButton

Repository files navigation

오디오 녹음 버튼.

Simple audio recorder component for android

Demo

progress image view

Add permissions in your androidmanifest.xml

<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'
}

Usage

XML

    <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>

Configure XML

  • 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)

Java

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);
}