get the proper video preview size at switching to video mode

This commit is contained in:
tibbi 2016-07-12 16:36:43 +02:00
parent d33e481e27
commit ebbc1c5647
1 changed files with 17 additions and 6 deletions

View File

@ -300,12 +300,12 @@ public class Preview extends ViewGroup implements SurfaceHolder.Callback, View.O
} }
private Camera.Size getOptimalVideoSize() { private Camera.Size getOptimalVideoSize() {
final List<Camera.Size> sizes = mParameters.getSupportedVideoSizes(); final List<Camera.Size> sizes = getSupportedVideoSizes();
Collections.sort(sizes, new SizesComparator()); Collections.sort(sizes, new SizesComparator());
Camera.Size maxSize = sizes.get(0); Camera.Size maxSize = sizes.get(0);
for (Camera.Size size : sizes) { for (Camera.Size size : sizes) {
final boolean isSixteenToNine = isProperRatio(size); final boolean isProperRatio = isProperRatio(size);
if (isSixteenToNine) { if (isProperRatio) {
maxSize = size; maxSize = size;
break; break;
} }
@ -313,6 +313,14 @@ public class Preview extends ViewGroup implements SurfaceHolder.Callback, View.O
return maxSize; return maxSize;
} }
public List<Camera.Size> getSupportedVideoSizes() {
if (mParameters.getSupportedVideoSizes() != null) {
return mParameters.getSupportedVideoSizes();
} else {
return mParameters.getSupportedPreviewSizes();
}
}
private int compensateDeviceRotation() { private int compensateDeviceRotation() {
int degrees = 0; int degrees = 0;
boolean isFrontCamera = (mCurrCameraId == Camera.CameraInfo.CAMERA_FACING_FRONT); boolean isFrontCamera = (mCurrCameraId == Camera.CameraInfo.CAMERA_FACING_FRONT);
@ -549,9 +557,12 @@ public class Preview extends ViewGroup implements SurfaceHolder.Callback, View.O
return false; return false;
mSwitchToVideoAsap = false; mSwitchToVideoAsap = false;
final Camera.Size preferred = mParameters.getPreferredPreviewSizeForVideo(); Camera.Size preferred = mParameters.getPreferredPreviewSizeForVideo();
if (preferred == null) if (preferred == null) {
return false; final List<Camera.Size> previewSizes = mParameters.getSupportedPreviewSizes();
Collections.sort(previewSizes, new SizesComparator());
preferred = previewSizes.get(0);
}
mParameters.setPreviewSize(preferred.width, preferred.height); mParameters.setPreviewSize(preferred.width, preferred.height);
mCamera.setParameters(mParameters); mCamera.setParameters(mParameters);