我目前正在阅读“构建相机应用”教程 - http://developer.android.com/guide/topics/media/camera.html#custom-camera
作为一个相对较新的Android用户,我觉得有时候有点混乱/不清楚。
我试图了解这段代码应该去哪里:
private boolean isRecording = false;
// Add a listener to the Capture button
Button captureButton = (Button) findViewById(id.button_capture);
captureButton.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
if (isRecording) {
// stop recording and release camera
mMediaRecorder.stop(); // stop the recording
releaseMediaRecorder(); // release the MediaRecorder object
mCamera.lock(); // take camera access back from MediaRecorder
// inform the user that recording has stopped
setCaptureButtonText("Capture");
isRecording = false;
} else {
// initialize video camera
if (prepareVideoRecorder()) {
// Camera is available and unlocked, MediaRecorder is prepared,
// now you can start recording
mMediaRecorder.start();
// inform the user that recording has started
setCaptureButtonText("Stop");
isRecording = true;
} else {
// prepare didn't work, release the camera
releaseMediaRecorder();
// inform user
}
}
}
}
);
这可以在顶级类中的任何位置,还是应该在提供的方法或内部类中?
无论我把这段代码放在哪里都会导致错误,告诉我添加或删除'}',但我确定我必须把它放在错误的地方,因为我确定google的代码没问题。
非常感谢任何帮助!
答案 0 :(得分:0)
此代码属于加载包含“button_capture”按钮的布局的活动。你可以在onCreate()方法中找到这个活动。
无论我在哪里放置此代码,都会导致错误,告诉我添加或删除'}'
这只是让你的大括号正确配对的问题。