setOutputFormat called in an invalid state: 1
来源:互联网 发布:3000元左右手机 知乎 编辑:程序博客网 时间:2024/06/08 17:30
在编写一个简单的录像应用程序的时候,爆出如下异常:
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 blocke.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}
1 0
- setOutputFormat called in an invalid state: 1
- android 录音时报 MediaRecorder: setOutputFile called in an invalid state(1)
- prepareAsync called in state 1
- Android录制视频报错setVideoSize called in a invalid state 1
- mediaplayer stop called in state 1
- mediaplayer stop called in state 1
- mysql出现Connection.close() has already been called. Invalid operation in this state.
- Error: MediaPlayer start called in state 1 & 64
- 【完美解决系列】Android MediaPlayer stop called in state 1
- ORA-06575: Package or function SPLIT is in an invalid state
- oracle 的自定义的存储函数遇到的 package or function is in an invalid state
- Error: MediaPlayer start called in state 64
- 错误信息:setDataSource is called in state
- media player prepareAsync called in state 8
- Mediaplayer start called in state 0
- WebView called on thread 'JavaBridge'的问题和MediaPlayer stop called in state 1报错解决记录
- OUI-10022:The target area /oracle/oraInventory cannot be used because it is in an invalid state.
- Android MediaPlayer播放prepareAsync called in state 8解决办法
- 移动互联网3.0时代【逆向付费】---微乐
- 设计模式—原型模式
- 12条很有用的Chrome浏览器命令
- 操作系统笔试、面试题
- 用好赏识教育的3条准则
- setOutputFormat called in an invalid state: 1
- c++ socket编程
- UI引擎机制系列(一)GLRender线程处理接口设计
- sensor调试过程中HAL层数据不能传输到app
- Plupload Api
- Oracle分页存储过程及PLSQL中的调用脚本
- static file in subfolder of static in django
- Android根据不同语言切换图片
- history.back返回后数据丢失的解决办法