setOutputFormat called in an invalid state: 1
在编写一个简单的录像应用程序的时候,爆出例如以下异常:
E MediaRecorder: setOutputFormat called in an invalid state: 1
E AndroidRuntime: java.lang.IllegalStateException
E AndroidRuntime: at android.media.MediaRecorder.setOutputFormat(Native Method)
由于code是全然依照google的Demo写的,认为比較奇怪。
看描写叙述是说setOutputFormat的时候,状态应该错乱了。最后又看了一下google文档,原因在于google对于设定MediaRecorder是有要求的:
所以在写代码的时候应该全然依照人家要求的设定顺序来写,详细例如以下:
mCamera.unlock();
mProfile = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH); //1st. Initial state
mMediaRecorder = new MediaRecorder();
mMediaRecorder.setCamera(mCamera); //2st. Initialized state
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); //3st. config
mMediaRecorder.setOutputFormat(mProfile.fileFormat);
mMediaRecorder.setAudioEncoder(mProfile.audioCodec);
mMediaRecorder.setVideoEncoder(mProfile.videoCodec);
mMediaRecorder.setOutputFile("/sdcard/FBVideo.3gp");
mMediaRecorder.setVideoSize(mProfile.videoFrameWidth, mProfile.videoFrameHeight);
mMediaRecorder.setVideoFrameRate(mProfile.videoFrameRate);
mMediaRecorder.setVideoEncodingBitRate(mProfile.videoBitRate);
mMediaRecorder.setAudioEncodingBitRate(mProfile.audioBitRate);
mMediaRecorder.setAudioChannels(mProfile.audioChannels);
mMediaRecorder.setAudioSamplingRate(mProfile.audioSampleRate); mMediaRecorder.setPreviewDisplay(mHolder.getSurface()); try {
mMediaRecorder.prepare();
mMediaRecorder.start();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
setOutputFormat called in an invalid state: 1的更多相关文章
- Android录制视频报错setVideoSize called in a invalid state 1
录制视频时想获取手机支持的录制视频的分辨率,使用代码如下: List<Camera.Size> videoSize = camera.getParameters().getSupporte ...
- java.lang.IllegalStateException: The remote endpoint was in state [TEXT_FULL_WRITING] which is an invalid state for called method 解决办法
java.lang.IllegalStateException: The remote endpoint was in state [TEXT_FULL_WRITING] which is an in ...
- MongoError: server instance in invalid state undefined 解决办法
MongoDB关键点集锦(更新中...) 2017-01-20 09:33:48[其它数据库]点击数:15作者:Real_Bird的博客来源: 网络 随机为您推荐的文章:MongDB索引的介绍及使用 ...
- oracle 的自定义的存储函数遇到的 package or function is in an invalid state
转: oracle 的自定义的存储函数遇到的 package or function is in an invalid state 2017-10-28 11:08:17 major_tom 阅读数 ...
- State Machine.(状态机)
What is a State Machine? Any device that changes its state from one to another due to some actions a ...
- JavaScript对象状态
有限状态机(Finite-state machine)是一个非常有用的模型,可以模拟世界上大部分事物. 简单说,它有三个特征: * 状态总数(state)是有限的. * 任一时刻,只处在一种状态之中. ...
- [译]Kinect for Windows SDK开发入门(十八):Kinect Interaction交互控件
本文译自 http://dotneteers.net/blogs/vbandi/archive/2013/03/25/kinect-interactions-with-wpf-part-i-getti ...
- System Error Codes
很明显,以下的文字来自微软MSDN 链接http://msdn.microsoft.com/en-us/library/windows/desktop/ms681382(v=vs.85).aspx M ...
- Google C++ Style Guide
Background C++ is one of the main development languages used by many of Google's open-source project ...
随机推荐
- jdbc 接口学习笔记
一.JDBC概念 JDBC(Java Data Base Connectivity,java数据库连接)是一种用于执行SQL语句的Java API,可以为多种关系型数据库提供统一访问,它由一组用Jav ...
- POJ 2418 简单trie树
Hardwood Species Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 21845 Accepted: 8551 De ...
- 题解报告:hdu 1850 Being a Good Boy in Spring Festival(尼姆博弈)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1850 Problem Description 一年在外 父母时刻牵挂春节回家 你能做几天好孩子吗寒假里 ...
- C# Datetime 使用详解
获得当前系统时间: DateTime dt = DateTime.Now; Environment.TickCount可以得到“系统启动到现在”的毫秒值 DateTime now = DateTime ...
- 《Linux程序设计》笔记(二)shell程序设计
1. 进程树形显示 ps -e f 2. 重定向 > 覆盖文件 >> 附加至文件 1> 标准输出 2> 标准错误输出 0 代表一个程序的标准输入 3. 程序可以在当前目录 ...
- sql_3 join
http://www.cnblogs.com/rush/archive/2012/03/27/2420246.html
- vue路由中的 Meta
在项目中肯定有这样的需求,那就是在某个页面的时候,顶部展示 现在当前的页面路径,如下图: 这个在vue中其实很好实现. 首先出现这个肯定是相对应不同的页面,也就是说对应不同的路由,我们在定义路由的时候 ...
- Js 字符串中提取数字
一 parseInt()方法: 首先想到的是js提供的parseInt方法,例子: var str ="4500元"; var num = parseInt(str); alert ...
- Windows上架设自己的ssh代理 — copSSH
最近网上对ssh代理讨论的比较多, 主要是为了穿墙. 其实在自己的电脑上也可以架设ssh代理, 当然国内自己架的不具有FQ功能, 如果你有国外朋友或是远程win服务器…则可以用此方法架设私有代理. 其 ...
- Android 性能测试初探(三)
书接上文 Android 性能测试初探(二) 本文接着往下聊,今天主聊 CPU 及 内存 看到这两个名词,做过PC性能测试的就比较熟悉了,同样的性能测试关注点 :) 首先说说内存,移动端关注的是内存消 ...