我不知道为什么,但是 start() 方法会引发错误并使应用程序崩溃:
public class Noise extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.noise);
MediaRecorder recorder=new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
try{
recorder.prepare();
}catch(IllegalStateException e){
Log.d("Error",e.toString());
e.printStackTrace();
}catch(IOException e){
Log.d("Error",e.toString());
e.printStackTrace();
}
recorder.start();
Timer timer=new Timer();
timer.scheduleAtFixedRate(new RecorderTask(recorder), 0, 500);
}
private class RecorderTask extends TimerTask{
TextView risultato=(TextView) findViewById(R.id.risultato_recorder);
private MediaRecorder recorder;
public RecorderTask(MediaRecorder recorder){
this.recorder = recorder;
}
public void run(){
runOnUiThread(new Runnable() {
@Override
public void run() {
risultato.setText("" + recorder.getMaxAmplitude());
}
});
}
}
}
如果我删除准备和开始,它可以工作,但在文本视图中总是返回 0。任何人都可以帮助我吗?这件事让我发疯
这是日志猫:https ://dl.dropbox.com/u/16047047/log.txt
在电话中,它崩溃了。