Skip to content

Commit

Permalink
add module
Browse files Browse the repository at this point in the history
  • Loading branch information
HelloHuDi committed May 9, 2018
1 parent b7878b3 commit b9eb4c7
Show file tree
Hide file tree
Showing 26 changed files with 412 additions and 136 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<p align="center">
<img width="72" height="72" src="art/audio_icon.png"/>
</p>
<h3 align="center">AudioCapture</h3>
<p align="center">
<a href="" target="_blank"><img src="https://img.shields.io/badge/release-v1.0-blue.svg"></img></a>
<a href="" target="_blank"><img src="https://img.shields.io/badge/demo-v1.0-blue.svg"></img></a>
</p>

### License

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
10 changes: 8 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ android {
compileSdkVersion 27
defaultConfig {
applicationId "com.hd.audiorecorderlearn"
minSdkVersion 20
minSdkVersion 14
targetSdkVersion 22
versionCode 1
versionName "1.0"
Expand All @@ -16,13 +16,19 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation project(':audiocapture')
}
8 changes: 2 additions & 6 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.hd.audiorecorderlearn">

<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:icon="@mipmap/audio_icon"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:roundIcon="@mipmap/audio_icon"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".AudioActivity">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.hd.audiocapture.callback.CaptureCallback;

import java.io.File;


/**
* Created by hd on 2018/5/8 .
*/
public class AudioActivity extends AppCompatActivity implements RadioGroup.OnCheckedChangeListener, AudioCallback {
public class AudioActivity extends AppCompatActivity implements RadioGroup.OnCheckedChangeListener, CaptureCallback {
private TextView tvAudioFilePath;
private File file;
private AudioPresenter audioPresenter;
Expand Down Expand Up @@ -64,7 +65,7 @@ public void play(View view) {
}

@Override
public void audioPath(@NonNull final File file) {
public void capturePath(final File file) {
this.file = file;
runOnUiThread(new Runnable() {
@SuppressLint("SetTextI18n")
Expand Down
14 changes: 0 additions & 14 deletions app/src/main/java/com/hd/audiorecorderlearn/AudioCallback.java

This file was deleted.

73 changes: 0 additions & 73 deletions app/src/main/java/com/hd/audiorecorderlearn/AudioModel.java

This file was deleted.

36 changes: 20 additions & 16 deletions app/src/main/java/com/hd/audiorecorderlearn/AudioPresenter.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package com.hd.audiorecorderlearn;

import android.content.Context;
import android.util.Log;

import com.hd.audiocapture.AudioCapture;
import com.hd.audiocapture.Utils;
import com.hd.audiocapture.callback.CaptureCallback;
import com.hd.audiocapture.capture.Capture;

import java.io.File;

Expand All @@ -14,38 +18,38 @@ public class AudioPresenter {

public final static int AUDIORECORD_STYLE = 1;

private Context context;

private MediaRecorderModel mediaRecorderModel;
private Capture capture;

private AudioRecordModel audioRecordModel;
private Context context;

private AudioModel audioModel;
private CaptureCallback callback;

public AudioPresenter(Context context, AudioCallback callback) {
this.context = context.getApplicationContext();
mediaRecorderModel = new MediaRecorderModel(callback);
audioRecordModel = new AudioRecordModel(callback);
AudioPresenter(Context context, CaptureCallback callback) {
if (Utils.isPermissionGranted(context) && Utils.isExternalStorageReady()) {
this.context = context;
this.callback = callback;
}else{
throw new RuntimeException("permission not grant");
}
}

public void initStyle(int style) {
if (style == MEDIARECORDER_STYLE) {
audioModel = mediaRecorderModel;
capture = AudioCapture.useAudioRecord().setCaptureCallback(callback).getCapture();
} else {
audioModel = audioRecordModel;
capture = AudioCapture.useMediaRecorder().setCaptureCallback(callback).getCapture();
}
Log.d("tag","init recorder style :"+audioModel);
}

public void start() {
audioModel.start();
capture.startCapture(5000);
}

public void stop() {
audioModel.stop();
capture.stopCapture();
}

public void play(File file) {
new Player().asyncPlay(context, file);
capture.play(context, file);
}
}
Binary file added app/src/main/res/mipmap-mdpi/audio_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added art/audio_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions audiocapture/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
35 changes: 35 additions & 0 deletions audiocapture/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 27

defaultConfig {
minSdkVersion 14
targetSdkVersion 27
versionCode 1
versionName "1.0"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
21 changes: 21 additions & 0 deletions audiocapture/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.hd.audiocapture;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();

assertEquals("com.hd.audiocapture.test", appContext.getPackageName());
}
}
7 changes: 7 additions & 0 deletions audiocapture/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.hd.audiocapture">
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>

</manifest>
27 changes: 27 additions & 0 deletions audiocapture/src/main/java/com/hd/audiocapture/AudioCapture.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.hd.audiocapture;

/**
* Created by hd on 2018/5/9 .
* audio capture, create aac audio file
*
*/
public final class AudioCapture {

private static CaptureManager getCaptureManager(String tag) {
CaptureType captureType = new CaptureType();
return captureType.of(tag);
}

private static CaptureManager use(String tag) {
return getCaptureManager(tag);
}

public static CaptureManager useAudioRecord() {
return use(CaptureType.MEDIA_RECORDER_TYPE);
}

public static CaptureManager useMediaRecorder() {
return use(CaptureType.AUDIO_RECORD_TYPE);
}

}
Loading

0 comments on commit b9eb4c7

Please sign in to comment.