Skip to content

Commit

Permalink
IdealRecorder中增加返回全部pcm数据的功能和回调
Browse files Browse the repository at this point in the history
  • Loading branch information
ideastudios committed May 22, 2018
1 parent 348da56 commit a87de92
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.support.v4.content.ContextCompat;
import android.text.TextUtils;

import java.io.ByteArrayOutputStream;
import java.util.concurrent.atomic.AtomicBoolean;

import tech.oom.idealrecorder.file.AudioFileHelper;
Expand All @@ -35,7 +36,7 @@ public class IdealRecorder implements RecorderCallback, AudioFileListener {
private long maxRecordTime = 6000L;
private long volumeInterval = 200L;
private int count;

private ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
private AtomicBoolean isStarted = new AtomicBoolean(false);

private IdealRecorder() {
Expand Down Expand Up @@ -213,6 +214,7 @@ public boolean onRecorderStart() {
audioFileHelper.start();
}
count = 0;
byteArrayOutputStream.reset();
runOnUi(new Runnable() {
public void run() {
if (statusListener != null) {
Expand All @@ -232,7 +234,7 @@ public void onRecorded(final short[] wave) {

audioFileHelper.save(bytes, 0, bytes.length);
}

byteArrayOutputStream.write(bytes, 0, bytes.length);
runOnUi(new Runnable() {
@Override
public void run() {
Expand Down Expand Up @@ -304,10 +306,12 @@ public void onRecorderStop() {
@Override
public void run() {
if (statusListener != null) {
statusListener.onRecordedAllData(byteArrayOutputStream.toByteArray());
statusListener.onStopRecording();
}
}
});
// byteArrayOutputStream.reset();
}

private int calculateVolume(short[] wave) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public void onVoiceVolume(int volume) {
}



/**
* 录音失败
*
Expand Down Expand Up @@ -69,4 +68,13 @@ public void onFileSaveSuccess(String fileUri) {
public void onStopRecording() {
}

/**
* 全部的录音pcm数据
*
* @param arr 所有的录音pcm数据
*/
public void onRecordedAllData(byte[] arr) {

}

}

0 comments on commit a87de92

Please sign in to comment.