在编写一个简单的录像应用程序的时候,爆出例如以下异常:

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的更多相关文章

  1. Android录制视频报错setVideoSize called in a invalid state 1

    录制视频时想获取手机支持的录制视频的分辨率,使用代码如下: List<Camera.Size> videoSize = camera.getParameters().getSupporte ...

  2. 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 ...

  3. MongoError: server instance in invalid state undefined 解决办法

    MongoDB关键点集锦(更新中...)  2017-01-20 09:33:48[其它数据库]点击数:15作者:Real_Bird的博客来源: 网络 随机为您推荐的文章:MongDB索引的介绍及使用 ...

  4. 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 阅读数 ...

  5. State Machine.(状态机)

    What is a State Machine? Any device that changes its state from one to another due to some actions a ...

  6. JavaScript对象状态

    有限状态机(Finite-state machine)是一个非常有用的模型,可以模拟世界上大部分事物. 简单说,它有三个特征: * 状态总数(state)是有限的. * 任一时刻,只处在一种状态之中. ...

  7. [译]Kinect for Windows SDK开发入门(十八):Kinect Interaction交互控件

    本文译自 http://dotneteers.net/blogs/vbandi/archive/2013/03/25/kinect-interactions-with-wpf-part-i-getti ...

  8. System Error Codes

    很明显,以下的文字来自微软MSDN 链接http://msdn.microsoft.com/en-us/library/windows/desktop/ms681382(v=vs.85).aspx M ...

  9. Google C++ Style Guide

    Background C++ is one of the main development languages used by many of Google's open-source project ...

随机推荐

  1. c语言中struct的初始化

    C++中的struct已经和class一样,可以用构造函数初始化. C语言中的struct怎么初始化呢? typedef struct _TEST_T {        int i;        c ...

  2. SQL连接其它服务器操作

    Exec sp_droplinkedsrvlogin ZYB,Null --删除映射(录与链接服务器上远程登录之间的映射) Exec sp_dropserver ZYB --删除远程服务器链接 EXE ...

  3. 在PL/SQL中使用带参数的游标

    需求:查询并输出部门名称为SALES的员工信息 SET serveroutput ON; DECLARE CURSOR c_emp(paramName VARCHAR2) IS SELECT * FR ...

  4. 在PL/SQL中使用游标、动态sql和绑定变量的小例子

    需求:查询并输出30号部门的雇员信息 方式一:使用 loop...fetch SET serveroutput ON; DECLARE CURSOR c_emp IS ; v_emp emp%rowt ...

  5. Android fragment的切换(解决REPLACE的低效)

    在项目中切换Fragment,一直都是用replace()方法来替换Fragment.但是这样做有一个问题,每次切换的时候Fragment都会重新实列化,重新加载一次数据,这样做会非常消耗性能用用户的 ...

  6. Mysql Workbench 执行sql语句删除数据时提示error code 1175

    error code 1175是因为有安全模式限制 执行命令SET SQL_SAFE_UPDATES = 0;之后可以进行操作

  7. Azure Service Bus

    Azure Service Bus  是类似Rabbit的一个队列的应用. 找了两个基本的教程 First(但是这个,没有写怎么去链接账户)  Sec:这个有   Third(讲的也很好) Windo ...

  8. 【Oracle】to_char技巧

    Select to_char(sysdate,'ss') from dual;      取当前时间秒部分 Select to_char(sysdate,'mi') from dual;      取 ...

  9. [转]常用Git命令清单

    原文地址:http://www.ruanyifeng.com/blog/2015/12/git-cheat-sheet.html 作者: 阮一峰 日期: 2015年12月 9日 我每天使用 Git , ...

  10. C# 检测字符串是否为数字

    long n; 1. ], ].All(char.IsDigit); //识别空字符时候 会认为是数字 string str0 = ""; string str1 = " ...