在使用MediaRecorder录音的时候很卡
代码如下:
Button.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
mRecordBtn.setText("松开结束");
mRecordBtn.setBackgroundColor(Color.GREEN);
mRecorder = new MediaRecorder();
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.AMR_NB);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mRecorder.setOutputFile(mPath + "/" + System.currentTimeMillis() + ".mp3");
try {
mRecorder.prepare();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
mRecorder.start();
}
break;
case MotionEvent.ACTION_UP:
mRecorder.stop();
mRecorder.release();
mRecorder = null;
mRecordBtn.setText("按住说话");
mRecordBtn.setBackgroundColor(Color.WHITE);
mVoiceAnimDraw.stop();
break;
}
return false;
}
});
触摸按钮的时候要等2秒才会进入录音状态,需要做点什么优化才能像QQ和微信那样,一触摸到按钮就能马上进入录音呢?
代码如下:
Button.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
mRecordBtn.setText("松开结束");
mRecordBtn.setBackgroundColor(Color.GREEN);
mRecorder = new MediaRecorder();
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.AMR_NB);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mRecorder.setOutputFile(mPath + "/" + System.currentTimeMillis() + ".mp3");
try {
mRecorder.prepare();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
mRecorder.start();
}
break;
case MotionEvent.ACTION_UP:
mRecorder.stop();
mRecorder.release();
mRecorder = null;
mRecordBtn.setText("按住说话");
mRecordBtn.setBackgroundColor(Color.WHITE);
mVoiceAnimDraw.stop();
break;
}
return false;
}
});
触摸按钮的时候要等2秒才会进入录音状态,需要做点什么优化才能像QQ和微信那样,一触摸到按钮就能马上进入录音呢?