Anton  Chukanov Anton Chukanov - 1 year ago 193
Android Question

How to limit duration of MediaStore in Android 7

What's new with duration limit of MediaStore in Android 7? There is nothing about it in documentation, but since sdk version 24 a device records a video without any limit.

final Activity activity = (Activity) context;
String controlId = videoInput.getControlId();
Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
if (videoInput.getMaxDuration() > 0) {
intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, videoInput.getMaxDuration());
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, videoInput.getRecordQuality().ordinal());
int requestCode = ActivityResultBus.getInstance().generateRequestCode(new SBundle(controlId));
activity.startActivityForResult(intent, requestCode);

I tested it on a real Motorola Nexus 6 with Android 7.0 and on virtual devices with 7.0 and 7.1.1. On previous versions all works as I want.

Mb something wrong with my
enter image description here

Answer Source

"There is no requirement for any camera app to honor EXTRA_DURATION_LIMIT. This is a request, not a command"

Any other way to limit the length of video ?

Not when you delegate the work to a third-party app. You are welcome to use the camera APIs and record the video directly yourself. Or, if your concern is not with the video on the device but some subset that you need to upload, look into how you can chop off the first 10 seconds of the video, and upload that piece.

This answer is directly compiled from this question : MediaStore.EXTRA_DURATION_LIMIT Not working Nexus Devices?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download