├── .github
└── FUNDING.yml
├── .gitignore
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── cafe
│ │ └── adriel
│ │ └── androidaudiorecorder
│ │ └── example
│ │ ├── MainActivity.java
│ │ └── Util.java
│ └── res
│ ├── layout
│ └── activity_main.xml
│ ├── mipmap-hdpi
│ └── ic_launcher.png
│ ├── mipmap-mdpi
│ └── ic_launcher.png
│ ├── mipmap-xhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxxhdpi
│ └── ic_launcher.png
│ └── values
│ ├── colors.xml
│ ├── strings.xml
│ └── styles.xml
├── build.gradle
├── demo.gif
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── lib
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── cafe
│ │ └── adriel
│ │ └── androidaudiorecorder
│ │ ├── AndroidAudioRecorder.java
│ │ ├── AudioRecorderActivity.java
│ │ ├── Util.java
│ │ ├── VisualizerHandler.java
│ │ └── model
│ │ ├── AudioChannel.java
│ │ ├── AudioSampleRate.java
│ │ └── AudioSource.java
│ └── res
│ ├── drawable-hdpi
│ ├── aar_ic_check.png
│ └── aar_ic_clear.png
│ ├── drawable-mdpi
│ ├── aar_ic_check.png
│ └── aar_ic_clear.png
│ ├── drawable-xhdpi
│ ├── aar_ic_check.png
│ └── aar_ic_clear.png
│ ├── drawable-xxhdpi
│ ├── aar_ic_check.png
│ └── aar_ic_clear.png
│ ├── drawable-xxxhdpi
│ ├── aar_ic_check.png
│ └── aar_ic_clear.png
│ ├── drawable
│ ├── aar_ic_pause.png
│ ├── aar_ic_play.png
│ ├── aar_ic_rec.png
│ ├── aar_ic_restart.png
│ └── aar_ic_stop.png
│ ├── layout
│ └── aar_activity_audio_recorder.xml
│ ├── menu
│ └── aar_audio_recorder.xml
│ ├── values-pt
│ └── strings.xml
│ └── values
│ ├── dimens.xml
│ └── strings.xml
├── screenshots.png
└── settings.gradle
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | ko_fi: adrielcafe
2 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | .idea
4 | /local.properties
5 | /.idea/workspace.xml
6 | /.idea/libraries
7 | .DS_Store
8 | /build
9 | /captures
10 | .externalNativeBuild
11 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](https://android-arsenal.com/details/1/4099) [](https://jitpack.io/#adrielcafe/AndroidAudioRecorder)
2 |
3 | # AndroidAudioRecorder
4 |
5 | > A fancy audio recorder for Android. It supports `WAV` format at `48kHz`.
6 |
7 | 
8 |
9 | 
10 |
11 | ## How To Use
12 |
13 | 1 - Add these permissions into your `AndroidManifest.xml` and [request for them in Android 6.0+](https://developer.android.com/training/permissions/requesting.html)
14 | ```xml
15 |
16 |
17 |
18 | ```
19 |
20 | 2 - Open the recorder activity
21 | ```java
22 | String filePath = Environment.getExternalStorageDirectory() + "/recorded_audio.wav";
23 | int color = getResources().getColor(R.color.colorPrimaryDark);
24 | int requestCode = 0;
25 | AndroidAudioRecorder.with(this)
26 | // Required
27 | .setFilePath(filePath)
28 | .setColor(color)
29 | .setRequestCode(requestCode)
30 |
31 | // Optional
32 | .setSource(AudioSource.MIC)
33 | .setChannel(AudioChannel.STEREO)
34 | .setSampleRate(AudioSampleRate.HZ_48000)
35 | .setAutoStart(true)
36 | .setKeepDisplayOn(true)
37 |
38 | // Start recording
39 | .record();
40 | ```
41 |
42 | 3 - Wait for result
43 | ```java
44 | @Override
45 | protected void onActivityResult(int requestCode, int resultCode, Intent data) {
46 | super.onActivityResult(requestCode, resultCode, data);
47 | if (requestCode == 0) {
48 | if (resultCode == RESULT_OK) {
49 | // Great! User has recorded and saved the audio file
50 | } else if (resultCode == RESULT_CANCELED) {
51 | // Oops! User has canceled the recording
52 | }
53 | }
54 | }
55 | ```
56 |
57 | ## Import to your project
58 | Put this into your `app/build.gradle`:
59 | ```
60 | repositories {
61 | maven {
62 | url "https://jitpack.io"
63 | }
64 | }
65 |
66 | dependencies {
67 | compile 'com.github.adrielcafe:AndroidAudioRecorder:0.3.0'
68 | }
69 | ```
70 |
71 | ## FEATURES
72 | - [X] Record audio
73 | - [X] Tint images to black when background color is too bright (thanks to [@prakh25](https://github.com/prakh25))
74 | - [X] Wave visualization based on this [player concept](https://dribbble.com/shots/2369760-Player-Concept)
75 | - [X] Play recorded audio
76 | - [X] Pause recording
77 | - [X] Configure audio source (Mic/Camcorder), channel (Stereo/Mono) and sample rate (8kHz to 48kHz)
78 | - [X] Auto start recording when open activity
79 | - [X] Keep display on while recording
80 | - [ ] Skip silence
81 | - [ ] Animations
82 | - [ ] Landscape screen orientation (only supports portrait at the moment)
83 |
84 | ## Dependencies
85 | * [OmRecorder](https://github.com/kailash09dabhi/OmRecorder)
86 | * [WaveInApp](https://github.com/Cleveroad/WaveInApp)
87 |
88 | ## Want to CONVERT AUDIO into your app?
89 | **Take a look at [AndroidAudioConverter](https://github.com/adrielcafe/AndroidAudioConverter)! Example of usage [here](https://github.com/adrielcafe/AndroidAudioRecorder/issues/8#issuecomment-247311572).**
90 |
91 | ## License
92 | ```
93 | The MIT License (MIT)
94 |
95 | Copyright (c) 2016 Adriel Café
96 |
97 | Permission is hereby granted, free of charge, to any person obtaining a copy
98 | of this software and associated documentation files (the "Software"), to deal
99 | in the Software without restriction, including without limitation the rights
100 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
101 | copies of the Software, and to permit persons to whom the Software is
102 | furnished to do so, subject to the following conditions:
103 |
104 | The above copyright notice and this permission notice shall be included in
105 | all copies or substantial portions of the Software.
106 |
107 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
108 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
109 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
110 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
111 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
112 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
113 | THE SOFTWARE.
114 | ```
115 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 24
5 | buildToolsVersion "24.0.2"
6 | defaultConfig {
7 | applicationId "cafe.adriel.androidaudiorecorder.example"
8 | minSdkVersion 15
9 | targetSdkVersion 24
10 | versionCode 1
11 | versionName "1.0"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | compile 'com.android.support:appcompat-v7:24.2.1'
23 | compile project(':lib')
24 | // compile 'com.github.adrielcafe:AndroidAudioRecorder:0.1.0'
25 | }
26 |
27 | repositories {
28 | maven { url "https://jitpack.io" }
29 | }
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/adrielcafe/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
9 |
10 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/app/src/main/java/cafe/adriel/androidaudiorecorder/example/MainActivity.java:
--------------------------------------------------------------------------------
1 | package cafe.adriel.androidaudiorecorder.example;
2 |
3 | import android.Manifest;
4 | import android.content.Intent;
5 | import android.graphics.drawable.ColorDrawable;
6 | import android.os.Bundle;
7 | import android.os.Environment;
8 | import android.support.v4.content.ContextCompat;
9 | import android.support.v7.app.AppCompatActivity;
10 | import android.view.View;
11 | import android.widget.Toast;
12 |
13 | import cafe.adriel.androidaudiorecorder.AndroidAudioRecorder;
14 | import cafe.adriel.androidaudiorecorder.model.AudioChannel;
15 | import cafe.adriel.androidaudiorecorder.model.AudioSampleRate;
16 | import cafe.adriel.androidaudiorecorder.model.AudioSource;
17 |
18 | public class MainActivity extends AppCompatActivity {
19 | private static final int REQUEST_RECORD_AUDIO = 0;
20 | private static final String AUDIO_FILE_PATH =
21 | Environment.getExternalStorageDirectory().getPath() + "/recorded_audio.wav";
22 |
23 | @Override
24 | protected void onCreate(Bundle savedInstanceState) {
25 | super.onCreate(savedInstanceState);
26 | setContentView(R.layout.activity_main);
27 |
28 | if (getSupportActionBar() != null) {
29 | getSupportActionBar().setBackgroundDrawable(
30 | new ColorDrawable(ContextCompat.getColor(this, R.color.colorPrimaryDark)));
31 | }
32 |
33 | Util.requestPermission(this, Manifest.permission.RECORD_AUDIO);
34 | Util.requestPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
35 | }
36 |
37 | @Override
38 | protected void onActivityResult(int requestCode, int resultCode, Intent data) {
39 | super.onActivityResult(requestCode, resultCode, data);
40 | if (requestCode == REQUEST_RECORD_AUDIO) {
41 | if (resultCode == RESULT_OK) {
42 | Toast.makeText(this, "Audio recorded successfully!", Toast.LENGTH_SHORT).show();
43 | } else if (resultCode == RESULT_CANCELED) {
44 | Toast.makeText(this, "Audio was not recorded", Toast.LENGTH_SHORT).show();
45 | }
46 | }
47 | }
48 |
49 | public void recordAudio(View v) {
50 | AndroidAudioRecorder.with(this)
51 | // Required
52 | .setFilePath(AUDIO_FILE_PATH)
53 | .setColor(ContextCompat.getColor(this, R.color.recorder_bg))
54 | .setRequestCode(REQUEST_RECORD_AUDIO)
55 |
56 | // Optional
57 | .setSource(AudioSource.MIC)
58 | .setChannel(AudioChannel.STEREO)
59 | .setSampleRate(AudioSampleRate.HZ_48000)
60 | .setAutoStart(false)
61 | .setKeepDisplayOn(true)
62 |
63 | // Start recording
64 | .record();
65 | }
66 |
67 | }
--------------------------------------------------------------------------------
/app/src/main/java/cafe/adriel/androidaudiorecorder/example/Util.java:
--------------------------------------------------------------------------------
1 | package cafe.adriel.androidaudiorecorder.example;
2 |
3 | import android.app.Activity;
4 | import android.content.pm.PackageManager;
5 | import android.support.v4.app.ActivityCompat;
6 | import android.support.v4.content.ContextCompat;
7 |
8 | public class Util {
9 |
10 | public static void requestPermission(Activity activity, String permission) {
11 | if (ContextCompat.checkSelfPermission(activity, permission)
12 | != PackageManager.PERMISSION_GRANTED) {
13 | ActivityCompat.requestPermissions(activity, new String[]{permission}, 0);
14 | }
15 | }
16 |
17 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adrielcafe/AndroidAudioRecorder/242f73b160cd60c85c5320c13ec7dcf488892178/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adrielcafe/AndroidAudioRecorder/242f73b160cd60c85c5320c13ec7dcf488892178/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adrielcafe/AndroidAudioRecorder/242f73b160cd60c85c5320c13ec7dcf488892178/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adrielcafe/AndroidAudioRecorder/242f73b160cd60c85c5320c13ec7dcf488892178/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adrielcafe/AndroidAudioRecorder/242f73b160cd60c85c5320c13ec7dcf488892178/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 | #F4511E
8 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | AndroidAudioRecorder
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
9 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | repositories {
3 | jcenter()
4 | }
5 | dependencies {
6 | classpath 'com.android.tools.build:gradle:2.2.0'
7 | }
8 | }
9 |
10 | allprojects {
11 | repositories {
12 | jcenter()
13 | }
14 | }
15 |
16 | task clean(type: Delete) {
17 | delete rootProject.buildDir
18 | }
--------------------------------------------------------------------------------
/demo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adrielcafe/AndroidAudioRecorder/242f73b160cd60c85c5320c13ec7dcf488892178/demo.gif
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adrielcafe/AndroidAudioRecorder/242f73b160cd60c85c5320c13ec7dcf488892178/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Aug 25 11:20:16 BRT 2016
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/lib/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/lib/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 24
5 | buildToolsVersion "24.0.2"
6 |
7 | defaultConfig {
8 | minSdkVersion 15
9 | targetSdkVersion 24
10 | versionCode 1
11 | versionName "1.0"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | compile 'com.android.support:appcompat-v7:24.2.1'
23 | compile 'com.kailashdabhi:om-recorder:1.1.0'
24 | compile 'com.cleveroad:audiovisualization:1.0.0'
25 | }
--------------------------------------------------------------------------------
/lib/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/adrielcafe/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/lib/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/lib/src/main/java/cafe/adriel/androidaudiorecorder/AndroidAudioRecorder.java:
--------------------------------------------------------------------------------
1 | package cafe.adriel.androidaudiorecorder;
2 |
3 | import android.app.Activity;
4 | import android.content.Intent;
5 | import android.graphics.Color;
6 | import android.os.Environment;
7 | import android.support.v4.app.Fragment;
8 |
9 | import cafe.adriel.androidaudiorecorder.model.AudioChannel;
10 | import cafe.adriel.androidaudiorecorder.model.AudioSampleRate;
11 | import cafe.adriel.androidaudiorecorder.model.AudioSource;
12 |
13 | public class AndroidAudioRecorder {
14 |
15 | protected static final String EXTRA_FILE_PATH = "filePath";
16 | protected static final String EXTRA_COLOR = "color";
17 | protected static final String EXTRA_SOURCE = "source";
18 | protected static final String EXTRA_CHANNEL = "channel";
19 | protected static final String EXTRA_SAMPLE_RATE = "sampleRate";
20 | protected static final String EXTRA_AUTO_START = "autoStart";
21 | protected static final String EXTRA_KEEP_DISPLAY_ON = "keepDisplayOn";
22 |
23 | private Activity activity;
24 | private Fragment fragment;
25 |
26 | private String filePath = Environment.getExternalStorageDirectory() + "/recorded_audio.wav";
27 | private AudioSource source = AudioSource.MIC;
28 | private AudioChannel channel = AudioChannel.STEREO;
29 | private AudioSampleRate sampleRate = AudioSampleRate.HZ_44100;
30 | private int color = Color.parseColor("#546E7A");
31 | private int requestCode = 0;
32 | private boolean autoStart = false;
33 | private boolean keepDisplayOn = false;
34 |
35 | private AndroidAudioRecorder(Activity activity) {
36 | this.activity = activity;
37 | }
38 |
39 | private AndroidAudioRecorder(Fragment fragment) {
40 | this.fragment = fragment;
41 | }
42 |
43 | public static AndroidAudioRecorder with(Activity activity) {
44 | return new AndroidAudioRecorder(activity);
45 | }
46 |
47 | public static AndroidAudioRecorder with(Fragment fragment) {
48 | return new AndroidAudioRecorder(fragment);
49 | }
50 |
51 | public AndroidAudioRecorder setFilePath(String filePath) {
52 | this.filePath = filePath;
53 | return this;
54 | }
55 |
56 | public AndroidAudioRecorder setColor(int color) {
57 | this.color = color;
58 | return this;
59 | }
60 |
61 | public AndroidAudioRecorder setRequestCode(int requestCode) {
62 | this.requestCode = requestCode;
63 | return this;
64 | }
65 |
66 | public AndroidAudioRecorder setSource(AudioSource source) {
67 | this.source = source;
68 | return this;
69 | }
70 |
71 | public AndroidAudioRecorder setChannel(AudioChannel channel) {
72 | this.channel = channel;
73 | return this;
74 | }
75 |
76 | public AndroidAudioRecorder setSampleRate(AudioSampleRate sampleRate) {
77 | this.sampleRate = sampleRate;
78 | return this;
79 | }
80 |
81 | public AndroidAudioRecorder setAutoStart(boolean autoStart) {
82 | this.autoStart = autoStart;
83 | return this;
84 | }
85 |
86 | public AndroidAudioRecorder setKeepDisplayOn(boolean keepDisplayOn) {
87 | this.keepDisplayOn = keepDisplayOn;
88 | return this;
89 | }
90 |
91 | public void record() {
92 | Intent intent = new Intent(activity, AudioRecorderActivity.class);
93 | intent.putExtra(EXTRA_FILE_PATH, filePath);
94 | intent.putExtra(EXTRA_COLOR, color);
95 | intent.putExtra(EXTRA_SOURCE, source);
96 | intent.putExtra(EXTRA_CHANNEL, channel);
97 | intent.putExtra(EXTRA_SAMPLE_RATE, sampleRate);
98 | intent.putExtra(EXTRA_AUTO_START, autoStart);
99 | intent.putExtra(EXTRA_KEEP_DISPLAY_ON, keepDisplayOn);
100 | activity.startActivityForResult(intent, requestCode);
101 | }
102 |
103 | public void recordFromFragment() {
104 | Intent intent = new Intent(fragment.getActivity(), AudioRecorderActivity.class);
105 | intent.putExtra(EXTRA_FILE_PATH, filePath);
106 | intent.putExtra(EXTRA_COLOR, color);
107 | intent.putExtra(EXTRA_SOURCE, source);
108 | intent.putExtra(EXTRA_CHANNEL, channel);
109 | intent.putExtra(EXTRA_SAMPLE_RATE, sampleRate);
110 | intent.putExtra(EXTRA_AUTO_START, autoStart);
111 | intent.putExtra(EXTRA_KEEP_DISPLAY_ON, keepDisplayOn);
112 | fragment.startActivityForResult(intent, requestCode);
113 | }
114 |
115 | }
116 |
--------------------------------------------------------------------------------
/lib/src/main/java/cafe/adriel/androidaudiorecorder/AudioRecorderActivity.java:
--------------------------------------------------------------------------------
1 | package cafe.adriel.androidaudiorecorder;
2 |
3 | import android.graphics.Color;
4 | import android.graphics.PorterDuff;
5 | import android.graphics.drawable.ColorDrawable;
6 | import android.media.MediaPlayer;
7 | import android.os.Bundle;
8 | import android.support.v4.content.ContextCompat;
9 | import android.support.v7.app.AppCompatActivity;
10 | import android.view.Menu;
11 | import android.view.MenuItem;
12 | import android.view.View;
13 | import android.view.WindowManager;
14 | import android.widget.ImageButton;
15 | import android.widget.RelativeLayout;
16 | import android.widget.TextView;
17 |
18 | import com.cleveroad.audiovisualization.DbmHandler;
19 | import com.cleveroad.audiovisualization.GLAudioVisualizationView;
20 |
21 | import java.io.File;
22 | import java.util.Timer;
23 | import java.util.TimerTask;
24 |
25 | import cafe.adriel.androidaudiorecorder.model.AudioChannel;
26 | import cafe.adriel.androidaudiorecorder.model.AudioSampleRate;
27 | import cafe.adriel.androidaudiorecorder.model.AudioSource;
28 | import omrecorder.AudioChunk;
29 | import omrecorder.OmRecorder;
30 | import omrecorder.PullTransport;
31 | import omrecorder.Recorder;
32 |
33 | public class AudioRecorderActivity extends AppCompatActivity
34 | implements PullTransport.OnAudioChunkPulledListener, MediaPlayer.OnCompletionListener {
35 |
36 | private String filePath;
37 | private AudioSource source;
38 | private AudioChannel channel;
39 | private AudioSampleRate sampleRate;
40 | private int color;
41 | private boolean autoStart;
42 | private boolean keepDisplayOn;
43 |
44 | private MediaPlayer player;
45 | private Recorder recorder;
46 | private VisualizerHandler visualizerHandler;
47 |
48 | private Timer timer;
49 | private MenuItem saveMenuItem;
50 | private int recorderSecondsElapsed;
51 | private int playerSecondsElapsed;
52 | private boolean isRecording;
53 |
54 | private RelativeLayout contentLayout;
55 | private GLAudioVisualizationView visualizerView;
56 | private TextView statusView;
57 | private TextView timerView;
58 | private ImageButton restartView;
59 | private ImageButton recordView;
60 | private ImageButton playView;
61 |
62 | @Override
63 | protected void onCreate(Bundle savedInstanceState) {
64 | super.onCreate(savedInstanceState);
65 | setContentView(R.layout.aar_activity_audio_recorder);
66 |
67 | if(savedInstanceState != null) {
68 | filePath = savedInstanceState.getString(AndroidAudioRecorder.EXTRA_FILE_PATH);
69 | source = (AudioSource) savedInstanceState.getSerializable(AndroidAudioRecorder.EXTRA_SOURCE);
70 | channel = (AudioChannel) savedInstanceState.getSerializable(AndroidAudioRecorder.EXTRA_CHANNEL);
71 | sampleRate = (AudioSampleRate) savedInstanceState.getSerializable(AndroidAudioRecorder.EXTRA_SAMPLE_RATE);
72 | color = savedInstanceState.getInt(AndroidAudioRecorder.EXTRA_COLOR);
73 | autoStart = savedInstanceState.getBoolean(AndroidAudioRecorder.EXTRA_AUTO_START);
74 | keepDisplayOn = savedInstanceState.getBoolean(AndroidAudioRecorder.EXTRA_KEEP_DISPLAY_ON);
75 | } else {
76 | filePath = getIntent().getStringExtra(AndroidAudioRecorder.EXTRA_FILE_PATH);
77 | source = (AudioSource) getIntent().getSerializableExtra(AndroidAudioRecorder.EXTRA_SOURCE);
78 | channel = (AudioChannel) getIntent().getSerializableExtra(AndroidAudioRecorder.EXTRA_CHANNEL);
79 | sampleRate = (AudioSampleRate) getIntent().getSerializableExtra(AndroidAudioRecorder.EXTRA_SAMPLE_RATE);
80 | color = getIntent().getIntExtra(AndroidAudioRecorder.EXTRA_COLOR, Color.BLACK);
81 | autoStart = getIntent().getBooleanExtra(AndroidAudioRecorder.EXTRA_AUTO_START, false);
82 | keepDisplayOn = getIntent().getBooleanExtra(AndroidAudioRecorder.EXTRA_KEEP_DISPLAY_ON, false);
83 | }
84 |
85 | if(keepDisplayOn){
86 | getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
87 | }
88 |
89 | if (getSupportActionBar() != null) {
90 | getSupportActionBar().setHomeButtonEnabled(true);
91 | getSupportActionBar().setDisplayHomeAsUpEnabled(true);
92 | getSupportActionBar().setDisplayShowTitleEnabled(false);
93 | getSupportActionBar().setElevation(0);
94 | getSupportActionBar().setBackgroundDrawable(
95 | new ColorDrawable(Util.getDarkerColor(color)));
96 | getSupportActionBar().setHomeAsUpIndicator(
97 | ContextCompat.getDrawable(this, R.drawable.aar_ic_clear));
98 | }
99 |
100 | visualizerView = new GLAudioVisualizationView.Builder(this)
101 | .setLayersCount(1)
102 | .setWavesCount(6)
103 | .setWavesHeight(R.dimen.aar_wave_height)
104 | .setWavesFooterHeight(R.dimen.aar_footer_height)
105 | .setBubblesPerLayer(20)
106 | .setBubblesSize(R.dimen.aar_bubble_size)
107 | .setBubblesRandomizeSize(true)
108 | .setBackgroundColor(Util.getDarkerColor(color))
109 | .setLayerColors(new int[]{color})
110 | .build();
111 |
112 | contentLayout = (RelativeLayout) findViewById(R.id.content);
113 | statusView = (TextView) findViewById(R.id.status);
114 | timerView = (TextView) findViewById(R.id.timer);
115 | restartView = (ImageButton) findViewById(R.id.restart);
116 | recordView = (ImageButton) findViewById(R.id.record);
117 | playView = (ImageButton) findViewById(R.id.play);
118 |
119 | contentLayout.setBackgroundColor(Util.getDarkerColor(color));
120 | contentLayout.addView(visualizerView, 0);
121 | restartView.setVisibility(View.INVISIBLE);
122 | playView.setVisibility(View.INVISIBLE);
123 |
124 | if(Util.isBrightColor(color)) {
125 | ContextCompat.getDrawable(this, R.drawable.aar_ic_clear)
126 | .setColorFilter(Color.BLACK, PorterDuff.Mode.SRC_ATOP);
127 | ContextCompat.getDrawable(this, R.drawable.aar_ic_check)
128 | .setColorFilter(Color.BLACK, PorterDuff.Mode.SRC_ATOP);
129 | statusView.setTextColor(Color.BLACK);
130 | timerView.setTextColor(Color.BLACK);
131 | restartView.setColorFilter(Color.BLACK);
132 | recordView.setColorFilter(Color.BLACK);
133 | playView.setColorFilter(Color.BLACK);
134 | }
135 | }
136 |
137 | @Override
138 | public void onPostCreate(Bundle savedInstanceState) {
139 | super.onPostCreate(savedInstanceState);
140 | if(autoStart && !isRecording){
141 | toggleRecording(null);
142 | }
143 | }
144 |
145 | @Override
146 | public void onResume() {
147 | super.onResume();
148 | try {
149 | visualizerView.onResume();
150 | } catch (Exception e){ }
151 | }
152 |
153 | @Override
154 | protected void onPause() {
155 | restartRecording(null);
156 | try {
157 | visualizerView.onPause();
158 | } catch (Exception e){ }
159 | super.onPause();
160 | }
161 |
162 | @Override
163 | protected void onDestroy() {
164 | restartRecording(null);
165 | setResult(RESULT_CANCELED);
166 | try {
167 | visualizerView.release();
168 | } catch (Exception e){ }
169 | super.onDestroy();
170 | }
171 |
172 | @Override
173 | protected void onSaveInstanceState(Bundle outState) {
174 | outState.putString(AndroidAudioRecorder.EXTRA_FILE_PATH, filePath);
175 | outState.putInt(AndroidAudioRecorder.EXTRA_COLOR, color);
176 | super.onSaveInstanceState(outState);
177 | }
178 |
179 | @Override
180 | public boolean onCreateOptionsMenu(Menu menu) {
181 | getMenuInflater().inflate(R.menu.aar_audio_recorder, menu);
182 | saveMenuItem = menu.findItem(R.id.action_save);
183 | saveMenuItem.setIcon(ContextCompat.getDrawable(this, R.drawable.aar_ic_check));
184 | return super.onCreateOptionsMenu(menu);
185 | }
186 |
187 | @Override
188 | public boolean onOptionsItemSelected(MenuItem item) {
189 | int i = item.getItemId();
190 | if (i == android.R.id.home) {
191 | finish();
192 | } else if (i == R.id.action_save) {
193 | selectAudio();
194 | }
195 | return super.onOptionsItemSelected(item);
196 | }
197 |
198 | @Override
199 | public void onAudioChunkPulled(AudioChunk audioChunk) {
200 | float amplitude = isRecording ? (float) audioChunk.maxAmplitude() : 0f;
201 | visualizerHandler.onDataReceived(amplitude);
202 | }
203 |
204 | @Override
205 | public void onCompletion(MediaPlayer mediaPlayer) {
206 | stopPlaying();
207 | }
208 |
209 | private void selectAudio() {
210 | stopRecording();
211 | setResult(RESULT_OK);
212 | finish();
213 | }
214 |
215 | public void toggleRecording(View v) {
216 | stopPlaying();
217 | Util.wait(100, new Runnable() {
218 | @Override
219 | public void run() {
220 | if (isRecording) {
221 | pauseRecording();
222 | } else {
223 | resumeRecording();
224 | }
225 | }
226 | });
227 | }
228 |
229 | public void togglePlaying(View v){
230 | pauseRecording();
231 | Util.wait(100, new Runnable() {
232 | @Override
233 | public void run() {
234 | if(isPlaying()){
235 | stopPlaying();
236 | } else {
237 | startPlaying();
238 | }
239 | }
240 | });
241 | }
242 |
243 | public void restartRecording(View v){
244 | if(isRecording) {
245 | stopRecording();
246 | } else if(isPlaying()) {
247 | stopPlaying();
248 | } else {
249 | visualizerHandler = new VisualizerHandler();
250 | visualizerView.linkTo(visualizerHandler);
251 | visualizerView.release();
252 | if(visualizerHandler != null) {
253 | visualizerHandler.stop();
254 | }
255 | }
256 | saveMenuItem.setVisible(false);
257 | statusView.setVisibility(View.INVISIBLE);
258 | restartView.setVisibility(View.INVISIBLE);
259 | playView.setVisibility(View.INVISIBLE);
260 | recordView.setImageResource(R.drawable.aar_ic_rec);
261 | timerView.setText("00:00:00");
262 | recorderSecondsElapsed = 0;
263 | playerSecondsElapsed = 0;
264 | }
265 |
266 | private void resumeRecording() {
267 | isRecording = true;
268 | saveMenuItem.setVisible(false);
269 | statusView.setText(R.string.aar_recording);
270 | statusView.setVisibility(View.VISIBLE);
271 | restartView.setVisibility(View.INVISIBLE);
272 | playView.setVisibility(View.INVISIBLE);
273 | recordView.setImageResource(R.drawable.aar_ic_pause);
274 | playView.setImageResource(R.drawable.aar_ic_play);
275 |
276 | visualizerHandler = new VisualizerHandler();
277 | visualizerView.linkTo(visualizerHandler);
278 |
279 | if(recorder == null) {
280 | timerView.setText("00:00:00");
281 |
282 | recorder = OmRecorder.wav(
283 | new PullTransport.Default(Util.getMic(source, channel, sampleRate), AudioRecorderActivity.this),
284 | new File(filePath));
285 | }
286 | recorder.resumeRecording();
287 |
288 | startTimer();
289 | }
290 |
291 | private void pauseRecording() {
292 | isRecording = false;
293 | if(!isFinishing()) {
294 | saveMenuItem.setVisible(true);
295 | }
296 | statusView.setText(R.string.aar_paused);
297 | statusView.setVisibility(View.VISIBLE);
298 | restartView.setVisibility(View.VISIBLE);
299 | playView.setVisibility(View.VISIBLE);
300 | recordView.setImageResource(R.drawable.aar_ic_rec);
301 | playView.setImageResource(R.drawable.aar_ic_play);
302 |
303 | visualizerView.release();
304 | if(visualizerHandler != null) {
305 | visualizerHandler.stop();
306 | }
307 |
308 | if (recorder != null) {
309 | recorder.pauseRecording();
310 | }
311 |
312 | stopTimer();
313 | }
314 |
315 | private void stopRecording(){
316 | visualizerView.release();
317 | if(visualizerHandler != null) {
318 | visualizerHandler.stop();
319 | }
320 |
321 | recorderSecondsElapsed = 0;
322 | if (recorder != null) {
323 | recorder.stopRecording();
324 | recorder = null;
325 | }
326 |
327 | stopTimer();
328 | }
329 |
330 | private void startPlaying(){
331 | try {
332 | stopRecording();
333 | player = new MediaPlayer();
334 | player.setDataSource(filePath);
335 | player.prepare();
336 | player.start();
337 |
338 | visualizerView.linkTo(DbmHandler.Factory.newVisualizerHandler(this, player));
339 | visualizerView.post(new Runnable() {
340 | @Override
341 | public void run() {
342 | player.setOnCompletionListener(AudioRecorderActivity.this);
343 | }
344 | });
345 |
346 | timerView.setText("00:00:00");
347 | statusView.setText(R.string.aar_playing);
348 | statusView.setVisibility(View.VISIBLE);
349 | playView.setImageResource(R.drawable.aar_ic_stop);
350 |
351 | playerSecondsElapsed = 0;
352 | startTimer();
353 | } catch (Exception e){
354 | e.printStackTrace();
355 | }
356 | }
357 |
358 | private void stopPlaying(){
359 | statusView.setText("");
360 | statusView.setVisibility(View.INVISIBLE);
361 | playView.setImageResource(R.drawable.aar_ic_play);
362 |
363 | visualizerView.release();
364 | if(visualizerHandler != null) {
365 | visualizerHandler.stop();
366 | }
367 |
368 | if(player != null){
369 | try {
370 | player.stop();
371 | player.reset();
372 | } catch (Exception e){ }
373 | }
374 |
375 | stopTimer();
376 | }
377 |
378 | private boolean isPlaying(){
379 | try {
380 | return player != null && player.isPlaying() && !isRecording;
381 | } catch (Exception e){
382 | return false;
383 | }
384 | }
385 |
386 | private void startTimer(){
387 | stopTimer();
388 | timer = new Timer();
389 | timer.scheduleAtFixedRate(new TimerTask() {
390 | @Override
391 | public void run() {
392 | updateTimer();
393 | }
394 | }, 0, 1000);
395 | }
396 |
397 | private void stopTimer(){
398 | if (timer != null) {
399 | timer.cancel();
400 | timer.purge();
401 | timer = null;
402 | }
403 | }
404 |
405 | private void updateTimer() {
406 | runOnUiThread(new Runnable() {
407 | @Override
408 | public void run() {
409 | if(isRecording) {
410 | recorderSecondsElapsed++;
411 | timerView.setText(Util.formatSeconds(recorderSecondsElapsed));
412 | } else if(isPlaying()){
413 | playerSecondsElapsed++;
414 | timerView.setText(Util.formatSeconds(playerSecondsElapsed));
415 | }
416 | }
417 | });
418 | }
419 | }
420 |
--------------------------------------------------------------------------------
/lib/src/main/java/cafe/adriel/androidaudiorecorder/Util.java:
--------------------------------------------------------------------------------
1 | package cafe.adriel.androidaudiorecorder;
2 |
3 | import android.graphics.Color;
4 | import android.media.AudioFormat;
5 | import android.os.Handler;
6 |
7 | import cafe.adriel.androidaudiorecorder.model.AudioChannel;
8 | import cafe.adriel.androidaudiorecorder.model.AudioSampleRate;
9 | import cafe.adriel.androidaudiorecorder.model.AudioSource;
10 |
11 |
12 | public class Util {
13 | private static final Handler HANDLER = new Handler();
14 |
15 | private Util() {
16 | }
17 |
18 | public static void wait(int millis, Runnable callback){
19 | HANDLER.postDelayed(callback, millis);
20 | }
21 |
22 | public static omrecorder.AudioSource getMic(AudioSource source,
23 | AudioChannel channel,
24 | AudioSampleRate sampleRate) {
25 | return new omrecorder.AudioSource.Smart(
26 | source.getSource(),
27 | AudioFormat.ENCODING_PCM_16BIT,
28 | channel.getChannel(),
29 | sampleRate.getSampleRate());
30 | }
31 |
32 | public static boolean isBrightColor(int color) {
33 | if(android.R.color.transparent == color) {
34 | return true;
35 | }
36 | int [] rgb = {Color.red(color), Color.green(color), Color.blue(color)};
37 | int brightness = (int) Math.sqrt(
38 | rgb[0] * rgb[0] * 0.241 +
39 | rgb[1] * rgb[1] * 0.691 +
40 | rgb[2] * rgb[2] * 0.068);
41 | return brightness >= 200;
42 | }
43 |
44 | public static int getDarkerColor(int color) {
45 | float factor = 0.8f;
46 | int a = Color.alpha(color);
47 | int r = Color.red(color);
48 | int g = Color.green(color);
49 | int b = Color.blue(color);
50 | return Color.argb(a,
51 | Math.max((int) (r * factor), 0),
52 | Math.max((int) (g * factor), 0),
53 | Math.max((int) (b * factor), 0));
54 | }
55 |
56 | public static String formatSeconds(int seconds) {
57 | return getTwoDecimalsValue(seconds / 3600) + ":"
58 | + getTwoDecimalsValue(seconds / 60) + ":"
59 | + getTwoDecimalsValue(seconds % 60);
60 | }
61 |
62 | private static String getTwoDecimalsValue(int value) {
63 | if (value >= 0 && value <= 9) {
64 | return "0" + value;
65 | } else {
66 | return value + "";
67 | }
68 | }
69 |
70 | }
--------------------------------------------------------------------------------
/lib/src/main/java/cafe/adriel/androidaudiorecorder/VisualizerHandler.java:
--------------------------------------------------------------------------------
1 | package cafe.adriel.androidaudiorecorder;
2 |
3 | import com.cleveroad.audiovisualization.DbmHandler;
4 |
5 | public class VisualizerHandler extends DbmHandler {
6 |
7 | @Override
8 | protected void onDataReceivedImpl(Float amplitude, int layersCount, float[] dBmArray, float[] ampsArray) {
9 | amplitude = amplitude / 100;
10 | if(amplitude <= 0.5){
11 | amplitude = 0.0f;
12 | } else if(amplitude > 0.5 && amplitude <= 0.6){
13 | amplitude = 0.2f;
14 | } else if(amplitude > 0.6 && amplitude <= 0.7){
15 | amplitude = 0.6f;
16 | } else if(amplitude > 0.7){
17 | amplitude = 1f;
18 | }
19 | try {
20 | dBmArray[0] = amplitude;
21 | ampsArray[0] = amplitude;
22 | } catch (Exception e){ }
23 | }
24 |
25 | public void stop() {
26 | try {
27 | calmDownAndStopRendering();
28 | } catch (Exception e){ }
29 | }
30 |
31 | }
--------------------------------------------------------------------------------
/lib/src/main/java/cafe/adriel/androidaudiorecorder/model/AudioChannel.java:
--------------------------------------------------------------------------------
1 | package cafe.adriel.androidaudiorecorder.model;
2 |
3 | import android.media.AudioFormat;
4 |
5 | public enum AudioChannel {
6 | STEREO,
7 | MONO;
8 |
9 | public int getChannel(){
10 | switch (this){
11 | case MONO:
12 | return AudioFormat.CHANNEL_IN_MONO;
13 | default:
14 | return AudioFormat.CHANNEL_IN_STEREO;
15 | }
16 | }
17 | }
--------------------------------------------------------------------------------
/lib/src/main/java/cafe/adriel/androidaudiorecorder/model/AudioSampleRate.java:
--------------------------------------------------------------------------------
1 | package cafe.adriel.androidaudiorecorder.model;
2 |
3 | public enum AudioSampleRate {
4 | HZ_48000,
5 | HZ_44100,
6 | HZ_32000,
7 | HZ_22050,
8 | HZ_16000,
9 | HZ_11025,
10 | HZ_8000;
11 |
12 | public int getSampleRate(){
13 | return Integer.parseInt(name().replace("HZ_", ""));
14 | }
15 | }
--------------------------------------------------------------------------------
/lib/src/main/java/cafe/adriel/androidaudiorecorder/model/AudioSource.java:
--------------------------------------------------------------------------------
1 | package cafe.adriel.androidaudiorecorder.model;
2 |
3 | import android.media.MediaRecorder;
4 |
5 | public enum AudioSource {
6 | MIC,
7 | CAMCORDER;
8 |
9 | public int getSource(){
10 | switch (this){
11 | case CAMCORDER:
12 | return MediaRecorder.AudioSource.CAMCORDER;
13 | default:
14 | return MediaRecorder.AudioSource.MIC;
15 | }
16 | }
17 | }
--------------------------------------------------------------------------------
/lib/src/main/res/drawable-hdpi/aar_ic_check.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adrielcafe/AndroidAudioRecorder/242f73b160cd60c85c5320c13ec7dcf488892178/lib/src/main/res/drawable-hdpi/aar_ic_check.png
--------------------------------------------------------------------------------
/lib/src/main/res/drawable-hdpi/aar_ic_clear.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adrielcafe/AndroidAudioRecorder/242f73b160cd60c85c5320c13ec7dcf488892178/lib/src/main/res/drawable-hdpi/aar_ic_clear.png
--------------------------------------------------------------------------------
/lib/src/main/res/drawable-mdpi/aar_ic_check.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adrielcafe/AndroidAudioRecorder/242f73b160cd60c85c5320c13ec7dcf488892178/lib/src/main/res/drawable-mdpi/aar_ic_check.png
--------------------------------------------------------------------------------
/lib/src/main/res/drawable-mdpi/aar_ic_clear.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adrielcafe/AndroidAudioRecorder/242f73b160cd60c85c5320c13ec7dcf488892178/lib/src/main/res/drawable-mdpi/aar_ic_clear.png
--------------------------------------------------------------------------------
/lib/src/main/res/drawable-xhdpi/aar_ic_check.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adrielcafe/AndroidAudioRecorder/242f73b160cd60c85c5320c13ec7dcf488892178/lib/src/main/res/drawable-xhdpi/aar_ic_check.png
--------------------------------------------------------------------------------
/lib/src/main/res/drawable-xhdpi/aar_ic_clear.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adrielcafe/AndroidAudioRecorder/242f73b160cd60c85c5320c13ec7dcf488892178/lib/src/main/res/drawable-xhdpi/aar_ic_clear.png
--------------------------------------------------------------------------------
/lib/src/main/res/drawable-xxhdpi/aar_ic_check.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adrielcafe/AndroidAudioRecorder/242f73b160cd60c85c5320c13ec7dcf488892178/lib/src/main/res/drawable-xxhdpi/aar_ic_check.png
--------------------------------------------------------------------------------
/lib/src/main/res/drawable-xxhdpi/aar_ic_clear.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adrielcafe/AndroidAudioRecorder/242f73b160cd60c85c5320c13ec7dcf488892178/lib/src/main/res/drawable-xxhdpi/aar_ic_clear.png
--------------------------------------------------------------------------------
/lib/src/main/res/drawable-xxxhdpi/aar_ic_check.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adrielcafe/AndroidAudioRecorder/242f73b160cd60c85c5320c13ec7dcf488892178/lib/src/main/res/drawable-xxxhdpi/aar_ic_check.png
--------------------------------------------------------------------------------
/lib/src/main/res/drawable-xxxhdpi/aar_ic_clear.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adrielcafe/AndroidAudioRecorder/242f73b160cd60c85c5320c13ec7dcf488892178/lib/src/main/res/drawable-xxxhdpi/aar_ic_clear.png
--------------------------------------------------------------------------------
/lib/src/main/res/drawable/aar_ic_pause.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adrielcafe/AndroidAudioRecorder/242f73b160cd60c85c5320c13ec7dcf488892178/lib/src/main/res/drawable/aar_ic_pause.png
--------------------------------------------------------------------------------
/lib/src/main/res/drawable/aar_ic_play.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adrielcafe/AndroidAudioRecorder/242f73b160cd60c85c5320c13ec7dcf488892178/lib/src/main/res/drawable/aar_ic_play.png
--------------------------------------------------------------------------------
/lib/src/main/res/drawable/aar_ic_rec.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adrielcafe/AndroidAudioRecorder/242f73b160cd60c85c5320c13ec7dcf488892178/lib/src/main/res/drawable/aar_ic_rec.png
--------------------------------------------------------------------------------
/lib/src/main/res/drawable/aar_ic_restart.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adrielcafe/AndroidAudioRecorder/242f73b160cd60c85c5320c13ec7dcf488892178/lib/src/main/res/drawable/aar_ic_restart.png
--------------------------------------------------------------------------------
/lib/src/main/res/drawable/aar_ic_stop.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adrielcafe/AndroidAudioRecorder/242f73b160cd60c85c5320c13ec7dcf488892178/lib/src/main/res/drawable/aar_ic_stop.png
--------------------------------------------------------------------------------
/lib/src/main/res/layout/aar_activity_audio_recorder.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
17 |
18 |
27 |
28 |
36 |
37 |
38 |
39 |
43 |
44 |
58 |
59 |
71 |
72 |
85 |
86 |
87 |
88 |
--------------------------------------------------------------------------------
/lib/src/main/res/menu/aar_audio_recorder.xml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/lib/src/main/res/values-pt/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Salvar
3 | Pausado
4 | Gravando
5 | Reproduzindo
6 |
--------------------------------------------------------------------------------
/lib/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 60dp
4 | 30dp
5 | 200dp
6 |
--------------------------------------------------------------------------------
/lib/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | AndroidAudioRecorder
3 | Save
4 | Paused
5 | Recording
6 | Playing
7 |
--------------------------------------------------------------------------------
/screenshots.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adrielcafe/AndroidAudioRecorder/242f73b160cd60c85c5320c13ec7dcf488892178/screenshots.png
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':lib'
2 |
--------------------------------------------------------------------------------