Record Video using surface view android

前端 未结 2 1406
一整个雨季
一整个雨季 2021-02-01 10:29

I have to create an android app in which i am trying to record video and capture image using surface view. Up to now i am able to capture video but facing problem in record vide

2条回答
  •  说谎
    说谎 (楼主)
    2021-02-01 11:22

    You can get a list of available preview sizes by calling getSupportedPreviewSizes in the Camera.Parameters object returned by Camera.getParameters. Check here

    Add these below code inside surfaceChanged method

    Camera.Parameters parameters = camera.getParameters();  
       List sizes = parameters.getSupportedPreviewSizes();  
       Camera.Size cs = sizes.get(0);  // You need to choose the most appropriate previewSize for your app. So select one from the list
       parameters.setPreviewSize(cs.width, cs.height);  
       camera.setParameters(parameters);
       camera.startPreview();
    

    EDIT Change your surfaceChanged method like below and check

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

提交回复
热议问题