Skip to content

Commit

Permalink
Remote the OnPeriodListener params in constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
lrannn committed Jun 5, 2017
1 parent 470416e commit 235e389
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 0 additions & 2 deletions app/src/main/java/com/mass/audio/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,8 @@ public void onClick(View v) {
AudioFormat.ENCODING_PCM_16BIT/*格式*/,
MediaRecorder.AudioSource.MIC/*AudioSource*/,
512/*period*/,
null/**/,
this/*onDataChangeListener*/);


}

private boolean createOutputFile() {
Expand Down
11 changes: 8 additions & 3 deletions library/src/main/java/com/mass/audio/library/Recorder.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ public class Recorder {
private ByteBuffer byteBuffer;
private ShortBuffer shortBuffer;


private OnPeriodInFramesChangeListener l;

private Recorder() {
}

Expand All @@ -48,15 +51,13 @@ private Recorder() {
* @param format 位深度,参考{@link AudioFormat}
* @param audioSource 输入源 {@link android.media.MediaRecorder.AudioSource}
* @param period 处理sample数量
* @param l 处理完period大小sample的回调
* @param listener 读取完数据的回调
*/
public Recorder(int samplerate,
int channel,
int format,
int audioSource,
int period,
final OnPeriodInFramesChangeListener l,
final IBufferDataChangeInterface listener) {
int minBufferSize = AudioRecord.getMinBufferSize(samplerate, channel, format);
mAudioRecord = new AudioRecord(audioSource, samplerate, channel, format, minBufferSize);
Expand Down Expand Up @@ -116,6 +117,10 @@ public boolean isRecording() {
return mAudioRecord.getRecordingState() == AudioRecord.RECORDSTATE_RECORDING;
}

public void setOnPeriodInFramesChangeListener(OnPeriodInFramesChangeListener listener) {
l = listener;
}


private int read(byte[] data) {
int read = mAudioRecord.read(data, 0, data.length);
Expand All @@ -139,7 +144,7 @@ private boolean isEncodingPCM16Bit() {
/**
* 当走完设定的period*frame的时候调用
*/
interface OnPeriodInFramesChangeListener {
public interface OnPeriodInFramesChangeListener {
void onFrames(AudioRecord record);
}

Expand Down

0 comments on commit 235e389

Please sign in to comment.