To get the resolution of a recorded video supported by your phone when you record a video, use the following code:
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);
Two errors occurred, one time when recording a video, calling Camera.getparameters () times parameters is empty
, because the function was called after Camera.unlock (). It is OK to get it before unlock.
Another error is setvideosize called in a invalid state 1
, enter the Setvideosize function to find the condition description that throws the exception
/** * 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()
Indicates that the exception occurs if Setvideosize is called after prepare () or Setoutputformat (), which means that the Setvideosize function is required before prepare () and Setoutputformat ( ) is called after.
Check the code, found that I call setvideosize unexpectedly in Setoutputformat () before, changed to Setoutputformat () after the OK.
Android recording video error setvideosize called in a invalid state 1