save code
This commit is contained in:
+184
-37
@@ -1,41 +1,188 @@
|
||||
<template>
|
||||
<view>
|
||||
<image class="logo" src="/static/logo.png"></image>
|
||||
<text class="title">{{title}}</text>
|
||||
<xf-camera style="height:750rpx; background-color: red;" @error="onError" :flash="flash"
|
||||
:position="device"></xf-camera>
|
||||
<image v-if="imagePath" mode="aspectFit" :src="imagePath"></image>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
const title = ref('Hello')
|
||||
// 相机闪光灯状态('off' | 'on' | 'auto')
|
||||
const flash = ref('off')
|
||||
<template>
|
||||
<!-- #ifdef APP -->
|
||||
<!-- <xf-ijk-view ref="ijkplayer" :style="{width:widthNum+'rpx',height:heightNum+'px',background:yanse}">
|
||||
|
||||
// 相机朝向('front' | 'back')
|
||||
const device = ref('back')
|
||||
</xf-ijk-view> -->
|
||||
|
||||
// 拍摄的图片路径
|
||||
const imagePath = ref('')
|
||||
<scroll-view class="page-scroll-view">
|
||||
<!-- #endif -->
|
||||
<view>
|
||||
<!-- <video class="video" :src=videoPath :controls="true"></video> -->
|
||||
<button @click="_toggleFlash">切换闪光灯</button>
|
||||
<button @click="_toggledevice">切换前后置</button>
|
||||
<button @click="_takePhoto">拍照</button>
|
||||
<button @click="_setZoom">设置缩放</button>
|
||||
<button @click="_startRecord">开始录像</button>
|
||||
<button @click="_stopRecord">结束录像</button>
|
||||
<button @click="_addFrameCallback">设置监听</button>
|
||||
<button @click="_startFrame">开启监听</button>
|
||||
<button @click="_stopFrame">关闭监听</button>
|
||||
<xf-camera style="height:750rpx; background-color: red;" @error="onError" :flash="flash"
|
||||
:position="device"></xf-camera>
|
||||
<image v-if="imagePath" mode="aspectFit" :src="imagePath"></image>
|
||||
</view>
|
||||
<!-- #ifdef APP -->
|
||||
</scroll-view>
|
||||
<!-- #endif -->
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {
|
||||
//createCameraContext,
|
||||
stopCameraFrame,
|
||||
startCameraFrame,
|
||||
onCameraFrameListener,
|
||||
takePhoto,
|
||||
startRecord,
|
||||
stopRecord,
|
||||
setZoom,
|
||||
TakePhotoOption,
|
||||
TakePhotoSuccessCallbackResult,
|
||||
CameraContextSetZoomOption,
|
||||
SetZoomSuccessCallbackResult,
|
||||
CameraContextStartRecordOption,
|
||||
GeneralCallbackResult,
|
||||
CameraContextStopRecordOption,
|
||||
StopRecordSuccessCallbackResult,
|
||||
OnCameraFrameCallbackResult,
|
||||
CameraFrameListenerStartOption,
|
||||
StopOption,
|
||||
OnCameraFrameListenerOption
|
||||
} from '@/uni_modules/XF-cameraUTS'
|
||||
|
||||
// 相机错误处理
|
||||
const onError = (e : any) => {
|
||||
console.log('相机错误:', e)
|
||||
// 可在此添加用户提示,如 uni.showToast
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.logo {
|
||||
height: 100px;
|
||||
width: 100px;
|
||||
margin: 100px auto 25px auto;
|
||||
}
|
||||
|
||||
.title {
|
||||
font-size: 18px;
|
||||
color: #8f8f94;
|
||||
text-align: center;
|
||||
}
|
||||
// import {
|
||||
// startVideo,
|
||||
// StartVideoOption
|
||||
// } from "@/uni_modules/XF-ijkplayerUTS";
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
yanse: "red",
|
||||
widthNum: 750,
|
||||
heightNum: 200,
|
||||
|
||||
flash: "on",
|
||||
device: "front",
|
||||
imagePath: "",
|
||||
videoPath: "https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/2minute-demo.mp4"
|
||||
}
|
||||
},
|
||||
onLoad() {
|
||||
|
||||
},
|
||||
methods: {
|
||||
onError(res : any) {
|
||||
console.log(res)
|
||||
},
|
||||
_toggleFlash() {
|
||||
this.flash = this.flash == 'on' ? 'off' : 'on'
|
||||
console.log(this.flash)
|
||||
},
|
||||
_toggledevice() {
|
||||
this.device = this.device == 'back' ? 'front' : 'back'
|
||||
console.log(this.device)
|
||||
|
||||
},
|
||||
_takePhoto() {
|
||||
takePhoto({
|
||||
success: (res : TakePhotoSuccessCallbackResult) => {
|
||||
console.log('takePhoto', res)
|
||||
this.imagePath = res.tempImagePath;
|
||||
// _previewImage();
|
||||
},
|
||||
fail: (res : GeneralCallbackResult) => {
|
||||
console.log('takePhoto', res)
|
||||
}
|
||||
} as TakePhotoOption)
|
||||
},
|
||||
// _previewImage() {
|
||||
// console.log('previewImage')
|
||||
// // uni.previewImage({
|
||||
// // urls: [this.imagePath],
|
||||
// // complete(e : any) {
|
||||
// // console.log(JSON.stringify(e))
|
||||
// // }
|
||||
// // });
|
||||
// uni.previewImage({
|
||||
// urls: ["https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/uni@2x.png"],
|
||||
// current: 0,
|
||||
// indicator: "number",
|
||||
// loop: true,
|
||||
// complete(e : any) {
|
||||
// console.log(JSON.stringify(e))
|
||||
// }
|
||||
// } as PreviewImageOptions)
|
||||
// },
|
||||
_setZoom() {
|
||||
setZoom({
|
||||
zoom: Math.random() * 10,
|
||||
success: (res : SetZoomSuccessCallbackResult) => {
|
||||
console.log('setZoom', res.errMsg, res.zoom)
|
||||
},
|
||||
complete: (res : GeneralCallbackResult) => {
|
||||
console.log('setZoom', res)
|
||||
},
|
||||
} as CameraContextSetZoomOption)
|
||||
},
|
||||
_startRecord() {
|
||||
startRecord({
|
||||
success(res : GeneralCallbackResult) {
|
||||
console.log('startRecord', res)
|
||||
},
|
||||
complete(res : GeneralCallbackResult) {
|
||||
console.log('startRecord', res)
|
||||
},
|
||||
} as CameraContextStartRecordOption)
|
||||
},
|
||||
_stopRecord() {
|
||||
let that = this;
|
||||
stopRecord({
|
||||
success(result : StopRecordSuccessCallbackResult) {
|
||||
console.log('stopRecord', result.tempVideoPath)
|
||||
that.videoPath = result.tempVideoPath;
|
||||
|
||||
// startVideo({
|
||||
// url: result.tempVideoPath,
|
||||
// isAutoPlay: true,
|
||||
// isLive: false,
|
||||
// //headers: { "key1": 1, "key2": 2 },
|
||||
// // options: { "op1": 1, "op2": 2 },
|
||||
// success: (res) => {
|
||||
// console.log(res)
|
||||
// }
|
||||
// } as StartVideoOption);
|
||||
}
|
||||
} as CameraContextStopRecordOption)
|
||||
},
|
||||
_addFrameCallback() {
|
||||
onCameraFrameListener({
|
||||
success: (res : OnCameraFrameCallbackResult) => {
|
||||
console.log('onCameraFrame', res)
|
||||
}
|
||||
} as OnCameraFrameListenerOption)
|
||||
},
|
||||
_startFrame() {
|
||||
startCameraFrame({
|
||||
success: (res : GeneralCallbackResult) => {
|
||||
console.log('startCameraFrame', res)
|
||||
}
|
||||
} as CameraFrameListenerStartOption)
|
||||
},
|
||||
_stopFrame() {
|
||||
stopCameraFrame({
|
||||
success: (res : GeneralCallbackResult) => {
|
||||
console.log('stopCameraFrame', res)
|
||||
}
|
||||
} as StopOption)
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.video {
|
||||
width: 100%;
|
||||
height: 200px;
|
||||
}
|
||||
</style>
|
||||
@@ -1,2 +0,0 @@
|
||||
## 1.0.0
|
||||
初始化发布
|
||||
@@ -1,52 +0,0 @@
|
||||
# **概述**
|
||||
|
||||
Skin-cameraUTS封装了Android和iOS自定义相机预览的功能。
|
||||
|
||||
## **模块调用**
|
||||
|
||||
```js
|
||||
<xf-camera style="height:750rpx; background-color: red;" @ready="ready" @error="onError" @stop="stop" :flash="flash" :position="device">
|
||||
</xf-camera>
|
||||
```
|
||||
|
||||
## 参数说明:
|
||||
|
||||
position:
|
||||
|
||||
- 类型:字符串型
|
||||
- 描述:(可选项)前置或者后置相机。(front前置 |back 后置)
|
||||
|
||||
flash:
|
||||
|
||||
- 类型:字符串型
|
||||
- 描述:(可选项)是否开启闪光灯。( auto, on, off, torch)
|
||||
|
||||
|
||||
## **插件接口**
|
||||
|
||||
<div id="a0"></div>
|
||||
|
||||
# **takePhoto**
|
||||
|
||||
拍照
|
||||
|
||||
|
||||
## uni-app x项目(uvue)中调用示例:
|
||||
|
||||
```js
|
||||
import { takePhoto } from "@/uni_modules/Skin-cameraUTS";
|
||||
import { TakePhotoOption, TakePhotoSuccessCallbackResult } from "@/uni_modules/Skin-cameraUTS/utssdk/interface.uts";
|
||||
|
||||
let options = {
|
||||
success: (res : TakePhotoSuccessCallbackResult) => {
|
||||
console.log(res)
|
||||
}
|
||||
} as TakePhotoOption;
|
||||
takePhoto(options);
|
||||
```
|
||||
|
||||
## 可用性
|
||||
|
||||
iOS、Android系统
|
||||
|
||||
可提供的1.0.0及更高版本
|
||||
@@ -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)
|
||||
初始化发布
|
||||
@@ -1,8 +1,8 @@
|
||||
{
|
||||
"id": "Skin-cameraUTS",
|
||||
"id": "XF-cameraUTS",
|
||||
"displayName": "UTS实现自定义相机拍照和录像功能",
|
||||
"version": "1.0.0",
|
||||
"description": "封装了Android和iOS自定义相机预览的功能。",
|
||||
"version": "1.1.1",
|
||||
"description": "XF-cameraUTS封装了Android和iOS自定义相机预览的功能。",
|
||||
"keywords": [
|
||||
"相机",
|
||||
"录像",
|
||||
@@ -18,7 +18,7 @@
|
||||
"type": "component-uts",
|
||||
"sale": {
|
||||
"regular": {
|
||||
"price": "0.00"
|
||||
"price": "168.00"
|
||||
},
|
||||
"sourcecode": {
|
||||
"price": "0.00"
|
||||
@@ -0,0 +1,183 @@
|
||||
# **概述**
|
||||
|
||||
XF-cameraUTS封装了Android和iOS自定义相机预览的功能。
|
||||
|
||||
## **模块调用**
|
||||
|
||||
```js
|
||||
<xf-camera style="height:750rpx; background-color: red;" @ready="ready" @error="onError" @stop="stop" :flash="flash" :position="device">
|
||||
</xf-camera>
|
||||
```
|
||||
|
||||
## 参数说明:
|
||||
|
||||
position:
|
||||
|
||||
- 类型:字符串型
|
||||
- 描述:(可选项)前置或者后置相机。(front前置 |back 后置)
|
||||
|
||||
flash:
|
||||
|
||||
- 类型:字符串型
|
||||
- 描述:(可选项)是否开启闪光灯。( auto, on, off, torch)
|
||||
|
||||
|
||||
## **插件接口**
|
||||
|
||||
<div id="a0"></div>
|
||||
|
||||
# **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及更高版本
|
||||
|
||||
|
||||
<div id="a1"></div>
|
||||
|
||||
# **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及更高版本
|
||||
|
||||
|
||||
|
||||
<div id="a2"></div>
|
||||
|
||||
# **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及更高版本
|
||||
|
||||
|
||||
<div id="a3"></div>
|
||||
|
||||
# **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及更高版本
|
||||
Reference in New Issue
Block a user