0
        if (camera == null) {
            Log.d(TAG, "Already stopped.");
            return; 
        } 
 
        camera.setErrorCallback(null);
        if (mPreviewing) {
            stopPreview(); 
        } 
        camera.release();
        camera = null;
    } 
 
//    private void initTextureView() { 
//        mTextureView = new TextureView(currentActivity); 
//        mTextureView.setSurfaceTextureListener(new SurfaceTextureCallback()); 
//        mTextureView.setVisibility(View.GONE); 
//        FrameLayout.LayoutParams params = new LayoutParams( 
//                LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, Gravity.CENTER); 
//        mTextureView.setLayoutParams(params); 
//        Log.d(TAG, "add texture view to preview frame"); 
//        mPreviewFrame.addView(mTextureView); 
//    } 
// 
//    private void releaseSurfaceTexture() { 
//        if (mSurfaceTexture != null) { 
//            mPreviewFrame.removeAllViews(); 
//            mTextureView = null; 
//            mSurfaceTexture = null; 
//            mSurfaceTextureReady = false; 
//        } 
//    } 
// 
    private void initSurfaceView() { 
        surfaceView = new SurfaceView(currentActivity);
        surfaceView.getHolder().addCallback(new SurfaceViewCallback());
        surfaceView.setVisibility(View.GONE);
        FrameLayout.LayoutParams params = new LayoutParams(
                LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, Gravity.CENTER);
        surfaceView.setLayoutParams(params);
        Log.d(TAG, "add surface view to preview frame");
        previewFrame.addView(surfaceView);
    } 
 
    private void releaseSurfaceView() { 
        if (surfaceView != null) {
            previewFrame.removeAllViews();
            surfaceView = null;
            surfaceHolder = null;
            surfaceViewReady = false;
        } 
    } 
 
    private void startPreview() { 
//        if ((useTexture() && !mSurfaceTextureReady) || (!useTexture() && !mSurfaceViewReady)) { 
//            return; 
//        } 
 
        Log.v(TAG, "startPreview.");
        if (mPreviewing) {
            stopPreview(); 
        } 
 
        setCameraParameters(); 
        resizePreview(); 
 
        try { 
//            if (useTexture()) { 
//                mCamera.setPreviewTexture(mSurfaceTexture); 
//            } else { 
                camera.setPreviewDisplay(surfaceHolder);
//            } 
            camera.startPreview();
            mPreviewing = true;
        } catch (Exception e) {
            closeCamera(); 
            e.printStackTrace();
            Log.e(TAG, "startPreview failed.");
        } 
 
    } 
 
    private void stopPreview() { 
        Log.v(TAG, "stopPreview");
        if (camera != null) {
            camera.stopPreview();
            mPreviewing = false;
        } 
    } 
 
    public void onPause() { 
        paused = true;
 
        if (recording) {
            stopRecording(); 
        } 
        closeCamera(); 
 
//        if (useTexture()) { 
//            releaseSurfaceTexture(); 
//        } else { 
            releaseSurfaceView(); 
//        } 
    } 
 
    private void setCameraParameters() { 
        if (CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_720P)) {
            camcorderProfile = CamcorderProfile.get(CamcorderProfile.QUALITY_720P);
        } else if (CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_480P)) {
            camcorderProfile = CamcorderProfile.get(CamcorderProfile.QUALITY_480P);
        } else { 
            camcorderProfile = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);
        } 
        mVideoWidth = camcorderProfile.videoFrameWidth;
        mVideoHeight = camcorderProfile.videoFrameHeight;
        camcorderProfile.fileFormat = MediaRecorder.OutputFormat.MPEG_4;
        camcorderProfile.videoFrameRate = 25;
 
        Log.v(TAG, "mVideoWidth=" + mVideoWidth + " mVideoHeight=" + mVideoHeight);
        cameraParameters.setPreviewSize(mVideoWidth, mVideoHeight);
 
        if (cameraParameters.getSupportedWhiteBalance().contains(Camera.Parameters.WHITE_BALANCE_AUTO)) {
            cameraParameters.setWhiteBalance(Camera.Parameters.WHITE_BALANCE_AUTO);
        } 
 
        if (cameraParameters.getSupportedFocusModes().contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO)) {
            cameraParameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO);
        } 
 
        cameraParameters.setRecordingHint(true);
        cameraParameters.set("cam_mode", 1);
 
        camera.setParameters(cameraParameters);
        cameraParameters = camera.getParameters();
 
        camera.setDisplayOrientation(90);
        android.hardware.Camera.CameraInfo info = new android.hardware.Camera.CameraInfo();
        Log.d(TAG, info.orientation + " degree");
    } 
 
    private void resizePreview() {