Android录制视频,可限制时长,限大小

Android录制视频:

public static void recordVideo(Context context, int limit_time, int size) {
    Intent intent = new Intent();
    intent.setAction(MediaStore.ACTION_VIDEO_CAPTURE);
    intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
    intent.addCategory(Intent.CATEGORY_DEFAULT);
    if (size != 0) {
        intent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, size * 1024 * 1024L);//限制录制大小(10M=10 * 1024 * 1024L)
    }
    if (limit_time != 0) {
        intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, limit_time);//限制录制时间(10秒=10)
    }

    File videoFile = createVideoFile(context);
    if (videoFile != null) {
        intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(videoFile));
        context.startActivityForResult(intent, CAPTURE_VIDEO_CODE);
}}

你可能感兴趣的:(Android)