中国优质的IT技术网站
专业IT技术创作平台
IT职业在线教育平台
如何调用系统相机,拍照、录视频?
微信扫码分享
/** * 调用系统相机,拍照、录视频 * @param options * @returns */ static async camera(options?: CameraOptions): Promise<string> { try { if (!options) { options = new CameraOptions(); } if (!options.mediaTypes || options.mediaTypes.length == 0) { options.mediaTypes = [cameraPicker.PickerMediaType.PHOTO, cameraPicker.PickerMediaType.VIDEO]; } let pickerProfile: cameraPicker.PickerProfile = { cameraPosition: options.cameraPosition ? options.cameraPosition : camera.CameraPosition.CAMERA_POSITION_BACK, videoDuration: options.videoDuration, saveUri: options.saveUri }; let context = getContext() as common.Context; let pickerResult: cameraPicker.PickerResult = await cameraPicker.pick(context, options.mediaTypes, pickerProfile); if (pickerResult && pickerResult.resultUri) { return pickerResult.resultUri; } } catch (err) { let error = err as BusinessError; LogUtil.error(`PickerUtil-camera-异常 ~ code: ${error.code} -·- message: ${error.message}`); } return ""; }