get Best Video Profile - Android android.media

Android examples for android.media:Video

Description

get Best Video Profile

Demo Code

import android.media.CamcorderProfile;

public class Main {

  public static CamcorderProfile getBestVideoProfile(int cameraId, int width, int height, int rotation) {
    final int[] qualities = { CamcorderProfile.QUALITY_LOW, CamcorderProfile.QUALITY_CIF, CamcorderProfile.QUALITY_480P,
        CamcorderProfile.QUALITY_720P, CamcorderProfile.QUALITY_1080P, CamcorderProfile.QUALITY_HIGH };
    final boolean swap = rotation % 180 != 0;
    final int requiredWidth = swap ? height : width, requiredHeight = swap ? width : height;
    for (int quality : qualities) {
      if (CamcorderProfile.hasProfile(cameraId, quality)) {
        final CamcorderProfile profile = CamcorderProfile.get(cameraId, quality);
        if (profile.videoFrameWidth >= requiredWidth && profile.videoFrameHeight >= requiredHeight) {
          return profile;
        }/*from w  ww.  j a  va2  s.c o  m*/
      }
    }
    return null;
  }

}

Related Tutorials