diff --git a/uni_modules/XF-cameraUTS/changelog.md b/uni_modules/XF-cameraUTS/changelog.md new file mode 100644 index 0000000..5e5871e --- /dev/null +++ b/uni_modules/XF-cameraUTS/changelog.md @@ -0,0 +1,24 @@ +## 1.1.1(2025-10-15) + 修复监听持续返回事件问题。 +## 1.1.0(2024-10-13) +修改AndroidManifest.xml下的包名。 +## 1.0.9(2024-10-12) +删除takePhoto下的takeMode参数逻辑 +## 1.0.8(2024-10-10) +兼容处理uniapp无法切换相机和拍照的问题。 +## 1.0.7(2024-10-09) +修复uniapp环境下不能正常使用插件问题。 +## 1.0.6(2024-09-13) +去掉插件内部权限申请逻辑。 +## 1.0.5(2024-08-10) +修复Android不能正常录像的问题。 +## 1.0.4(2024-08-08) +修复iOS默认相机设置不生效的问题 +## 1.0.3(2024-08-06) +修改iOS拍照接口默认质量为原图。 +## 1.0.2(2024-07-22) +修复iOS编译问题。 +## 1.0.1(2024-07-04) +修复一些bug。 +## 1.0.0(2024-07-04) +初始化发布 diff --git a/uni_modules/XF-cameraUTS/encrypt b/uni_modules/XF-cameraUTS/encrypt new file mode 100644 index 0000000..708c6d5 Binary files /dev/null and b/uni_modules/XF-cameraUTS/encrypt differ diff --git a/uni_modules/XF-cameraUTS/package.json b/uni_modules/XF-cameraUTS/package.json new file mode 100644 index 0000000..0603086 --- /dev/null +++ b/uni_modules/XF-cameraUTS/package.json @@ -0,0 +1,114 @@ +{ + "id": "XF-cameraUTS", + "displayName": "UTS实现自定义相机拍照和录像功能", + "version": "1.1.1", + "description": "XF-cameraUTS封装了Android和iOS自定义相机预览的功能。", + "keywords": [ + "相机", + "录像", + "拍照" +], + "repository": "", + "engines": { + "HBuilderX": "^3.7.0", + "uni-app": "^4.74", + "uni-app-x": "^4.74" + }, + "dcloudext": { + "type": "component-uts", + "sale": { + "regular": { + "price": "168.00" + }, + "sourcecode": { + "price": "0.00" + } + }, + "contact": { + "qq": "" + }, + "declaration": { + "ads": "无", + "data": "无", + "permissions": "android.permission.CAMERA\nandroid.permission.RECORD_AUDIO\nandroid.permission.WRITE_EXTERNAL_STORAGE\nandroid.permission.READ_EXTERNAL_STORAGE\nPrivacy - Camera Usage Description" + }, + "npmurl": "", + "darkmode": "x", + "i18n": "x", + "widescreen": "x" + }, + "uni_modules": { + "dependencies": [], + "encrypt": [], + "platforms": { + "cloud": { + "tcb": "√", + "aliyun": "√", + "alipay": "√" + }, + "client": { + "uni-app": { + "vue": { + "vue2": "x", + "vue3": "x" + }, + "web": { + "safari": "x", + "chrome": "x" + }, + "app": { + "vue": "x", + "nvue": { + "extVersion": "1.0.1", + "minVersion": "" + }, + "android": { + "extVersion": "1.0.1", + "minVersion": "21" + }, + "ios": { + "extVersion": "1.0.1", + "minVersion": "12" + }, + "harmony": "x" + }, + "mp": { + "weixin": "x", + "alipay": "x", + "toutiao": "x", + "baidu": "x", + "kuaishou": "x", + "jd": "x", + "harmony": "x", + "qq": "x", + "lark": "x" + }, + "quickapp": { + "huawei": "x", + "union": "x" + } + }, + "uni-app-x": { + "web": { + "safari": "x", + "chrome": "x" + }, + "app": { + "android": { + "extVersion": "1.0.1", + "minVersion": "21" + }, + "ios": { + "extVersion": "1.0.1", + "minVersion": "12" + }, + "harmony": "x" + }, + "mp": { + "weixin": "x" + } + } + } + } + } +} \ No newline at end of file diff --git a/uni_modules/XF-cameraUTS/readme.md b/uni_modules/XF-cameraUTS/readme.md new file mode 100644 index 0000000..9871e04 --- /dev/null +++ b/uni_modules/XF-cameraUTS/readme.md @@ -0,0 +1,183 @@ +# **概述** + +XF-cameraUTS封装了Android和iOS自定义相机预览的功能。 + +## **模块调用** + +```js + + +``` + +## 参数说明: + +position: + +- 类型:字符串型 +- 描述:(可选项)前置或者后置相机。(front前置 |back 后置) + +flash: + +- 类型:字符串型 +- 描述:(可选项)是否开启闪光灯。( auto, on, off, torch) + + +## **插件接口** + +
+ +# **takePhoto** + +拍照 + +## uni-app项目中(nvue)调用示例: + +```js +import { takePhoto } from "@/uni_modules/XF-cameraUTS" + +takePhoto({ + success: (res) => { + console.log(res) + } +}); +``` + +## uni-app x项目(uvue)中调用示例: + +```js +import { takePhoto } from "@/uni_modules/XF-cameraUTS"; +import { TakePhotoOption, TakePhotoSuccessCallbackResult } from "@/uni_modules/XF-cameraUTS/utssdk/interface.uts"; + +let options = { + success: (res : TakePhotoSuccessCallbackResult) => { + console.log(res) + } +} as TakePhotoOption; +takePhoto(options); +``` + +## 可用性 + +iOS、Android系统 + +可提供的1.0.0及更高版本 + + +
+ +# **startRecord** + +开始录像 + +## uni-app项目中(nvue)调用示例: + +```js +import { startRecord } from "@/uni_modules/XF-cameraUTS" + +startRecord({ + success: (res) => { + console.log(res) + } +}); +``` + +## uni-app x项目(uvue)中调用示例: + +```js +import { startRecord } from "@/uni_modules/XF-cameraUTS"; +import { CameraContextStartRecordOption, GeneralCallbackResult } from "@/uni_modules/XF-cameraUTS/utssdk/interface.uts"; + +let options = { + success: (res : GeneralCallbackResult) => { + console.log(res) + } +} as CameraContextStartRecordOption; +startRecord(options); +``` + +## 可用性 + +iOS、Android系统 + +可提供的1.0.0及更高版本 + + + +
+ +# **stopRecord** + +停止录像 + +## uni-app项目中(nvue)调用示例: + +```js +import { stopRecord } from "@/uni_modules/XF-cameraUTS" + +stopRecord({ + success: (res) => { + console.log(res) + } +}); +``` + +## uni-app x项目(uvue)中调用示例: + +```js +import { stopRecord } from "@/uni_modules/XF-cameraUTS"; +import { CameraContextStopRecordOption, StopRecordSuccessCallbackResult } from "@/uni_modules/XF-cameraUTS/utssdk/interface.uts"; + +let options = { + success: (res : StopRecordSuccessCallbackResult) => { + console.log(res) + } +} as CameraContextStopRecordOption; +stopRecord(options); +``` + +## 可用性 + +iOS、Android系统 + +可提供的1.0.0及更高版本 + + +
+ +# **switchCamera** + +切换相机 + +## uni-app项目中(nvue)调用示例: + +```js +import { switchCamera } from "@/uni_modules/XF-cameraUTS" + +switchCamera({ + position: 'back', + success: (res) => { + console.log(res) + } +}); +``` + +## uni-app x项目(uvue)中调用示例: + +```js +import { switchCamera } from "@/uni_modules/XF-cameraUTS"; +import { SwitchOption, GeneralCallbackResult } from "@/uni_modules/XF-cameraUTS/utssdk/interface.uts"; + +let options = { + position: 'back', + success: (res : GeneralCallbackResult) => { + console.log(res) + } +} as SwitchOption; +switchCamera(options); +``` + +## 可用性 + +iOS、Android系统 + +可提供的1.0.8及更高版本 \ No newline at end of file diff --git a/uni_modules/XF-cameraUTS/utssdk/app-android/AndroidManifest.xml b/uni_modules/XF-cameraUTS/utssdk/app-android/AndroidManifest.xml new file mode 100644 index 0000000..86f5b64 --- /dev/null +++ b/uni_modules/XF-cameraUTS/utssdk/app-android/AndroidManifest.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/uni_modules/XF-cameraUTS/utssdk/app-android/CameraManager.uts b/uni_modules/XF-cameraUTS/utssdk/app-android/CameraManager.uts new file mode 100644 index 0000000..39ca547 Binary files /dev/null and b/uni_modules/XF-cameraUTS/utssdk/app-android/CameraManager.uts differ diff --git a/uni_modules/XF-cameraUTS/utssdk/app-android/camera.uts b/uni_modules/XF-cameraUTS/utssdk/app-android/camera.uts new file mode 100644 index 0000000..605928a Binary files /dev/null and b/uni_modules/XF-cameraUTS/utssdk/app-android/camera.uts differ diff --git a/uni_modules/XF-cameraUTS/utssdk/app-android/config.json b/uni_modules/XF-cameraUTS/utssdk/app-android/config.json new file mode 100644 index 0000000..39e876f --- /dev/null +++ b/uni_modules/XF-cameraUTS/utssdk/app-android/config.json @@ -0,0 +1,20 @@ +{ + "minSdkVersion": "19", + "dependencies": [ + // 使用camera2实现的CameraX核心库 + // 定义camerax_version为"1.4.0-alpha04" + // 下面的行是可选的,因为core库通过camera-camera2间接包含 + "androidx.camera:camera-core:1.4.0-alpha04" + "androidx.camera:camera-camera2:1.4.0-alpha04" + // 如果你想要额外使用CameraX生命周期库 + "androidx.camera:camera-lifecycle:1.4.0-alpha04" + // 如果你想要额外使用CameraX视频捕获库 + "androidx.camera:camera-video:1.4.0-alpha04" + // 如果你想要额外使用CameraX视图类 + "androidx.camera:camera-view:1.4.0-alpha04" + // 如果你想要额外添加CameraX ML Kit Vision集成 + // "androidx.camera:camera-mlkit-vision:1.4.0-alpha04" + // 如果你想要额外使用CameraX扩展库 + // "androidx.camera:camera-extensions:1.4.0-alpha04" + ] +} \ No newline at end of file diff --git a/uni_modules/XF-cameraUTS/utssdk/app-android/index.uts b/uni_modules/XF-cameraUTS/utssdk/app-android/index.uts new file mode 100644 index 0000000..86bf506 Binary files /dev/null and b/uni_modules/XF-cameraUTS/utssdk/app-android/index.uts differ diff --git a/uni_modules/XF-cameraUTS/utssdk/app-android/index.vue b/uni_modules/XF-cameraUTS/utssdk/app-android/index.vue new file mode 100644 index 0000000..c37a8c4 --- /dev/null +++ b/uni_modules/XF-cameraUTS/utssdk/app-android/index.vue @@ -0,0 +1,152 @@ + + + + + \ No newline at end of file diff --git a/uni_modules/XF-cameraUTS/utssdk/app-ios/CameraManager.uts b/uni_modules/XF-cameraUTS/utssdk/app-ios/CameraManager.uts new file mode 100644 index 0000000..39ca547 Binary files /dev/null and b/uni_modules/XF-cameraUTS/utssdk/app-ios/CameraManager.uts differ diff --git a/uni_modules/XF-cameraUTS/utssdk/app-ios/camera.uts b/uni_modules/XF-cameraUTS/utssdk/app-ios/camera.uts new file mode 100644 index 0000000..c8cfb6d Binary files /dev/null and b/uni_modules/XF-cameraUTS/utssdk/app-ios/camera.uts differ diff --git a/uni_modules/XF-cameraUTS/utssdk/app-ios/config.json b/uni_modules/XF-cameraUTS/utssdk/app-ios/config.json new file mode 100644 index 0000000..dfb9a96 --- /dev/null +++ b/uni_modules/XF-cameraUTS/utssdk/app-ios/config.json @@ -0,0 +1,3 @@ +{ + "deploymentTarget": "11" +} \ No newline at end of file diff --git a/uni_modules/XF-cameraUTS/utssdk/app-ios/index.uts b/uni_modules/XF-cameraUTS/utssdk/app-ios/index.uts new file mode 100644 index 0000000..593d823 Binary files /dev/null and b/uni_modules/XF-cameraUTS/utssdk/app-ios/index.uts differ diff --git a/uni_modules/XF-cameraUTS/utssdk/app-ios/index.vue b/uni_modules/XF-cameraUTS/utssdk/app-ios/index.vue new file mode 100644 index 0000000..fed3abc --- /dev/null +++ b/uni_modules/XF-cameraUTS/utssdk/app-ios/index.vue @@ -0,0 +1,167 @@ + + + + \ No newline at end of file diff --git a/uni_modules/XF-cameraUTS/utssdk/interface.uts b/uni_modules/XF-cameraUTS/utssdk/interface.uts new file mode 100644 index 0000000..ae3b66f --- /dev/null +++ b/uni_modules/XF-cameraUTS/utssdk/interface.uts @@ -0,0 +1,214 @@ +export type GeneralCallbackResult = { + /** 错误信息 */ + errMsg : string +} +export type TakePhotoSuccessCallbackResult = { + /** 照片文件的临时路径 (本地路径),安卓是jpg图片格式,ios是png */ + tempImagePath : string + quality : string + errMsg : string +} +/** 接口调用失败的回调函数 */ +export type TakePhotoFailCallback = (res : GeneralCallbackResult) => void +/** 接口调用成功的回调函数 */ +export type TakePhotoSuccessCallback = ( + result : TakePhotoSuccessCallbackResult +) => void + +/** 接口调用结束的回调函数(调用成功、失败都会执行) */ +export type TakePhotoCompleteCallback = (res : GeneralCallbackResult) => void + +export type TakePhotoOption = { + /** 接口调用结束的回调函数(调用成功、失败都会执行) */ + complete ?: TakePhotoCompleteCallback + /** 接口调用失败的回调函数 */ + fail ?: TakePhotoFailCallback + /** 成像质量 + * + * 可选值: + * - 'high': 高质量; + * - 'normal': 普通质量; + * - 'low': 低质量; + * - 'original': 原图; */ + quality ?: 'high' | 'normal' | 'low' | 'original' + /** + * 是否开启镜像 */ + selfieMirror ?: boolean + /** 接口调用成功的回调函数 */ + success ?: TakePhotoSuccessCallback +} + + +export type SetZoomSuccessCallbackResult = { + /** 实际设置的缩放级别。由于系统限制,某些机型可能无法设置成指定值,会改用最接近的可设值。 */ + zoom : number + errMsg : string +} +/** 接口调用结束的回调函数(调用成功、失败都会执行) */ +export type SetZoomCompleteCallback = (res : GeneralCallbackResult) => void +/** 接口调用失败的回调函数 */ +export type SetZoomFailCallback = (res : GeneralCallbackResult) => void +/** 接口调用成功的回调函数 */ +export type CameraContextSetZoomSuccessCallback = ( + result : SetZoomSuccessCallbackResult +) => void + +export type CameraContextSetZoomOption = { + /** 缩放级别,范围[1, maxZoom]。zoom 可取小数,精确到小数后一位。maxZoom 可在 bindinitdone 返回值中获取。 */ + zoom : number + /** 接口调用结束的回调函数(调用成功、失败都会执行) */ + complete ?: SetZoomCompleteCallback + /** 接口调用失败的回调函数 */ + fail ?: SetZoomFailCallback + /** 接口调用成功的回调函数 */ + success ?: CameraContextSetZoomSuccessCallback +} + +export type StartRecordTimeoutCallbackResult = { + /** 视频的文件的临时路径 (本地路径) */ + tempVideoPath : string +} + +/** 接口调用结束的回调函数(调用成功、失败都会执行) */ +export type StartRecordCompleteCallback = (res : GeneralCallbackResult) => void +/** 接口调用失败的回调函数 */ +export type StartRecordFailCallback = (res : GeneralCallbackResult) => void +/** 超过录制时长上限时会结束录像并触发此回调,录像异常退出时也会触发此回调 */ +export type StartRecordTimeoutCallback = ( + result : StartRecordTimeoutCallbackResult +) => void +/** 接口调用成功的回调函数 */ +export type CameraContextStartRecordSuccessCallback = ( + res : GeneralCallbackResult +) => void +export type CameraContextStartRecordOption = { + /** 接口调用结束的回调函数(调用成功、失败都会执行) */ + complete ?: StartRecordCompleteCallback + /** 接口调用失败的回调函数 */ + fail ?: StartRecordFailCallback + /** + * 是否开启镜像 */ + selfieMirror ?: boolean + /** 接口调用成功的回调函数 */ + success ?: CameraContextStartRecordSuccessCallback + /** + * 录制时长上限,单位为秒,最长不能超过 5 分钟 */ + timeout ?: number + /** 超过录制时长上限时会结束录像并触发此回调,录像异常退出时也会触发此回调 */ + timeoutCallback ?: StartRecordTimeoutCallback +} + +export type StopRecordSuccessCallbackResult = { + /** 视频的文件的临时路径 (本地路径) */ + tempVideoPath : string + errMsg : string +} +/** 接口调用结束的回调函数(调用成功、失败都会执行) */ +export type StopRecordCompleteCallback = (res : GeneralCallbackResult) => void +/** 接口调用失败的回调函数 */ +export type StopRecordFailCallback = (res : GeneralCallbackResult) => void +/** 接口调用成功的回调函数 */ +export type CameraContextStopRecordSuccessCallback = ( + result : StopRecordSuccessCallbackResult +) => void +export type CameraContextStopRecordOption = { + /** 接口调用结束的回调函数(调用成功、失败都会执行) */ + complete ?: StopRecordCompleteCallback + /** 启动视频压缩,压缩效果同`chooseVideo` */ + compressed ?: boolean + /** 接口调用失败的回调函数 */ + fail ?: StopRecordFailCallback + /** 接口调用成功的回调函数 */ + success ?: CameraContextStopRecordSuccessCallback +} + +/** 回调函数 */ +export type OnCameraFrameCallback = (result : OnCameraFrameCallbackResult) => void +export type OnCameraFrameCallbackResult = { + /** 图像像素点数据,一维数组,每四项表示一个像素点的 rgba */ + data : any + /** 图像数据矩形的高度 */ + height : number + /** 图像数据矩形的宽度 */ + width : number +} +/** 接口调用成功的回调函数 */ +export type StartSuccessCallback = (res : GeneralCallbackResult) => void +/** 接口调用失败的回调函数 */ +type StartFailCallback = (res : GeneralCallbackResult) => void +/** 接口调用结束的回调函数(调用成功、失败都会执行) */ +type StartCompleteCallback = (res : GeneralCallbackResult) => void +export type CameraFrameListenerStartOption = { + /** 接口调用结束的回调函数(调用成功、失败都会执行) */ + complete ?: StartCompleteCallback + /** 接口调用失败的回调函数 */ + fail ?: StartFailCallback + /** 接口调用成功的回调函数 */ + success ?: StartSuccessCallback + /** [Worker](https://developers.weixin.qq.com/miniprogram/dev/api/worker/Worker.html) + * + * 可选参数。如果需要在 iOS ExperimentalWorker 内监听摄像头帧数据,则需要传入对应 Worker 对象。详情 [Worker.getCameraFrameData](https://developers.weixin.qq.com/miniprogram/dev/api/worker/Worker.getCameraFrameData.html) */ + // worker ?: Worker +} + + +/** 接口调用结束的回调函数(调用成功、失败都会执行) */ +export type StopCompleteCallback = (res : GeneralCallbackResult) => void +/** 接口调用失败的回调函数 */ +export type StopFailCallback = (res : GeneralCallbackResult) => void +/** 接口调用成功的回调函数 */ +export type StopSuccessCallback = (res : GeneralCallbackResult) => void +export type StopOption = { + /** 接口调用结束的回调函数(调用成功、失败都会执行) */ + complete ?: StopCompleteCallback + /** 接口调用失败的回调函数 */ + fail ?: StopFailCallback + /** 接口调用成功的回调函数 */ + success ?: StopSuccessCallback +} + +export type FlashMode = 'auto' | 'on' | 'off' | 'torch' +export type DevicePosition = 'back' | 'front' +export type Resolution = 'low' | 'medium' | 'high' +export type FrameSize = 'medium' | 'small' | 'large' +export type QualityType = 'high' | 'normal' | 'low' | 'original' + + +export type CameraConfig = { + flash ?: FlashMode + devicePosition ?: DevicePosition + resolution ?: Resolution + frameSize ?: FrameSize +} + +////////////////////////////////////////////////////////////////////////////////////////////////// + +/** 接口调用结束的回调函数(调用成功、失败都会执行) */ +export type SwitchCompleteCallback = (res : GeneralCallbackResult) => void +/** 接口调用失败的回调函数 */ +export type SwitchFailCallback = (res : GeneralCallbackResult) => void +/** 接口调用成功的回调函数 */ +export type SwitchSuccessCallback = (res : GeneralCallbackResult) => void +export type SwitchOption = { + position : DevicePosition + /** 接口调用结束的回调函数(调用成功、失败都会执行) */ + complete ?: SwitchCompleteCallback + /** 接口调用失败的回调函数 */ + fail ?: SwitchFailCallback + /** 接口调用成功的回调函数 */ + success ?: SwitchSuccessCallback +} + +////////////////////////////////////////////////////////////////////////////////////////////////// +export type OnCameraFrameListenerOption = { + success ?: OnCameraFrameCallback +} + +export type TakePhoto = (options : TakePhotoOption) => void +export type SetZoom = (options : CameraContextSetZoomOption) => void +export type StartRecord = (options : CameraContextStartRecordOption) => void +export type StopRecord = (options : CameraContextStopRecordOption) => void +export type OnCameraFrameListener = (options : OnCameraFrameListenerOption) => void +export type StartCameraFrame = (options : CameraFrameListenerStartOption) => void +export type StopCameraFrame = (options : StopOption) => void +export type SwitchCamera = (options : SwitchOption) => void \ No newline at end of file