Android recording video error setvideosize called in a invalid state 1

Source: Internet
Author: User

To get the resolution of a recorded video supported by your phone when you record a video, use the following code:

List<Camera.Size> videoSize = camera.getParameters().getSupportedVideoSizes();Iterator<Camera.Size> itos = videoSize.iterator();        while (itos.hasNext()) {            Camera.Size curSize = itos.next();            int curSupporSize = curSize.width * curSize.height;            int fixPictrueSize = setFixPictureWidth * setFixPictureHeight;            if (curSupporSize > fixPictrueSize) {                setFixPictureWidth = curSize.width;                setFixPictureHeight = curSize.height;            }        }mediaRecorder.setVideoSize(setFixPictureWidth,        setFixPictureHeight);

Two errors occurred, one time when recording a video, calling Camera.getparameters () times parameters is empty , because the function was called after Camera.unlock (). It is OK to get it before unlock.
Another error is setvideosize called in a invalid state 1 , enter the Setvideosize function to find the condition description that throws the exception

/**     * Sets the width and height of the video to be captured.  Must be called     * after setVideoSource(). Call this after setOutFormat() but before     * prepare().     *     * @param width the width of the video to be captured     * @param height the height of the video to be captured     * @throws IllegalStateException if it is called after     * prepare() or before setOutputFormat()     */    public native void setVideoSize(int width, int height) throws IllegalStateException;

IllegalStateException if it is called after prepare() or before setOutputFormat()Indicates that the exception occurs if Setvideosize is called after prepare () or Setoutputformat (), which means that the Setvideosize function is required before prepare () and Setoutputformat ( ) is called after.
Check the code, found that I call setvideosize unexpectedly in Setoutputformat () before, changed to Setoutputformat () after the OK.

Android recording video error setvideosize called in a invalid state 1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.