当前位置: 首页 > news >正文

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了。



    本文转自 一点点征服   博客园博客,原文链接:http://www.cnblogs.com/ldq2016/p/6340216.html,如需转载请自行联系原作者




相关文章:

  • android自动化测试中hierarchyviewer和uiautomatorviewer获取控件信息的方式比对(1)
  • android89 服务service
  • 阿里云服务器使用之一:搭建jsp服务器
  • 安装 virtualenv
  • 实例详解ISA防火墙策略元素:ISA2006系列之五
  • 调查称没互联网35.8%的人将手足无措,您呢?
  • 实现.NET Core配置Provider之EF
  • hbase shell 启动报错
  • Ubuntu 16下安装zabbix agent
  • python2中MySQLdb加入超时及其重试功能
  • Redis实战(1)入门和适用场合
  • dell 1088 安装 windows xp 蓝屏的解决方法
  • Apache服务器之------https功能
  • mongodb3.4.4安装副本集,wt引擎配置优化(二)
  • PLSql使用
  • [Vue CLI 3] 配置解析之 css.extract
  • 【干货分享】SpringCloud微服务架构分布式组件如何共享session对象
  • 【跃迁之路】【641天】程序员高效学习方法论探索系列(实验阶段398-2018.11.14)...
  • android百种动画侧滑库、步骤视图、TextView效果、社交、搜房、K线图等源码
  • Magento 1.x 中文订单打印乱码
  • Rancher如何对接Ceph-RBD块存储
  • Spring Boot MyBatis配置多种数据库
  • SQLServer之创建数据库快照
  • Vue UI框架库开发介绍
  • 短视频宝贝=慢?阿里巴巴工程师这样秒开短视频
  • 浮现式设计
  • 你真的知道 == 和 equals 的区别吗?
  • 小而合理的前端理论:rscss和rsjs
  • 中国人寿如何基于容器搭建金融PaaS云平台
  • # Python csv、xlsx、json、二进制(MP3) 文件读写基本使用
  • #define用法
  • (13)Hive调优——动态分区导致的小文件问题
  • (八十八)VFL语言初步 - 实现布局
  • (转)Groupon前传:从10个月的失败作品修改,1个月找到成功
  • (转)h264中avc和flv数据的解析
  • (转)jdk与jre的区别
  • ******IT公司面试题汇总+优秀技术博客汇总
  • .a文件和.so文件
  • .jks文件(JAVA KeyStore)
  • .Net FrameWork总结
  • .NET企业级应用架构设计系列之开场白
  • .net中我喜欢的两种验证码
  • [ web基础篇 ] Burp Suite 爆破 Basic 认证密码
  • [.net 面向对象程序设计进阶] (19) 异步(Asynchronous) 使用异步创建快速响应和可伸缩性的应用程序...
  • [2018][note]用于超快偏振开关和动态光束分裂的all-optical有源THz超表——
  • [ASP.NET MVC]如何定制Numeric属性/字段验证消息
  • [codevs1288] 埃及分数
  • [Editor]Unity Editor类常用方法
  • [EFI]MSI GF63 Thin 9SCXR电脑 Hackintosh 黑苹果efi引导文件
  • [FxCop.设计规则]8. 也许参数类型应该是基类型
  • [Hadoop in China 2011] 蒋建平:探秘基于Hadoop的华为共有云
  • [HDU]2161Primes
  • [hive小技巧]同一份数据多种处理
  • [linux] C语言Linux系统编程进程基本概念
  • [luogu P1527]矩阵乘法(矩形k小)