get Best Video Profile - Android Media

Android examples for Media:Video

Description

get Best Video Profile

Demo Code


//package com.java2s;

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;//w ww. j  a  v  a 2s .c  o m
        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;
                }
            }
        }
        return null;
    }
}

Related Tutorials