我有以下按钮:
prStartBtn.setOnClickListener(new View.OnClickListener() {
// @Override
public void onClick(View v) {
if (prRecordInProcess == false) {
startRecording();
} else {
stopRecording();
}
}
});
当我第一次按下它时,它会这样做:
private boolean startRecording() {
prCamera.stopPreview();
try {
prCamera.unlock();
prMediaRecorder.setCamera(prCamera);
prMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
String lVideoFileFullPath;
String lDisplayMsg = "Current container format: ";
prMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); prMediaRecorder.setVideoEncoder(VideoEncoder.H264);
if (first) {
lVideoFileFullPath = cVideoFilePath + "result" + lVideoFileFullPath;
} else {
lVideoFileFullPath = cVideoFilePath + "vid2" + lVideoFileFullPath;
}
final File f = new File(lVideoFileFullPath);
f.createNewFile();
prRecordedFile = new FileOutputStream(f);
prMediaRecorder.setOutputFile(prRecordedFile.getFD());
prMediaRecorder.setVideoSize(sizeList.get(Utils.puResolutionChoice).width, sizeList.get(Utils.puResolutionChoice).height);
prMediaRecorder.setVideoEncodingBitRate(3000000);
prMediaRecorder.setVideoFrameRate(cFrameRate);
prMediaRecorder.setPreviewDisplay(prSurfaceHolder.getSurface());
prMediaRecorder.setMaxDuration(cMaxRecordDurationInMs);
prMediaRecorder.setMaxFileSize(cMaxFileSizeInBytes);
prMediaRecorder.prepare();
prMediaRecorder.start();
final Runnable r = new Runnable() {
public void run() {
try {
fileIn = new FileInputStream(f);
while (prRecordInProcess) {
// prRecordedFile.flush();
System.out.println("bytesAvailable: " + fileIn.available());
Thread.sleep(1000);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// handler.postDelayed(this, 1000);
}
};
handler.postDelayed(r, 1000);
prStartBtn.setText("Pause");
prRecordInProcess = true;
return true;
} catch (IOException _le) {
_le.printStackTrace();
return false;
}
}
现在,如果我注释掉可运行文件,则代码可以完美运行。如果我离开它,它会运行(它显示文件如何增长),但我无法再访问按钮(如果我再次按下按钮,停止录制,它什么也不做),过了一会儿,它崩溃(ANR)。任何想法如何解决这一问题?