概述
uni-app实现微信相机
在微信小程序中直接使用uni.chooseMedia即可调用微信相机进行摄录。但为了保持体验的相似性,造一个微信相机的轮子是有必要的
因为小程序的胶囊很碍事,所以对UI进行了调整,功能按钮均移动到页面下方。
本相机支持照片及视频的摄录,拍摄后可进行预览、重拍。采用页面栈的形式进行传值。
-
使用例:ClockIn.vue(记得先在pages.json中注册)
<template> <view> <button @click="doCapture">点击摄录</button> <image v-if="photoSrc" :src="photoSrc"></image> </view> <script> export default { data() { return { photoSrc: "" } }, methods: { doCapture(){ uni.navigateTo({ url: '/pages/TakePhotoAndVideo?dest=photoSrc' }) } } } </script> </template>
-
源代码:TakePhotoAndVideo.vue
<template>
<view class="complex-camera">
<video v-if="videoSrc" :src="videoSrc" style="width: 100vw; height:100vh;z-index: 9800;" autoplay="true" loop="true"
:controls="false" object-fit="cover">
<!-- 其它功能按钮,视频预览用 -->
<cover-image :src="backIcon" class="complex-camera-back" @click="goBack"></cover-image>
<cover-image :src="confirmIcon" class="complex-camera-previewer-success" @click="save"></cover-image>
</video>
<camera v-else device-position="back" @error="bindError" style="width: 100%; height:100vh;">
<cover-view style="height:100vh;">
<!-- 其它功能按钮 -->
<cover-image :src="backIcon" class="complex-camera-back" @click="goBack"></cover-image>
<cover-image :src="confirmIcon" class="complex-camera-previewer-success" v-if="photoSrc" @click="save">
</cover-image>
<!-- 预览 -->
<cover-image :src="photoSrc" v-if="photoSrc" style="width: 100vw; height:100vh;z-index: 9800;" />
<!-- 拍摄功能按钮 -->
<cover-view v-if="!photoSrc"
:class="[recordStartTime==0?'complex-camera-btn-text':'complex-camera-btn-recording-text']">
{{hintText}}
</cover-view>
<cover-image v-if="!photoSrc" :src="cameraIcon" @touchstart="handleTouchShutter" @touchend="handleTouchShutter"
@longpress="handleTouchShutter" class="complex-camera-btn" />
</cover-view>
</camera>
</view>
</template>
<script>
let recorderManager = uni.getRecorderManager();
let innerAudioContext = uni.createInnerAudioContext('myAudio');
innerAudioContext.autoplay = true;
let cameraCtx; //相机上下文
export default {
data() {
return {
dest: '', //上一页的目标data
windowHeight: '',
touchStartTime: 0,
recordStartTime: 0, //开始录制时的时间戳
photoSrc: '',
videoSrc: '',
backIcon: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAACXBIWXMAACNfAAAjXwHuwDalAAAGkmlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPD94cGFja2V0IGJlZ2luPSLvu78iIGlkPSJXNU0wTXBDZWhpSHpyZVN6TlRjemtjOWQiPz4gPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iQWRvYmUgWE1QIENvcmUgNy4xLWMwMDAgNzkuZWRhMmIzZmFjLCAyMDIxLzExLzE3LTE3OjIzOjE5ICAgICAgICAiPiA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPiA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtbG5zOmRjPSJodHRwOi8vcHVybC5vcmcvZGMvZWxlbWVudHMvMS4xLyIgeG1sbnM6cGhvdG9zaG9wPSJodHRwOi8vbnMuYWRvYmUuY29tL3Bob3Rvc2hvcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RFdnQ9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZUV2ZW50IyIgeG1wOkNyZWF0b3JUb29sPSJBZG9iZSBQaG90b3Nob3AgMjMuMSAoTWFjaW50b3NoKSIgeG1wOkNyZWF0ZURhdGU9IjIwMjItMDgtMDFUMTY6NTc6MjkrMDg6MDAiIHhtcDpNb2RpZnlEYXRlPSIyMDIyLTA4LTAxVDE3OjE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amJY2Ra1C2ADYnqX3tDXI3HnrW8b/auU5AD7lFDpW3xImYliHzJT+5VP49U/6vTn53gPxtR6KXR8a1nTGbTvvQ28BWWV//EACsAPby9IlGvm1+nvJ4t8KUvu8oVlmEi3k28LGnGM1O+NhScgA2v6H6fDudiocexgFYNX7XwczKIt2SBwCbV9RN9Rjs9cBTmDUqeQPvWMyyBp8zOW+Rwsq2UgKweeXb2BTePt8EzswBeL2wb5cWR2MTpHrKCsDm3oAjSEcTMRUzHQI63wMxlS5pTRn+Oeu33bwB2Gy3pZiPW4apmLka2DuDc9tb0jLjcS/YjaNbQ77GFTm5JaW9i3qjTP4PBnrKt+P2Hs9he/HZU44xgfRrFhfn4ZEjLw/k+wDPFnGKbKmkcyZi1l7cA1ws86XVmHq5KmAXsSr5WbX8zsXyN8+Ij3m41+e5qC6jb/WSBXDDW/K6AAoHVsssyXKxVYTRUH0t8Mc8XdM85sW6AO+j2lgzKbwbvQLo0SoxWws0KHc0yHNlmzxey7zPErTHfpemUtJDEoPcXsO8A9hsZ2Lq6spF04nefFoBzMB6YEqpSlXPyTmWzDUrNQCbrbukIlaWAHQrJJ1zSileq1IFcMP1wVeRz50362XsB5XyNSp1ADcseq3BtDILeeelOTLGGuzWAiuAObK2mJZjg2WWojFD4JbLGAbLLErbcrse5QhgS+uU+2A6Tk3CLH5flQJsTZg1v5Mwnbz6yLHLOv4K4KbWDrMW5DTgl8DvMYWhr2JWs82Q2/gXkgRukH/Plf+bLL/7lPxtf/HVkSK0O1MA1dQUQDUFUE1NAVRTANXUFEA1BVBNTQFUUwDV1BRANQVQTU0BVFMA1RRANTUFUE0BVFMrtv0XTlSAriBEObUAAAAASUVORK5CYII=",
}
},
computed: {
hintText() {
if (this.recordStartTime === 0) {
return "轻触拍照,长按录像";
} else {
return "录像中"
}
}
},
onLoad(e) {
this.dest = e.dest;
cameraCtx = uni.createCameraContext(); //初始化相机上下文
},
methods: {
handleTouchShutter(e) {
switch (e.type) {
case "touchstart":
this.touchStartTime = e.timeStamp;
break;
case "longpress":
this.recordStartTime = new Date().getTime();
//开始视频录制
this.takeVideo();
break;
case "touchend":
const touchTime = e.timeStamp - this.touchStartTime; //单位ms
if (touchTime > 350 || this.recordStartTime != 0) {
//结束视频录制
uni.showLoading({
title: '保存中',
mask: true,
success: () => {
cameraCtx.stopRecord({
// 视频压缩经常出问题
// compressed: true,
success: (res) => {
this.stopRecordVideo(res);
},
complete: (res) => {
uni.hideLoading();
}
})
}
})
} else {
//拍照
this.takePhoto();
}
break;
}
},
takePhoto() {
this.photoSrc = "";
this.videoSrc = "";
cameraCtx.takePhoto({
quality: 'low',
success: (res) => {
let photoSrc = res.tempImagePath;
//图片压缩则交换注释
this.photoSrc = photoSrc;
// uni.compressImage({
// src: photoSrc, // 图片路径
// quality: 50, // 压缩质量
// success: (response) => {
// this.photoSrc = response.tempFilePath;
// }
// })
}
});
},
takeVideo() {
//开始录像
this.photoSrc = "";
this.videoSrc = "";
cameraCtx.startRecord({
timeoutCallback: (cb) => {
uni.showLoading({
title: '保存中',
mask: true,
success: (res) => {
this.stopRecordVideo(cb)
}
})
},
success: (res) => {
console.log("开始录像", new Date())
},
fail: (err) => {
console.log(err)
},
})
},
stopRecordVideo(res) {
uni.hideLoading();
this.recordStartTime = 0;
const {
tempThumbPath,
tempVideoPath
} = res;
this.videoSrc = tempVideoPath;
},
goBack() {
if (this.photoSrc || this.videoSrc) {
this.photoSrc = "";
this.videoSrc = "";
this.touchStartTime = 0;
this.recordStartTime = 0;
} else {
uni.navigateBack()
}
},
save() {
let pages = getCurrentPages();
let prevPage = pages[pages.length - 2];
prevPage.$vm[this.dest] = this.videoSrc || this.photoSrc;
if (this.btn) {
prevPage.$vm[this.btn] = false;
}
uni.navigateBack();
},
bindError(e) {
let _this = this;
uni.showModal({
title: '提示',
content: '请允许摄像头授权',
showCancel: false,
success: function(res) {
if (res.confirm) {
uni.openSetting({
success(res) {
if (res.authSetting['scope.camera']) {
uni.navigateBack()
}
}
})
}
}
});
},
},
onUnload() {
recorderManager = null;
innerAudioContext = null;
cameraCtx = null;
}
}
</script>
<style>
page {
padding-bottom: 0;
}
</style>
<style lang="scss" scoped>
$btn-bottom: 100rpx;
.complex-camera-btn-text {
color: white;
position: absolute;
left: 260rpx;
bottom: $btn-bottom+170rpx;
}
.complex-camera-btn-recording-text {
color: red;
position: absolute;
left: 330rpx;
bottom: $btn-bottom+170rpx;
}
.complex-camera-btn {
z-index: 9000;
position: absolute;
width: 160rpx;
height: 160rpx;
left: 295rpx;
bottom: $btn-bottom;
}
// 返回按钮
.complex-camera-back {
position: absolute;
left: 50rpx;
bottom: $btn-bottom+56rpx;
z-index: 9990;
width: 48rpx;
height: 48rpx;
}
//完成按钮
.complex-camera-previewer-success {
position: absolute;
right: 50rpx;
bottom: $btn-bottom+56rpx;
z-index: 9990;
width: 48rpx;
height: 48rpx;
}
</style>
最后
以上就是闪闪御姐为你收集整理的uni-app实现微信相机uni-app实现微信相机的全部内容,希望文章能够帮你解决uni-app实现微信相机uni-app实现微信相机所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复