我遇到了一个非常奇怪的行为:有时我的 mediarecorder 因错误“停止失败”而崩溃,有时它工作正常。是我的错还是系统的错误?我不明白出了什么问题。
private void stopRecording(){
ticker.cancel();
ticker.purge();
recorder.stop();
startBtn.setText("Start");
recordInProcess = false;
markList = locWriteTask.getMarkArray();
mCamera.lock();
recorder.release();
}
private void startRecording(){
startBtn.setText("Stop");
recordInProcess = true;
recorder = new MediaRecorder();
mCamera.unlock();
recorder.setCamera(mCamera);
recorder.setPreviewDisplay(mSurfaceHolder.getSurface());
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);
recorder.setMaxDuration((int) 10000000);
recorder.setVideoSize(320, 240);
recorder.setVideoFrameRate(15);
recorder.setOutputFile(FULL_PATH_TO_LOCAL_FILE + counter + MP4);
try{
recorder.prepare();
} catch (Exception e){
finish();
}
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, ll);
ticker = new Timer();
locWriteTask = new WriteTimeLocationTimerTask(ll);
ticker.schedule(locWriteTask, 0, DELAY);
recorder.start();
}