Code example for Camera

Methods: releasesetErrorCallbackstopPreview

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() {