Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion library/src/main/java/com/czt/mp3recorder/MP3Recorder.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ public class MP3Recorder {
private static final int DEFAULT_LAME_MP3_BIT_RATE = 32;

//==================================================================

private static final int STATR = 1;
private static final int STOP = 2;
/**
* 自定义 每160帧作为一个周期,通知一下需要进行编码
*/
Expand All @@ -47,6 +48,7 @@ public class MP3Recorder {
private DataEncodeThread mEncodeThread;
private boolean mIsRecording = false;
private File mRecordFile;
private OnMp3RecorderListener listener;
/**
* Default constructor. Setup recorder with default sampling rate 1 channel,
* 16 bits pcm
Expand All @@ -65,6 +67,10 @@ public MP3Recorder(File recordFile) {
public void start() throws IOException {
if (mIsRecording) return;
initAudioRecorder();
mAudioRecord.startRecording();
Message uMsg = handler.obtainMessage();
uMsg.what = STATR;
handler.sendMessage(uMsg);
mAudioRecord.startRecording();
new Thread() {

Expand All @@ -89,6 +95,9 @@ public void run() {
Message msg = Message.obtain(mEncodeThread.getHandler(),
DataEncodeThread.PROCESS_STOP);
msg.sendToTarget();
Message uMsg = handler.obtainMessage();
uMsg.what = STOP;
handler.sendMessage(uMsg);
}
/**
* 此计算方法来自samsung开发范例
Expand Down Expand Up @@ -161,4 +170,30 @@ private void initAudioRecorder() throws IOException {
mAudioRecord.setRecordPositionUpdateListener(mEncodeThread, mEncodeThread.getHandler());
mAudioRecord.setPositionNotificationPeriod(FRAME_COUNT);
}
private Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
if (listener != null) {
switch (msg.what) {
case STATR:
listener.startMP3Recorder();
break;
case STOP:
listener.stopMP3Recorder();
break;
}
}
}
};

public void setOnMp3RecorderListener(OnMp3RecorderListener listener) {
this.listener = listener;
}

public interface OnMp3RecorderListener {
public void startMP3Recorder();

public void stopMP3Recorder();
}
}