use of com.codename1.capture.VideoCaptureConstraints in project CodenameOne by codenameone.
the class IOSVideoCaptureConstraintsCompiler method compile.
@Override
public VideoCaptureConstraints compile(VideoCaptureConstraints cnst) {
VideoCaptureConstraints out = new VideoCaptureConstraints(cnst);
int[] prefSize = new int[] { cnst.getPreferredWidth(), cnst.getPreferredHeight() };
Object[] supportedDimensions = new Object[] { new int[] { 640, 480 }, new int[] { 1280, 720 }, new int[] { 960, 540 } };
boolean dimensionsSupported = false;
for (Object o : supportedDimensions) {
int[] dim = (int[]) o;
if (Arrays.equals(dim, prefSize)) {
dimensionsSupported = true;
break;
}
}
if (!dimensionsSupported) {
out.preferredWidth(0).preferredHeight(0);
}
out.preferredMaxFileSize(0);
if (prefSize[0] != 0 && prefSize[1] != 0 && cnst.getPreferredQuality() == 0) {
// Use the preferred size to infer a quality value.
if (prefSize[0] <= 320 || prefSize[1] <= 240) {
out.preferredQuality(VideoCaptureConstraints.QUALITY_LOW);
} else if (prefSize[0] > 800 || prefSize[1] > 600) {
out.preferredQuality(VideoCaptureConstraints.QUALITY_HIGH);
}
}
return out;
}
use of com.codename1.capture.VideoCaptureConstraints in project CodenameOne by codenameone.
the class AndroidImplementation method captureVideo.
@Override
public void captureVideo(VideoCaptureConstraints cnst, ActionListener response) {
if (getActivity() == null) {
throw new RuntimeException("Cannot capture video in background mode");
}
if (!checkForPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, "This is required to take a video")) {
return;
}
if (getRequestedPermissions().contains(Manifest.permission.CAMERA)) {
// See https://github.com/codenameone/CodenameOne/issues/2409#issuecomment-391696058
if (!checkForPermission(Manifest.permission.CAMERA, "This is required to take a video")) {
return;
}
}
callback = new EventDispatcher();
callback.addListener(response);
Intent intent = new Intent(android.provider.MediaStore.ACTION_VIDEO_CAPTURE);
if (cnst != null) {
switch(cnst.getQuality()) {
case VideoCaptureConstraints.QUALITY_LOW:
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 0);
break;
case VideoCaptureConstraints.QUALITY_HIGH:
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
break;
}
if (cnst.getMaxFileSize() > 0) {
intent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, cnst.getMaxFileSize());
}
if (cnst.getMaxLength() > 0) {
intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, cnst.getMaxLength());
}
}
File newFile = getOutputMediaFile(true);
newFile.getParentFile().mkdirs();
newFile.getParentFile().setWritable(true, false);
Uri videoUri = FileProvider.getUriForFile(getContext(), getContext().getPackageName() + ".provider", newFile);
Storage.getInstance().writeObject("videoUri", newFile.getAbsolutePath());
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, videoUri);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
if (Build.VERSION.SDK_INT < 21) {
List<ResolveInfo> resInfoList = getContext().getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo resolveInfo : resInfoList) {
String packageName = resolveInfo.activityInfo.packageName;
getContext().grantUriPermission(packageName, videoUri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
}
}
this.getActivity().startActivityForResult(intent, CAPTURE_VIDEO);
}
use of com.codename1.capture.VideoCaptureConstraints in project CodenameOne by codenameone.
the class AndroidVideoCaptureConstraintsCompiler method compile.
@Override
public VideoCaptureConstraints compile(VideoCaptureConstraints cnst) {
VideoCaptureConstraints out = new VideoCaptureConstraints(cnst);
// We can't actually support explicit width and height constraints
// right now, so we set these to zero
out.preferredHeight(0);
out.preferredWidth(0);
// But we do support low and high quality
switch(cnst.getPreferredQuality()) {
case VideoCaptureConstraints.QUALITY_LOW:
case VideoCaptureConstraints.QUALITY_HIGH:
break;
default:
// Smaller than 640x480 we'll call low quality. That number is just pulled out of the air.
if (cnst.getPreferredHeight() > 0 && cnst.getPreferredWidth() > 0) {
if (cnst.getPreferredHeight() <= 480 || cnst.getPreferredWidth() <= 640) {
out.preferredQuality(VideoCaptureConstraints.QUALITY_LOW);
} else {
out.preferredQuality(VideoCaptureConstraints.QUALITY_HIGH);
}
}
}
return out;
}
use of com.codename1.capture.VideoCaptureConstraints in project CodenameOne by codenameone.
the class IOSImplementation method captureVideo.
/**
* Captures a video and notifies with the data when available
* @param response callback for the resulting video
*/
public void captureVideo(VideoCaptureConstraints cnst, ActionListener response) {
if (!nativeInstance.checkCameraUsage() || !nativeInstance.checkMicrophoneUsage()) {
throw new RuntimeException("Please add the ios.NSCameraUsageDescription and ios.NSMicrophoneUsageDescription build hints");
}
gallerySelectMultiple = false;
captureCallback = new EventDispatcher();
captureCallback.addListener(response);
nativeInstance.captureCamera(true, getUIPickerControllerQualityType(cnst), cnst != null ? cnst.getPreferredMaxLength() : 0);
dropEvents = true;
}
Aggregations