camera startPreview failed

后端 未结 5 1204
猫巷女王i
猫巷女王i 2021-01-02 09:46

I am creating a camera app but I have problems on startPreview, it sends me:

java.lang.RuntimeException: startPreview failed

h

5条回答
  •  醉话见心
    2021-01-02 10:17

    I have solved deleting some lines in surfaceChanged

     public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
            // If your preview can change or rotate, take care of those events here.
            // Make sure to stop the preview before resizing or reformatting it.
            Log.d("Function", "surfaceChanged iniciado");
            if (mHolder.getSurface() == null){
              // preview surface does not exist
              return;
            }
    
            // stop preview before making changes
            try {
                mCamera.stopPreview();
            } catch (Exception e){
              // ignore: tried to stop a non-existent preview
            }
    
            // set preview size and make any resize, rotate or
            // reformatting changes here
    
    
            // start preview with new settings
            try {
                mCamera.setPreviewDisplay(mHolder);
                mCamera.startPreview();
    
            } catch (Exception e){
                Log.d(TAG, "Error starting camera preview: " + e.getMessage());
            }
        }
    

    So the error must be in i one of these lines:

    Parameters parameters= mCamera.getParameters();
        parameters.setPreviewSize(w, h);
        mCamera.setParameters(parameters);
    

    Someone could explain me what was wrong in those lines?

提交回复
热议问题