Android录制视频报错setVideoSize called in a invalid state 1
2017-01-22 14:30
543 查看
录制视频时想获取手机支持的录制视频的分辨率,使用代码如下:
出现了两次错误,一次是录制视频时调用camera.getParameters()时报
还有一个错误就是
查了下代码,发现我调用setVideoSize竟然是在setOutputFormat()之前,改到setOutputFormat()之后就ok了。
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了。
相关文章推荐
- Android录制视频报错setVideoSize called in a invalid state 1
- android 录音时报 MediaRecorder: setOutputFile called in an invalid state(1)
- 解决Android录制适配 setVideoSize 后start failed问题
- android:视频录制编写代码一直报非法状态错误,很多时候定位在setVideoEncoder和setAudioEncoder
- 音乐Visualizer类的错误 setCaptureSize() called in wrong state: 2 的解决办法
- setOutputFormat called in an invalid state: 1
- setOutputFormat called in an invalid state: 1
- Android模拟器无法启动,报错:Cannot set up guest memory ‘android_arm’ Invalid argument的解决方法
- mysql出现Connection.close() has already been called. Invalid operation in this state.
- android错误之MediaPlayer用法的Media Player called in state *
- java.lang.IllegalStateException: The remote endpoint was in state [TEXT_FULL_WRITING] which is an invalid state for called method 解决办法
- Android MediaPlayer播放prepareAsync called in state 8解决办法
- 错误信息:setDataSource is called in state
- Android MediaPlayer 播放prepareAsync called in state 8解决办法
- Android模拟器无法启动,报错:Cannot set up guest memory ‘android_arm’ Invalid argument的解决方法
- android错误之MediaPlayer用法的Media Player called in state *,androidmediaplayer
- 【完美解决系列】Android MediaPlayer stop called in state 1
- Android MediaPlayer播放prepareAsync called in state 8解决办法
- Android MediaPlayer Error (-38, 0) “stop called in state 0”
- 关于android创建对话框报错The method setPositiveButton(int, DialogInterface.OnClickListener) in the type Alert