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 ...
随机推荐
- c语言中struct的初始化
C++中的struct已经和class一样,可以用构造函数初始化. C语言中的struct怎么初始化呢? typedef struct _TEST_T { int i; c ...
- xhtml1-frameset.dtd
<!-- Extensible HTML version 1.0 Frameset DTD This is the same as HTML 4 Frameset except for chan ...
- Combotree--别样的构建层级json字符串
1.先看效果 2.需要使用层级json格式,如: 3.先不要着急怎么去实现它,先来想想怎么用对象来描述它 4.代码 protected void Page_Load(object sender, Ev ...
- 修改Switch 的颜色
1:效果图 2:布局 <Switch android:id="@+id/switch_bg" style="@style/switchStyle" and ...
- HangFire的定时任务和Quartz.NET总结(三)Quartz 配置
在一个Net Core需求中,需要在每天的凌晨三点去抓取两个电商仓库的剩余的每个料号的数量来写会自己的表中, 用到了HangFire的定时任务 这篇文章讲的很详细记录下 文章2 这篇更简单 Qu ...
- error C3859: 超过了PCH的虚拟内存范围;请使用“-Zm33”或更大的命令行选项重新编译
编译 ORB_SLAM的Release版本时,出现了此问题: 错误 2 error C3859: 超过了 PCH 的虚拟内存范围;请使用"-Zm465"或更大的命令行 修改方法: ...
- AFNetworking源码解析-https证书相关
本篇说说安全相关的AFSecurityPolicy模块,AFSecurityPolicy用于验证HTTPS请求的证书,先来看看HTTPS的原理和证书相关的几个问题. HTTPS HTTPS连接建立过程 ...
- 关于java中的继承
我们都知道Java中的继承是复用代码.扩展子类的一种方式,继承使得Java中重复的代码能够被提取出来供子类共用,对于Java程序的性能以及修改和扩展有很大的意义,所以这是一个非常重要的知识点. 那么对 ...
- <meta http-equiv="refresh" content="3"> 什么意思?
<meta http-equiv="refresh" content="3"> 什么意思?平常都是<meta http-equiv=" ...
- OAuth网络协议
一.应用场景 为了理解OAuth的适用场合,让我举一个假设的例子. 有一个"云冲印"的网站,可以将用户储存在Google的照片,冲印出来.用户为了使用该服务,必须让"云冲 ...