標籤:使用 exce put size als out cap 代碼 this
錄製視頻時想擷取手機支援的錄製視頻的解析度,使用代碼如下:
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