关于线程上的问题
问题是我在使用recorder的时候 程序没有响应,recorder.start() 的功能是 录音+ 画声纹。
原本当使用多线程的调用,用runnable,暂停按钮是没有反应的(延迟好几秒),不能及时结束线程。估计是在UI更新上的问题(可是不是已经用新线程了嘛?)
然后现在用的handler的switch 来写,也是延迟的问题
错误依然是 主线程要处理太多东西、、
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.receive_activity_back:
finish();
break;
case R.id.btn_receive_activity_play:
Message msg = Message.obtain();
msg.what = IS_REC;
Log.i("MSG",msg.what + "");
mhandler.sendMessage(msg);
break;
case R.id.btn_receive_activity_replay:
msg = Message.obtain();
msg.what = STOP_REC;
Log.i("MSG",msg.what + "");
mhandler.sendMessage(msg);
break;
}
}
Handler mhandler = new Handler() {
public void handleMessage(Message msg) {
tv.append("ing///....." + msg.what);
switch (msg.what){
case 1:
Calendar c = Calendar.getInstance();
String ss = c.get(Calendar.YEAR) + "-" + (c.get(Calendar.MONTH) + 1) + "-" + c.get(Calendar.DAY_OF_MONTH) + "-"
+ c.get(Calendar.HOUR_OF_DAY) + "-" + c.get(Calendar.MINUTE) + "-" + c.get(Calendar.SECOND);
ss = path + "/" + ss + ".arm";
Log.i("MSG", ss);
mRecorder.setOutputFile(ss);
mRecorder.prepare();
mRecorder.start();
Log.i("MSG", "start to recorder");
break;
case 0:
mRecorder.stop();
mRecorder.release();
break;
}
}
};
}
普通废的柴
9 years, 6 months ago