├── reactiveaudiorecord
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ └── values
│ │ │ │ └── strings.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── minimize
│ │ │ └── library
│ │ │ └── RecorderOnSubscribe.java
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── example
│ │ │ └── reactiveaudiorecord
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── example
│ │ └── reactiveaudiorecord
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── .idea
├── copyright
│ └── profiles_settings.xml
├── vcs.xml
├── libraries
│ ├── javax_inject_1.xml
│ ├── jsr305_2_0_1.xml
│ ├── javawriter_2_1_1.xml
│ ├── hamcrest_library_1_3.xml
│ ├── hamcrest_integration_1_3.xml
│ ├── javax_annotation_api_1_2.xml
│ ├── constraint_layout_solver_1_0_0_alpha3.xml
│ ├── junit_4_12.xml
│ ├── constraint_layout_1_0_0_alpha3.xml
│ ├── rxjava_1_1_6.xml
│ ├── hamcrest_core_1_3.xml
│ ├── support_annotations_24_0_0.xml
│ ├── chronometerpersist_1_0_0.xml
│ ├── rxandroid_1_2_1.xml
│ ├── espresso_core_2_2_2.xml
│ ├── support_vector_drawable_24_0_0.xml
│ ├── animated_vector_drawable_24_0_0.xml
│ ├── espresso_idling_resource_2_2_2.xml
│ ├── exposed_instrumentation_api_publish_0_5.xml
│ ├── rules_0_5.xml
│ ├── runner_0_5.xml
│ ├── appcompat_v7_24_0_0.xml
│ └── support_v4_24_0_0.xml
├── modules.xml
├── gradle.xml
├── compiler.xml
└── misc.xml
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── sample
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── styles.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-w820dp
│ │ │ │ └── dimens.xml
│ │ │ └── layout
│ │ │ │ └── activity_main.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── minimize
│ │ │ └── android
│ │ │ └── recorder
│ │ │ └── MainActivity.java
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── example
│ │ │ └── arkhitech
│ │ │ └── reactiveaudiorecord
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── example
│ │ └── arkhitech
│ │ └── reactiveaudiorecord
│ │ └── ExampleInstrumentedTest.java
├── .gitignore
├── proguard-rules.pro
└── build.gradle
├── .gitignore
├── gradle.properties
├── ReactiveAudioRecord.iml
├── gradlew.bat
├── README.md
└── gradlew
/reactiveaudiorecord/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':sample', ':reactiveaudiorecord'
2 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ahmedrizwan/ReactiveAudioRecord/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/sample/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | ReactiveAudioRecord
3 |
4 |
--------------------------------------------------------------------------------
/reactiveaudiorecord/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Reactive Audio Record
3 |
4 |
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ahmedrizwan/ReactiveAudioRecord/HEAD/sample/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ahmedrizwan/ReactiveAudioRecord/HEAD/sample/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ahmedrizwan/ReactiveAudioRecord/HEAD/sample/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ahmedrizwan/ReactiveAudioRecord/HEAD/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ahmedrizwan/ReactiveAudioRecord/HEAD/sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/reactiveaudiorecord/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
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.10-all.zip
7 |
--------------------------------------------------------------------------------
/.idea/libraries/javax_inject_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/libraries/jsr305_2_0_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/libraries/javawriter_2_1_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/libraries/hamcrest_library_1_3.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/libraries/hamcrest_integration_1_3.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/libraries/javax_annotation_api_1_2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/sample/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/.idea/libraries/constraint_layout_solver_1_0_0_alpha3.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/libraries/junit_4_12.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/libraries/constraint_layout_1_0_0_alpha3.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/libraries/rxjava_1_1_6.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/sample/src/test/java/com/example/arkhitech/reactiveaudiorecord/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.example.arkhitech.reactiveaudiorecord;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/reactiveaudiorecord/src/test/java/com/example/reactiveaudiorecord/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.example.reactiveaudiorecord;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest
13 | {
14 | @Test
15 | public void addition_isCorrect() throws Exception
16 | {
17 | assertEquals(4, 2 + 2);
18 | }
19 | }
--------------------------------------------------------------------------------
/.idea/libraries/hamcrest_core_1_3.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/libraries/support_annotations_24_0_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 | ### Android template
3 | # Built application files
4 | *.apk
5 | *.ap_
6 |
7 | # Files for the ART/Dalvik VM
8 | *.dex
9 |
10 | # Java class files
11 | *.class
12 |
13 | # Generated files
14 | bin/
15 | gen/
16 | out/
17 |
18 | # Gradle files
19 | .gradle/
20 | build/
21 |
22 | # Local configuration file (sdk path, etc)
23 | local.properties
24 |
25 | # Proguard folder generated by Eclipse
26 | proguard/
27 |
28 | # Log Files
29 | *.log
30 |
31 | # Android Studio Navigation editor temp files
32 | .navigation/
33 |
34 | # Android Studio captures folder
35 | captures/
36 |
37 | # Intellij
38 | *.iml
39 | .idea/workspace.xml
40 |
41 | # Keystore files
42 | *.jks
43 |
44 |
--------------------------------------------------------------------------------
/sample/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 | ### Android template
3 | # Built application files
4 | *.apk
5 | *.ap_
6 |
7 | # Files for the ART/Dalvik VM
8 | *.dex
9 |
10 | # Java class files
11 | *.class
12 |
13 | # Generated files
14 | bin/
15 | gen/
16 | out/
17 |
18 | # Gradle files
19 | .gradle/
20 | build/
21 |
22 | # Local configuration file (sdk path, etc)
23 | local.properties
24 |
25 | # Proguard folder generated by Eclipse
26 | proguard/
27 |
28 | # Log Files
29 | *.log
30 |
31 | # Android Studio Navigation editor temp files
32 | .navigation/
33 |
34 | # Android Studio captures folder
35 | captures/
36 |
37 | # Intellij
38 | *.iml
39 | .idea/workspace.xml
40 |
41 | # Keystore files
42 | *.jks
43 |
44 |
--------------------------------------------------------------------------------
/.idea/libraries/chronometerpersist_1_0_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/sample/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/Arkhitech/Library/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 |
--------------------------------------------------------------------------------
/reactiveaudiorecord/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/Arkhitech/Library/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 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
18 |
19 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/.idea/libraries/rxandroid_1_2_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/espresso_core_2_2_2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/support_vector_drawable_24_0_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/animated_vector_drawable_24_0_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/ReactiveAudioRecord.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/sample/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/reactiveaudiorecord/src/androidTest/java/com/example/reactiveaudiorecord/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.example.reactiveaudiorecord;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest
19 | {
20 | @Test
21 | public void useAppContext() throws Exception
22 | {
23 | // Context of the app under test.
24 | Context appContext = InstrumentationRegistry.getTargetContext();
25 |
26 | assertEquals("com.example.reactiveaudiorecord.test", appContext.getPackageName());
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/sample/src/androidTest/java/com/example/arkhitech/reactiveaudiorecord/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.example.arkhitech.reactiveaudiorecord;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.example.arkhitech.reactiveaudiorecord", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/.idea/libraries/espresso_idling_resource_2_2_2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/exposed_instrumentation_api_publish_0_5.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/rules_0_5.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/.idea/libraries/runner_0_5.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/.idea/libraries/appcompat_v7_24_0_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/sample/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 24
5 | buildToolsVersion "24.0.0"
6 | defaultConfig {
7 | applicationId "com.minimize.android.recorder"
8 | minSdkVersion 16
9 | targetSdkVersion 24
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(include: ['*.jar'], dir: 'libs')
24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
25 | exclude group: 'com.android.support', module: 'support-annotations'
26 | })
27 | compile 'com.android.support:appcompat-v7:24.0.0'
28 | compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha3'
29 | testCompile 'junit:junit:4.12'
30 | compile 'com.minimize.library:chronometerpersist:1.0.0'
31 | compile project(':reactiveaudiorecord')
32 | }
33 |
--------------------------------------------------------------------------------
/.idea/libraries/support_v4_24_0_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/reactiveaudiorecord/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | ext {
3 | // Where you will see your artifact in Bintray's web interface
4 | // The "bintrayName" should match the name of the Bintray repro.
5 | bintrayRepo = 'maven'
6 | bintrayName = 'reactiveaudiorecord'
7 |
8 | // Maven metadata
9 | publishedGroupId = 'com.minimize.library'
10 | libraryName = 'ReactiveAudioRecord'
11 | // Save yourself a head ache, and set this equal to the name of the Android Studio library
12 | // module. The artifact name needs to match the name of the library.
13 | artifact = 'reactiveaudiorecord'
14 |
15 | libraryDescription = 'A reactive wrapper library for Android AudioRecord.'
16 | libraryVersion = '1.0.2'
17 |
18 | developerId = 'ahmedrizwan'
19 | developerName = 'Ahmed Rizwan'
20 | developerEmail = 'ahmedrizwan@outlook.com'
21 |
22 | }
23 | android {
24 | compileSdkVersion 24
25 | buildToolsVersion "24.0.0"
26 |
27 | defaultConfig {
28 | minSdkVersion 16
29 | targetSdkVersion 24
30 | versionCode 1
31 | versionName "1.0"
32 |
33 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
34 |
35 | }
36 | buildTypes {
37 | release {
38 | minifyEnabled false
39 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
40 | }
41 | }
42 | }
43 |
44 | dependencies {
45 | compile fileTree(dir: 'libs', include: ['*.jar'])
46 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
47 | exclude group: 'com.android.support', module: 'support-annotations'
48 | })
49 | compile 'com.android.support:appcompat-v7:24.0.0'
50 | testCompile 'junit:junit:4.12'
51 | compile 'io.reactivex:rxandroid:1.2.1'
52 | compile 'io.reactivex:rxjava:1.1.6'
53 | }
54 | apply from: 'https://raw.githubusercontent.com/attwellBrian/JCenter/master/installv1.gradle'
55 | apply from: 'https://raw.githubusercontent.com/attwellBrian/JCenter/master/bintrayv1.gradle'
56 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
21 |
31 |
42 |
51 |
52 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ReactiveAudioRecord
2 |
3 | [](https://bintray.com/sbrukhanda/maven/FragmentViewPager)
4 | [](https://github.com/sbrukhanda/fragmentviewpager/blob/master/LICENSE.txt)
5 | [](https://android-arsenal.com/details/1/2084)
6 |
7 | A reactive (Rx) implementation of the AudioRecord API for recording raw (pcm) audio-data. Also includes helper methods for the creation of Wave audio files.
8 |
9 | ### How to use it?
10 |
11 | ##### Create an instance of RecorderOnSubscribe giving it the path to the file
12 | ```java
13 | final String filePath = Environment.getExternalStorageDirectory() + "/sample.wav"; //dummy file
14 | RecorderOnSubscribe recorder = new RecorderOnSubscribe.Builder(filePath)
15 | .sampleRate(22000) //by default 44100
16 | .stereo() //by default mono
17 | .audioSourceCamcorder() //by default MIC
18 | .build();
19 | ```
20 | ##### Use the recorder OnSubscribe to create an observable
21 | ```java
22 | Observable.create(recorder)
23 | .subscribe( shorts -> {
24 | ...
25 | recorder.writeShortsToFile(shorts); //a helper method that writes the buffers to (wave) file
26 | });
27 | ```
28 |
29 | #### After setting up the Observer, manipulate the recording-process by using these methods
30 |
31 | | Name | Description |
32 | |:----:|:-----------:|
33 | | start() | Starts the recorder and moves it to *Recording* state |
34 | | stop() | Stops the recorder and moves it to *Stopped* state |
35 | | pause() | Pauses the recorder and moves it to *Paused* state |
36 | | resume() | Resumes the recorder if it's in *Paused* state |
37 | | isRecording() | Returns true if the recorder is in *Recording* state |
38 | | isRecordingStopped() | Checks whether the recorder is in *Stopped* state or not |
39 |
40 | #### Helper methods for wave file write operations
41 |
42 | | Name | Description |
43 | |:----:|:-----------:|
44 | | writeShortsToFile(shorts) | Writes the short buffers to wave file |
45 | | completeRecording() | Writes the Wave header info to the file (Call it after *stop()* method) |
46 |
47 | And that's it! Check out the sample code for a working example!
48 |
49 | ## Download
50 | Repository available on jCenter
51 |
52 | ```Gradle
53 | compile 'com.minimize.library:reactiveaudiorecord:1.0.2'
54 | ```
55 |
56 | ## License
57 | ```
58 | Copyright 2015 Ahmed Rizwan
59 |
60 | Licensed under the Apache License, Version 2.0 (the "License");
61 | you may not use this file except in compliance with the License.
62 | You may obtain a copy of the License at
63 |
64 | http://www.apache.org/licenses/LICENSE-2.0
65 |
66 | Unless required by applicable law or agreed to in writing, software
67 | distributed under the License is distributed on an "AS IS" BASIS,
68 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
69 | See the License for the specific language governing permissions and
70 | limitations under the License.
71 | ```
72 |
73 |
74 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/minimize/android/recorder/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.minimize.android.recorder;
2 |
3 | import com.example.arkhitech.reactiveaudiorecord.R;
4 | import com.minimize.library.RecorderOnSubscribe;
5 |
6 | import android.content.Intent;
7 | import android.net.Uri;
8 | import android.os.Bundle;
9 | import android.os.Environment;
10 | import android.support.v7.app.AppCompatActivity;
11 | import android.util.Log;
12 | import android.view.View;
13 | import android.widget.Chronometer;
14 | import android.widget.TextView;
15 |
16 | import java.io.File;
17 | import java.io.FileNotFoundException;
18 | import java.io.IOException;
19 |
20 | import library.minimize.com.chronometerpersist.ChronometerPersist;
21 | import rx.Observable;
22 | import rx.Subscription;
23 | import rx.functions.Action1;
24 |
25 | public class MainActivity extends AppCompatActivity
26 | {
27 | private Subscription mSubscription;
28 | private RecorderOnSubscribe mRecorderOnSubscribe;
29 |
30 |
31 | @Override
32 | protected void onCreate(Bundle savedInstanceState)
33 | {
34 | super.onCreate(savedInstanceState);
35 | setContentView(R.layout.activity_main);
36 |
37 |
38 | TextView textViewPath = (TextView) findViewById(R.id.textViewPath);
39 |
40 | Chronometer chronometer = (Chronometer) findViewById(R.id.chronometer);
41 |
42 | final ChronometerPersist chronometerPersist = ChronometerPersist.getInstance(chronometer,
43 | getSharedPreferences(
44 | "MyPrefs",
45 | MODE_PRIVATE));
46 | final String filePath = Environment.getExternalStorageDirectory() + "/sample.wav";
47 |
48 | textViewPath.setText(filePath);
49 |
50 | mRecorderOnSubscribe = new RecorderOnSubscribe.Builder(filePath)
51 | .audioSourceCamcorder()
52 | .build();
53 |
54 | final View playButton = findViewById(R.id.buttonPlay);
55 | findViewById(R.id.buttonRecord).setOnClickListener(new View.OnClickListener()
56 | {
57 | @Override
58 | public void onClick(View view)
59 | {
60 | //start recording
61 | if (mRecorderOnSubscribe.isRecording())
62 | {
63 | ((TextView) view).setText("Record");
64 | try
65 | {
66 | mRecorderOnSubscribe.stop();
67 | //helper method for closing the dataStream, also writes the
68 | //wave header
69 | mRecorderOnSubscribe.completeRecording();
70 | } catch (IOException e)
71 | {
72 | Log.e("Recorder", e.getMessage());
73 | }
74 | playButton.setVisibility(View.VISIBLE);
75 | chronometerPersist.stopChronometer();
76 | }
77 | else
78 | {
79 | ((TextView) view).setText("Stop");
80 | try
81 | {
82 | mRecorderOnSubscribe.start();
83 | } catch (FileNotFoundException e)
84 | {
85 | Log.e("Recorder Error", e.getMessage());
86 | }
87 | chronometerPersist.startChronometer();
88 | }
89 | }
90 | });
91 |
92 | mSubscription = Observable.create(mRecorderOnSubscribe).subscribe(new Action1()
93 | {
94 | @Override
95 | public void call(short[] shorts)
96 | {
97 | try
98 | {
99 | mRecorderOnSubscribe.writeShortsToFile(shorts);
100 | } catch (IOException e)
101 | {
102 | Log.e("Recorder", e.getMessage());
103 | }
104 | }
105 | }, new Action1()
106 | {
107 | @Override
108 | public void call(Throwable throwable)
109 | {
110 | Log.e("Recorder Error", throwable.getMessage());
111 | }
112 | });
113 |
114 | playButton.setVisibility(View.GONE);
115 |
116 | playButton.setOnClickListener(new View.OnClickListener()
117 | {
118 | @Override
119 | public void onClick(View view)
120 | {
121 | playFile(filePath);
122 | }
123 | });
124 |
125 | }
126 |
127 | @Override
128 | protected void onPause()
129 | {
130 | super.onPause();
131 | if (mSubscription != null)
132 | {
133 | try
134 | {
135 | mRecorderOnSubscribe.stop();
136 | } catch (IOException e)
137 | {
138 | Log.e("onPause", e.getMessage());
139 | }
140 | mSubscription.unsubscribe();
141 | }
142 | }
143 |
144 | private void playFile(String filePath)
145 | {
146 | //set up MediaPlayer
147 | Intent intent = new Intent();
148 | intent.setAction(android.content.Intent.ACTION_VIEW);
149 | File file = new File(filePath);
150 | intent.setDataAndType(Uri.fromFile(file), "audio/*");
151 | startActivity(intent);
152 | }
153 | }
154 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/reactiveaudiorecord/src/main/java/com/minimize/library/RecorderOnSubscribe.java:
--------------------------------------------------------------------------------
1 | package com.minimize.library;
2 |
3 | import android.media.AudioFormat;
4 | import android.media.AudioRecord;
5 | import android.media.MediaRecorder;
6 |
7 | import java.io.BufferedOutputStream;
8 | import java.io.DataOutputStream;
9 | import java.io.File;
10 | import java.io.FileNotFoundException;
11 | import java.io.FileOutputStream;
12 | import java.io.IOException;
13 | import java.io.RandomAccessFile;
14 |
15 | import rx.Observable;
16 | import rx.Subscriber;
17 |
18 | /**
19 | * Created by ahmedrizwan on 4/24/15.
20 | * Custom onSubscribe for an Observable, when start() is called, it sends out short buffers of
21 | * audio data.
22 | * Pause/Resume/Stop/Stop methods to control the streaming/publishing of audio data to the
23 | * Observer.
24 | */
25 | public class RecorderOnSubscribe implements Observable.OnSubscribe, Runnable
26 | {
27 | private String mFilePath;
28 | private final int mSampleRate;
29 | private final int mChannels;
30 | private final int mBitsPerSecond;
31 | private final int mAudioSource;
32 | private AudioRecord audioRecorder = null;
33 | private int bufferSize;
34 | private boolean isRecording = false;
35 | private final Object mPauseLock;
36 | private boolean mPaused;
37 | private Subscriber super short[]> mSubscriber;
38 | private Thread thread;
39 | private DataOutputStream mDataOutputStream;
40 |
41 | public static class Builder
42 | {
43 | int mSampleRate;
44 | int mBitsPerSecond;
45 | int mChannels;
46 | int mAudioSource;
47 | String mFilePath;
48 |
49 | public Builder(String filePath)
50 | {
51 | mFilePath = filePath;
52 | mSampleRate = 44100;
53 | mBitsPerSecond = AudioFormat.ENCODING_PCM_16BIT;
54 | mAudioSource = MediaRecorder.AudioSource.MIC;
55 | mChannels = 1;
56 | }
57 |
58 | public Builder sampleRate(int sampleRate)
59 | {
60 | mSampleRate = sampleRate;
61 | return this;
62 | }
63 |
64 | public Builder stereo()
65 | {
66 | mChannels = 2;
67 | return this;
68 | }
69 |
70 | public Builder mono()
71 | {
72 | mChannels = 1;
73 | return this;
74 | }
75 |
76 | public Builder audioSourceMic()
77 | {
78 | mAudioSource = MediaRecorder.AudioSource.MIC;
79 | return this;
80 | }
81 |
82 | public Builder audioSourceCamcorder()
83 | {
84 | mAudioSource = MediaRecorder.AudioSource.CAMCORDER;
85 | return this;
86 | }
87 |
88 | public RecorderOnSubscribe build()
89 | {
90 | return new RecorderOnSubscribe(this.mFilePath, this.mSampleRate, this.mChannels,
91 | this.mBitsPerSecond, this.mAudioSource);
92 | }
93 | }
94 |
95 | private RecorderOnSubscribe(String filePath, int sampleRate, int channels, int bitsPerSecond,
96 | int audioSource)
97 | {
98 | mFilePath = filePath;
99 | mSampleRate = sampleRate;
100 | mChannels = channels == 1 ? AudioFormat.CHANNEL_IN_MONO : AudioFormat.CHANNEL_IN_STEREO;
101 | mBitsPerSecond = bitsPerSecond;
102 | mAudioSource = audioSource;
103 |
104 | mPauseLock = new Object();
105 | mPaused = false;
106 | }
107 |
108 | @Override
109 | public void call(Subscriber super short[]> subscriber)
110 | {
111 | mSubscriber = subscriber;
112 | }
113 |
114 | public void start() throws RuntimeException, FileNotFoundException
115 | {
116 | this.mDataOutputStream = new DataOutputStream(
117 | new BufferedOutputStream(new FileOutputStream(this.mFilePath)));
118 |
119 | this.bufferSize = AudioRecord.getMinBufferSize(mSampleRate, mChannels,
120 | AudioFormat.ENCODING_PCM_16BIT);
121 |
122 | if (bufferSize != AudioRecord.ERROR_BAD_VALUE && bufferSize != AudioRecord.ERROR)
123 | {
124 | audioRecorder = new AudioRecord(mAudioSource, mSampleRate, mChannels,
125 | AudioFormat.ENCODING_PCM_16BIT, bufferSize * 10);
126 |
127 | if (audioRecorder.getState() == AudioRecord.STATE_INITIALIZED)
128 | {
129 | audioRecorder.startRecording();
130 | isRecording = true;
131 | thread = new Thread(this);
132 | thread.start();
133 | }
134 | else
135 | {
136 | throw new RuntimeException("Unable to create AudioRecord instance");
137 | }
138 |
139 | }
140 | else
141 | {
142 | throw new RuntimeException("Unable to get minimum buffer size");
143 | }
144 | }
145 |
146 | public void stop() throws IOException
147 | {
148 | isRecording = false;
149 | if (audioRecorder != null)
150 | {
151 | if (audioRecorder.getRecordingState() == AudioRecord.RECORDSTATE_RECORDING)
152 | {
153 | audioRecorder.stop();
154 | }
155 | if (audioRecorder.getState() == AudioRecord.STATE_INITIALIZED)
156 | {
157 | audioRecorder.release();
158 | }
159 | }
160 | }
161 |
162 | /**
163 | * Call this on pause.
164 | */
165 | public void pause()
166 | {
167 | synchronized (mPauseLock)
168 | {
169 | mPaused = true;
170 | }
171 | }
172 |
173 | /**
174 | * Call this on resume.
175 | */
176 | public void resume()
177 | {
178 | synchronized (mPauseLock)
179 | {
180 | mPaused = false;
181 | mPauseLock.notifyAll();
182 | }
183 | }
184 |
185 | @Override
186 | public void run()
187 | {
188 | short[] tempBuf = new short[bufferSize / 2];
189 |
190 | while (isRecording && audioRecorder.getRecordingState() == AudioRecord.RECORDSTATE_RECORDING)
191 | {
192 | audioRecorder.read(tempBuf, 0, tempBuf.length);
193 | mSubscriber.onNext(tempBuf);
194 | synchronized (mPauseLock)
195 | {
196 | while (mPaused)
197 | {
198 | try
199 | {
200 | mPauseLock.wait();
201 | } catch (InterruptedException e)
202 | {
203 | mSubscriber.onError(e);
204 | }
205 | }
206 | }
207 | }
208 | }
209 |
210 | public boolean isRecording()
211 | {
212 | return (audioRecorder != null) && (audioRecorder.getRecordingState() == AudioRecord.RECORDSTATE_RECORDING);
213 | }
214 |
215 | @Override
216 | protected void finalize() throws Throwable
217 | {
218 | super.finalize();
219 |
220 | if (audioRecorder != null && audioRecorder.getState() == AudioRecord.STATE_INITIALIZED)
221 | {
222 | audioRecorder.stop();
223 | audioRecorder.release();
224 | }
225 |
226 | audioRecorder = null;
227 | thread = null;
228 | }
229 |
230 | public boolean isRecordingStopped()
231 | {
232 | return audioRecorder == null || audioRecorder.getRecordingState() == 1;
233 | }
234 |
235 | private void convertFileToWave(File file) throws IOException
236 | {
237 | try
238 | {
239 | rawToWave(file, mSampleRate, 16);
240 | } catch (IOException e)
241 | {
242 | throw new IOException("Unable to convert file");
243 | }
244 | }
245 |
246 | //channels -> Mono or Stereo
247 | //bitsPerSecond -> 16 or 8 (currently android supports 16 only)
248 | private void rawToWave(File rawFile, int sampleRate, int bitsPerSecond) throws IOException
249 | {
250 | RandomAccessFile randomAccessFile = new RandomAccessFile(rawFile, "rw");
251 | int channels = mChannels == AudioFormat.CHANNEL_IN_MONO ? 1 : 2;
252 | //seek to beginning
253 | randomAccessFile.seek(0);
254 | try
255 | {
256 | writeString(randomAccessFile, "RIFF"); // chunk id
257 | writeInt(randomAccessFile, (int) (36 + rawFile.length())); // chunk size
258 | writeString(randomAccessFile, "WAVE"); // format
259 | writeString(randomAccessFile, "fmt "); // subchunk 1 id
260 | writeInt(randomAccessFile, 16); // subchunk 1 size
261 | writeShort(randomAccessFile, (short) 1); // audio format (1 = PCM)
262 | writeShort(randomAccessFile, (short) channels); // number of channels
263 | writeInt(randomAccessFile, sampleRate); // sample rate
264 | writeInt(randomAccessFile, sampleRate * 2); // byte rate
265 | writeShort(randomAccessFile, (short) 2); // block align
266 | writeShort(randomAccessFile, (short) bitsPerSecond); // bits per sample
267 | writeString(randomAccessFile, "data"); // subchunk 2 id
268 | writeInt(randomAccessFile, (int) rawFile.length()); // subchunk 2 size
269 | } finally
270 | {
271 | randomAccessFile.close();
272 | }
273 | }
274 |
275 | private void writeInt(final RandomAccessFile output, final int value) throws IOException
276 | {
277 | output.write(value);
278 | output.write(value >> 8);
279 | output.write(value >> 16);
280 | output.write(value >> 24);
281 | }
282 |
283 | private void writeShort(final RandomAccessFile output, final short value) throws IOException
284 | {
285 | output.write(value);
286 | output.write(value >> 8);
287 | }
288 |
289 | private void writeString(final RandomAccessFile output, final String value) throws IOException
290 | {
291 | for (int i = 0; i < value.length(); i++)
292 | {
293 | output.write(value.charAt(i));
294 | }
295 | }
296 |
297 | public void writeShortsToFile(short[] shorts) throws IOException
298 | {
299 | for (int i = 0; i < shorts.length; i++)
300 | {
301 | mDataOutputStream.writeByte(shorts[i] & 0xFF);
302 | mDataOutputStream.writeByte((shorts[i] >> 8) & 0xFF);
303 | }
304 | }
305 |
306 | public void completeRecording() throws IOException
307 | {
308 | mDataOutputStream.flush();
309 | mDataOutputStream.close();
310 |
311 | File file = new File(mFilePath);
312 | convertFileToWave(file);
313 | }
314 |
315 | }
316 |
--------------------------------------------------------------------------------