Amsheer
Amsheer

Reputation: 7131

get Camera parameter Android

I am little confused about it. Is there any difference between the following two declarations?

Camera.Parameters parameters = camera.getParameters();

and

Parameters parameters = camera.getParameters();

I read the developer docs. It says getParameters() is used to get the camera parameter of the device.

Upvotes: 1

Views: 2502

Answers (5)

Amsheer
Amsheer

Reputation: 7131

I solved this error by replacing the following code:

protected void startRecording() {
        try {
            mrec = new MediaRecorder();
            mCamera.unlock();
            mrec.setCamera(mCamera);

            //Set audio source
            mrec.setAudioSource(MediaRecorder.AudioSource.MIC);
            //set video source
            mrec.setVideoSource(MediaRecorder.VideoSource.CAMERA);

            //set output format
            mrec.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);

            int width = 320;
            int height = 240;
            try {
                //get the available sizes of the video
                List<Size> tmpList = getSupportedVideoSizes();

                final List<Size> sizeList = new Vector<Size>();

                // compare the apsect ratio of the candidate sizes against the
                // real ratio
                Double aspectRatio = (Double.valueOf(getWindowManager()
                        .getDefaultDisplay().getHeight()) / getWindowManager()
                        .getDefaultDisplay().getWidth());
                for (int i = tmpList.size() - 1; i > 0; i--) {
                    Double tmpRatio = Double.valueOf(tmpList.get(i).height)
                            / tmpList.get(i).width;
                    if (EnableLog.LOG_TAG) {
                        Log.e("Width & height", tmpList.get(i).width + " x "
                                + tmpList.get(i).height);
                    }
                    if (Math.abs(aspectRatio - tmpRatio) < .15) {
                        width = tmpList.get(i).width;
                        height = tmpList.get(i).height;
                        sizeList.add(tmpList.get(i));
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }

            // set the size of video.
            // If the size is not applicable then throw the media recorder stop
            // -19 error
            mrec.setVideoSize(width, height);

            // Set the video encoding bit rate this changes for the high, low.
            // medium quality devices
            mrec.setVideoEncodingBitRate(1700000);

            //Set the video frame rate
            mrec.setVideoFrameRate(30);

            //set audio encoder format
            mrec.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);

            //set video encoder format
            mrec.setVideoEncoder(MediaRecorder.VideoEncoder.H264);

            //Show the display preview
            mrec.setPreviewDisplay(surfaceHolder.getSurface());

            //output file path
            mrec.setOutputFile(output_path);

            mrec.prepare();

            mrec.start();

        } catch (IllegalStateException e) {
            Crashlytics.logException(e);
            e.printStackTrace();
        } catch (IOException e) {
            Crashlytics.logException(e);
            e.printStackTrace();
        }
    }

public List<Size> getSupportedVideoSizes() {
        if (params.getSupportedVideoSizes() != null) {
            return params.getSupportedVideoSizes();
        } else {
            // Video sizes may be null, which indicates that all the supported
            // preview sizes are supported for video recording.
            return params.getSupportedPreviewSizes();
        }
    }

Upvotes: 0

Galmani
Galmani

Reputation: 71

Both are same you can use both:

Camera.Parameters parameters = camera.getParameters();

or

Parameters parameters = camera.getParameters();

Upvotes: 1

G.Nader
G.Nader

Reputation: 857

Same, you can use both :

Camera.Parameters parameters = camera.getParameters();

or

Parameters parameters = camera.getParameters();

Upvotes: 0

林知易
林知易

Reputation: 1

There are the same.

Parameters parameters = camera.getParameters();

You can see the import. It will be import android.hardware.Camera.* When you import View.* ,also you can use GONE instead of View.GONE

Upvotes: 0

Dima
Dima

Reputation: 158

Camera.Parameters means, that you don`t need an explicit import of android.hardware.Camera.Parameters. There is also a class java.security.Policy.Parameters.

Upvotes: 0

Related Questions