zoukankan      html  css  js  c++  java
  • Android录制视频报错setVideoSize called in a invalid state 1

    录制视频时想获取手机支持的录制视频的分辨率,使用代码如下:

    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);

    出现了两次错误,一次是录制视频时调用camera.getParameters()时报parameters is empty,这是由于在camera.unlock()之后调用了该函数,将其在unlock之前获取就ok了。
    还有一个错误就是setVideoSize called in a invalid state 1,进入setVideoSize函数中可以发现抛出异常的条件说明

     /**
         * 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()表示如果setVideoSize在prepare() 之后或者setOutputFormat()之前调用的话就会出现该异常,即是说要求setVideoSize函数在prepare()之前以及setOutputFormat()之后调用。
    查了下代码,发现我调用setVideoSize竟然是在setOutputFormat()之前,改到setOutputFormat()之后就ok了。

  • 相关阅读:
    SDN原理 OpenFlow协议 -3
    SDN原理 OpenFlow协议 -2
    蓝桥杯----特殊的回文
    hdu-4513吉哥系列故事——完美队形II--最长回文
    蓝桥杯: 基础练习 十六进制转八进制
    母函数模板核心
    杭电ACM hdu 2079 选课时间 (模板)
    杭电ACM hdu 1398 Square Coins
    求用1g、2g、3g的砝码(每种砝码有无穷多个)称出10g的方案有几种
    有1克、2克、3克、4克的砝码各一枚,能称出哪几种重量?
  • 原文地址:https://www.cnblogs.com/ldq2016/p/6340216.html
Copyright © 2011-2022 走看看