0

以下代码不允许录制视频。此代码通过按钮调用,但按钮冻结。我正在尝试使用摄像机配置文件来录制视频。

    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();
}
4

1 回答 1

1

总是尽力捕捉抛出的异常:

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.
}
于 2012-10-26T15:15:16.447 回答