所有视频预览尺寸并非在所有设备都支持。你只能以编程方式进行。 如果大小是不适用的,然后扔媒体记录停止-19错误
int width = 320;
int height = 240;
try {
//get the available sizes of the video
List<Size> tmpList = getSupportedVideoSizes();
final List<Size> sizeList = new Vector<Size>();
// compare the apsect ratio of the candidate sizes against the
// real ratio
Double aspectRatio = (Double.valueOf(getWindowManager()
.getDefaultDisplay().getHeight())/getWindowManager()
.getDefaultDisplay().getWidth());
for (int i = tmpList.size() - 1; i > 0; i--) {
Double tmpRatio = Double.valueOf(tmpList.get(i).height)
/tmpList.get(i).width;
if (EnableLog.LOG_TAG) {
Log.e("Width & height", tmpList.get(i).width + " x "
+ tmpList.get(i).height);
}
if (Math.abs(aspectRatio - tmpRatio) < .15) {
width = tmpList.get(i).width;
height = tmpList.get(i).height;
sizeList.add(tmpList.get(i));
}
}
if (EnableLog.LOG_TAG) {
Log.e("tmpList", tmpList + "*");
}
} catch (Exception e) {
e.printStackTrace();
}
// set the size of video.
// If the size is not applicable then throw the media recorder stop
// -19 error
mrec.setVideoSize(width, height);
/**
* This method will return the size of the video
*
* if the getSupportedVideoSizes() is return null
*
* then it is possible to get the size of video from
* getSupportedPreviewSizes()
*
* @return list of size
*/
public List<Size> getSupportedVideoSizes() {
if (params.getSupportedVideoSizes() != null) {
return params.getSupportedVideoSizes();
} else {
// Video sizes may be null, which indicates that all the supported
// preview sizes are supported for video recording.
return params.getSupportedPreviewSizes();
}
}
试试这个代码,也许会有所帮助。
编辑:
根据您的意见,你要那么你需要改变的循环来设定最佳预览大小。我会告诉你的例子
变化for循环
for (int i = tmpList.size() - 1; i > 0; i--) {
}
到
for (int i = 0 ; i < tmpList.size()-1; i++) {
}
这会给你更好的预览大小。
尽管当然欢迎您随时调用'setPreviewSize()',否则会期望许多设备崩溃,并说这不是支持的预览大小。 – CommonsWare
@CommonsWare是的。它会在很多设备上崩溃。那么有什么办法可以实现与第二个效果相同的效果? –
您可以尝试在预览表面使用'TextureView'并将矩阵应用于'TextureView'来旋转预览帧。 – CommonsWare