From b8f6672dfce025dc73a5e8a30c683b661aa6155d Mon Sep 17 00:00:00 2001 From: luxiaojie <358231333@qq.com> Date: Tue, 8 Dec 2015 11:35:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BD=95=E9=9F=B3=E5=AE=8C=E6=88=90=E6=97=B6?= =?UTF-8?q?=E9=A9=AC=E4=B8=8A=E6=93=8D=E4=BD=9C=E8=AF=A5=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E4=BC=9A=E5=87=BA=E7=8E=B0=E5=BC=82=E5=B8=B8,=E5=9B=A0?= =?UTF-8?q?=E4=B8=BA=E8=BF=99=E4=B8=AA=E6=97=B6=E5=80=99=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E8=BF=98=E6=B2=A1=E6=9C=89=E8=BD=AC=E6=8D=A2=E7=BB=93=E6=9D=9F?= =?UTF-8?q?,=E6=89=80=E4=BB=A5=E6=B7=BB=E5=8A=A0=E4=B8=80=E4=B8=AAinterfac?= =?UTF-8?q?e=E7=94=A8=E4=BA=8E=E5=9B=9E=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/czt/mp3recorder/MP3Recorder.java | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/library/src/main/java/com/czt/mp3recorder/MP3Recorder.java b/library/src/main/java/com/czt/mp3recorder/MP3Recorder.java index ec59f6a..136db74 100644 --- a/library/src/main/java/com/czt/mp3recorder/MP3Recorder.java +++ b/library/src/main/java/com/czt/mp3recorder/MP3Recorder.java @@ -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帧作为一个周期,通知一下需要进行编码 */ @@ -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 @@ -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() { @@ -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开发范例 @@ -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(); + } } \ No newline at end of file