aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorMykhailo Shchurov <shchurov.m@gmail.com>2016-01-19 18:01:34 +0900
committerYuichi Araki <yaraki@google.com>2016-01-19 18:01:34 +0900
commit90ec985bba5710f733d8959530163a480d1e84d4 (patch)
tree08c2fe536b1743f26c1a8bcd797b3382a1bedf11 /common
parent26ee87662313234a7109f1be0a7ad8a8a5d5a704 (diff)
downloadandroid-90ec985bba5710f733d8959530163a480d1e84d4.tar.gz
MediaRecorder: Merge a pull request
https://github.com/googlesamples/android-MediaRecorder/pull/3 Considered Camera.getSupportedVideoSizes(), handled exception on MediaRecorder.stop() Change-Id: Ie758fa9724fed1b2dc2f6cc1de9b609eb0dbaaad
Diffstat (limited to 'common')
-rw-r--r--common/src/java/com/example/android/common/media/CameraHelper.java38
1 files changed, 23 insertions, 15 deletions
diff --git a/common/src/java/com/example/android/common/media/CameraHelper.java b/common/src/java/com/example/android/common/media/CameraHelper.java
index 1fa84167..b578767d 100644
--- a/common/src/java/com/example/android/common/media/CameraHelper.java
+++ b/common/src/java/com/example/android/common/media/CameraHelper.java
@@ -36,49 +36,57 @@ public class CameraHelper {
public static final int MEDIA_TYPE_VIDEO = 2;
/**
- * Iterate over supported camera preview sizes to see which one best fits the
+ * Iterate over supported camera video sizes to see which one best fits the
* dimensions of the given view while maintaining the aspect ratio. If none can,
* be lenient with the aspect ratio.
*
- * @param sizes Supported camera preview sizes.
- * @param w The width of the view.
- * @param h The height of the view.
- * @return Best match camera preview size to fit in the view.
+ * @param supportedVideoSizes Supported camera video sizes.
+ * @param previewSizes Supported camera preview sizes.
+ * @param w The width of the view.
+ * @param h The height of the view.
+ * @return Best match camera video size to fit in the view.
*/
- public static Camera.Size getOptimalPreviewSize(List<Camera.Size> sizes, int w, int h) {
+ public static Camera.Size getOptimalVideoSize(List<Camera.Size> supportedVideoSizes,
+ List<Camera.Size> previewSizes, int w, int h) {
// Use a very small tolerance because we want an exact match.
final double ASPECT_TOLERANCE = 0.1;
double targetRatio = (double) w / h;
- if (sizes == null)
- return null;
+ // Supported video sizes list might be null, it means that we are allowed to use the preview
+ // sizes
+ List<Camera.Size> videoSizes;
+ if (supportedVideoSizes != null) {
+ videoSizes = supportedVideoSizes;
+ } else {
+ videoSizes = previewSizes;
+ }
Camera.Size optimalSize = null;
- // Start with max value and refine as we iterate over available preview sizes. This is the
+ // Start with max value and refine as we iterate over available video sizes. This is the
// minimum difference between view and camera height.
double minDiff = Double.MAX_VALUE;
// Target view height
int targetHeight = h;
- // Try to find a preview size that matches aspect ratio and the target view size.
+ // Try to find a video size that matches aspect ratio and the target view size.
// Iterate over all available sizes and pick the largest size that can fit in the view and
// still maintain the aspect ratio.
- for (Camera.Size size : sizes) {
+ for (Camera.Size size : videoSizes) {
double ratio = (double) size.width / size.height;
if (Math.abs(ratio - targetRatio) > ASPECT_TOLERANCE)
continue;
- if (Math.abs(size.height - targetHeight) < minDiff) {
+ if (Math.abs(size.height - targetHeight) < minDiff && previewSizes.contains(size)) {
optimalSize = size;
minDiff = Math.abs(size.height - targetHeight);
}
}
- // Cannot find preview size that matches the aspect ratio, ignore the requirement
+ // Cannot find video size that matches the aspect ratio, ignore the requirement
if (optimalSize == null) {
minDiff = Double.MAX_VALUE;
- for (Camera.Size size : sizes) {
- if (Math.abs(size.height - targetHeight) < minDiff) {
+ for (Camera.Size size : videoSizes) {
+ if (Math.abs(size.height - targetHeight) < minDiff && previewSizes.contains(size)) {
optimalSize = size;
minDiff = Math.abs(size.height - targetHeight);
}