Reputation: 749
Following code is not allowing to record a video. This code is invoked through a button but the button freezes. I am trying to use the camcorder profile to record the video.
public void startRecording() {
mCamera.unlock();
mrec.setCamera(mCamera);
CamcorderProfile cpHigh = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);
mrec.setProfile(cpHigh);
File dir = new File(SdCardPath + Directory);
if (!dir.exists()) {
if (dir.mkdir()) {
Log.v(STORAGE_SERVICE, "Created directory");
} else {
Log.v(STORAGE_SERVICE, "Failed to create Directory");
}
}
FullFilePath = SdCardPath + Directory + RecordFileName;
mrec.setOutputFile(FullFilePath);
mrec.setPreviewDisplay(surfaceHolder.getSurface());
try {
mrec.prepare();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
mrec.start();
}
Upvotes: 0
Views: 1595
Reputation: 17140
Always do you best to catch exceptions thrown:
public void startRecording() {
try {
mCamera.unlock();
catch (RuntimeException ex){
// looks like camera was locked in the first place, who is using it?
}
mrec.setCamera(mCamera);
///...the rest of your code.
}
Upvotes: 1