diff --git a/README.md b/README.md index 0342f71..a65b5bf 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ # AndroidAudioRecorder -> A fancy audio recorder for Android. It supports `WAV` format. +> A fancy audio recorder for Android. It supports `WAV` format at 48kHz. ![Screenshots](https://raw.githubusercontent.com/adrielcafe/AndroidAudioRecorder/master/demo.gif) @@ -22,9 +22,17 @@ String filePath = Environment.getExternalStorageDirectory() + "/recorded_audio.w int color = getResources().getColor(R.color.colorPrimaryDark); int requestCode = 0; AndroidAudioRecorder.with(this) + // Required .setFilePath(filePath) .setColor(color) .setRequestCode(requestCode) + + // Optional + .setSource(AudioSource.MIC) + .setChannel(AudioChannel.STEREO) + .setSampleRate(AudioSampleRate.HZ_48000) + + // Start recording .record(); ``` @@ -53,7 +61,7 @@ repositories { } dependencies { - compile 'com.github.adrielcafe:AndroidAudioRecorder:0.0.9' + compile 'com.github.adrielcafe:AndroidAudioRecorder:0.1.0' } ``` @@ -63,6 +71,7 @@ dependencies { - [X] Wave visualization based on this [player concept](https://dribbble.com/shots/2369760-Player-Concept) - [X] Play recorded audio - [X] Pause recording +- [X] Configure audio source (Mic/Camcorder), channel (Stereo/Mono) and sample rate (8kHz to 48kHz) - [ ] Skip silence - [ ] Animations - [ ] Landscape screen orientation (only supports portrait at the moment) diff --git a/app/src/main/java/cafe/adriel/androidaudiorecorder/example/MainActivity.java b/app/src/main/java/cafe/adriel/androidaudiorecorder/example/MainActivity.java index 897edc4..da66bef 100644 --- a/app/src/main/java/cafe/adriel/androidaudiorecorder/example/MainActivity.java +++ b/app/src/main/java/cafe/adriel/androidaudiorecorder/example/MainActivity.java @@ -10,7 +10,9 @@ import android.widget.Toast; import cafe.adriel.androidaudiorecorder.AndroidAudioRecorder; -import cafe.adriel.androidaudiorecorder.Util; +import cafe.adriel.androidaudiorecorder.model.AudioChannel; +import cafe.adriel.androidaudiorecorder.model.AudioSampleRate; +import cafe.adriel.androidaudiorecorder.model.AudioSource; public class MainActivity extends AppCompatActivity { private static final String AUDIO_FILE_PATH = Environment.getExternalStorageDirectory() + "/recorded_audio.wav"; @@ -44,9 +46,17 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { public void recordAudio(View v) { AndroidAudioRecorder.with(this) + // Required .setFilePath(AUDIO_FILE_PATH) .setColor(getResources().getColor(R.color.recorder_bg)) .setRequestCode(RECORD_AUDIO) + + // Optional + .setSource(AudioSource.MIC) + .setChannel(AudioChannel.STEREO) + .setSampleRate(AudioSampleRate.HZ_48000) + + // Start recording .record(); } diff --git a/app/src/main/java/cafe/adriel/androidaudiorecorder/example/Util.java b/app/src/main/java/cafe/adriel/androidaudiorecorder/example/Util.java new file mode 100644 index 0000000..a2b0c82 --- /dev/null +++ b/app/src/main/java/cafe/adriel/androidaudiorecorder/example/Util.java @@ -0,0 +1,17 @@ +package cafe.adriel.androidaudiorecorder.example; + +import android.app.Activity; +import android.content.pm.PackageManager; +import android.support.v4.app.ActivityCompat; +import android.support.v4.content.ContextCompat; + +public class Util { + + public static void requestPermission(Activity activity, String permission) { + if (ContextCompat.checkSelfPermission(activity, permission) + != PackageManager.PERMISSION_GRANTED) { + ActivityCompat.requestPermissions(activity, new String[]{permission}, 0); + } + } + +} \ No newline at end of file diff --git a/lib/build.gradle b/lib/build.gradle index 70c1d73..e20728f 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -19,7 +19,7 @@ android { } dependencies { - compile 'com.android.support:appcompat-v7:24.1.1' + compile 'com.android.support:appcompat-v7:24.2.1' compile 'com.kailashdabhi:om-recorder:1.1.0' - compile 'com.cleveroad:audiovisualization:0.9.4' + compile 'com.cleveroad:audiovisualization:1.0.0' } \ No newline at end of file diff --git a/lib/src/main/AndroidManifest.xml b/lib/src/main/AndroidManifest.xml index 663bfed..a50fcba 100644 --- a/lib/src/main/AndroidManifest.xml +++ b/lib/src/main/AndroidManifest.xml @@ -3,9 +3,7 @@ xmlns:android="http://schemas.android.com/apk/res/android" package="cafe.adriel.androidaudiorecorder"> - + = 200; } diff --git a/lib/src/main/java/cafe/adriel/androidaudiorecorder/model/AudioChannel.java b/lib/src/main/java/cafe/adriel/androidaudiorecorder/model/AudioChannel.java new file mode 100644 index 0000000..8235c7f --- /dev/null +++ b/lib/src/main/java/cafe/adriel/androidaudiorecorder/model/AudioChannel.java @@ -0,0 +1,17 @@ +package cafe.adriel.androidaudiorecorder.model; + +import android.media.AudioFormat; + +public enum AudioChannel { + STEREO, + MONO; + + public int getChannel(){ + switch (this){ + case MONO: + return AudioFormat.CHANNEL_IN_MONO; + default: + return AudioFormat.CHANNEL_IN_STEREO; + } + } +} \ No newline at end of file diff --git a/lib/src/main/java/cafe/adriel/androidaudiorecorder/model/AudioSampleRate.java b/lib/src/main/java/cafe/adriel/androidaudiorecorder/model/AudioSampleRate.java new file mode 100644 index 0000000..a0343b3 --- /dev/null +++ b/lib/src/main/java/cafe/adriel/androidaudiorecorder/model/AudioSampleRate.java @@ -0,0 +1,15 @@ +package cafe.adriel.androidaudiorecorder.model; + +public enum AudioSampleRate { + HZ_48000, + HZ_44100, + HZ_32000, + HZ_22050, + HZ_16000, + HZ_11025, + HZ_8000; + + public int getSampleRate(){ + return Integer.parseInt(name().replace("HZ_", "")); + } +} \ No newline at end of file diff --git a/lib/src/main/java/cafe/adriel/androidaudiorecorder/model/AudioSource.java b/lib/src/main/java/cafe/adriel/androidaudiorecorder/model/AudioSource.java new file mode 100644 index 0000000..daae49c --- /dev/null +++ b/lib/src/main/java/cafe/adriel/androidaudiorecorder/model/AudioSource.java @@ -0,0 +1,17 @@ +package cafe.adriel.androidaudiorecorder.model; + +import android.media.MediaRecorder; + +public enum AudioSource { + MIC, + CAMCORDER; + + public int getSource(){ + switch (this){ + case CAMCORDER: + return MediaRecorder.AudioSource.CAMCORDER; + default: + return MediaRecorder.AudioSource.MIC; + } + } +} \ No newline at end of file