I am writing an app where I am allowing the user to capture video using the phones camera. I am using my own code to record the video as opposed to Androids built in camera app.
Everything is working OK except I need to be able to access the list of supported camera resolutions so I can choose at runtime which one to use. I am looking for something like getSupportedPictureSizes()
but for video. Android 3.0 has this functionality but I am looking for something for 2.2.
As of right now I am using CamcorderProfile.QUALITY_HIGH / QUALITY_LOW
, but this only gives me two options and on the phones I have been testing on, the file sizes are at each extreme.(QUALITY_LOW is 216 kb/s and QUALITY_HIGH is > 3 MB/s)
Any hel开发者_JAVA百科p would be greatly appreciated, Thank You!
Did you try to use the getSupportedVideoSizes()
method from Camera.Parameters
class?
public List<Camera.Size> getSupportedVideoSizes()
This method returns a list of Size objects. It will return null
if the camera does not have separate preview and video output. The answer here indicates that when this returns null
you may use the getSupportedPreviewSizes()
list.
Ok I think I figured it out. It seems to work correctly on the phones I have been testing on.
List<Size> tmpList = camera.getParameters().getSupportedPreviewSizes();
final List<Size> sizeList = new Vector<Size>();
//compair the apsect ratio of the candidate sizes against the real ratio
Double aspectRatio = (Double.valueOf(getWindowManager().getDefaultDisplay().getHeight()) / getWindowManager().getDefaultDisplay().getWidth());
for(int i=0; i<tmpList.size(); i++){
Double tmpRatio = Double.valueOf(tmpList.get(i).height) / tmpList.get(i).width;
if(Math.abs(aspectRatio - tmpRatio) < .15){
sizeList.add(tmpList.get(i));
}
}
精彩评论