|
@@ -19,6 +19,7 @@ const bottomTips = {
|
|
|
let T: number = 0;
|
|
|
let notify = ""
|
|
|
const daoJiShi: number = 15;
|
|
|
+let isOver = false;
|
|
|
Page({
|
|
|
|
|
|
/**
|
|
@@ -26,14 +27,9 @@ Page({
|
|
|
*/
|
|
|
data: {
|
|
|
isStartVideo: false, // 是否点击开始按钮
|
|
|
- isEmpower: false, // 是否授权
|
|
|
- isUpLoad: false, // 是否上传中
|
|
|
- initFace: false, // 是否初始化人脸识别
|
|
|
- isTranscribe: false, // 是否录制中
|
|
|
seconds: 0, // 倒计
|
|
|
topTips: topTips.ready, // 提示语句
|
|
|
- bottomTips: "", // 底部提示语句
|
|
|
- buttomText: "录制"
|
|
|
+ bottomTips: "" // 底部提示语句
|
|
|
},
|
|
|
|
|
|
// 开始初始化录制
|
|
@@ -46,74 +42,79 @@ Page({
|
|
|
isStartVideo: true
|
|
|
})
|
|
|
wx.nextTick(() => {
|
|
|
- this.getMssage().then(async (r: any) => {
|
|
|
- console.log('是否授权发送消息:', r);
|
|
|
- notify = r;
|
|
|
- if (!ctx) ctx = wx.createCameraContext();
|
|
|
- this.createVK();
|
|
|
- ctx.startRecord({
|
|
|
- timeout: daoJiShi, // 录制时长
|
|
|
- selfieMirror: false,
|
|
|
- timeoutCallback: (res) => {
|
|
|
- // 超出录制时长 关闭录屏
|
|
|
- this.setData({
|
|
|
- isStartVideo: false,
|
|
|
- bottomTips: "",
|
|
|
- topTips: topTips.ready, // 提示语句
|
|
|
+ app.getPageInfo({
|
|
|
+ success: (res: any) => {
|
|
|
+ const configPage = res || {};
|
|
|
+ this.getMssage(configPage).then(async (r: any) => {
|
|
|
+ console.log('是否授权发送消息:', r);
|
|
|
+ notify = r;
|
|
|
+ ctx = wx.createCameraContext();
|
|
|
+ this.createVK();
|
|
|
+ this.addListen();
|
|
|
+ ctx.startRecord({
|
|
|
+ timeout: daoJiShi, // 录制时长
|
|
|
+ selfieMirror: false,
|
|
|
+ timeoutCallback: (res) => {
|
|
|
+ // 超出录制时长 关闭录屏
|
|
|
+ if(this.data.seconds) return
|
|
|
+ this.setData({
|
|
|
+ isStartVideo: false,
|
|
|
+ bottomTips: "",
|
|
|
+ topTips: topTips.ready, // 提示语句
|
|
|
+ })
|
|
|
+ createVKSession?.stop();
|
|
|
+ listener?.stop();
|
|
|
+ this.getUrl(res);
|
|
|
+ },
|
|
|
+ success: () => {
|
|
|
+ // 调用成功,开始录制
|
|
|
+ wx.hideLoading();
|
|
|
+ this.setData({
|
|
|
+ seconds: daoJiShi,
|
|
|
+ bottomTips: bottomTips.recording,
|
|
|
+ topTips: topTips.front
|
|
|
+ });
|
|
|
+ innerAudioContext.src = "assets/voice/front.mp3";
|
|
|
+ innerAudioContext?.play();
|
|
|
+ },
|
|
|
+ fail: () => {
|
|
|
+ // 调用失败
|
|
|
+ wx.hideLoading();
|
|
|
+ this.overVideo();
|
|
|
+ wx.showToast({
|
|
|
+ icon: "none",
|
|
|
+ title: "相机调用失败",
|
|
|
+ duration: 2000
|
|
|
+ })
|
|
|
+ }
|
|
|
})
|
|
|
- createVKSession?.stop();
|
|
|
- listener?.stop();
|
|
|
- this.getUrl(res);
|
|
|
- },
|
|
|
- success: () => {
|
|
|
- // 调用成功,开始录制
|
|
|
- wx.hideLoading();
|
|
|
- this.setData({
|
|
|
- seconds: daoJiShi,
|
|
|
- bottomTips: bottomTips.recording,
|
|
|
- topTips: topTips.front
|
|
|
- });
|
|
|
- innerAudioContext.src = "assets/voice/front.mp3";
|
|
|
- innerAudioContext.play();
|
|
|
- },
|
|
|
- fail: () => {
|
|
|
- // 调用失败
|
|
|
- wx.hideLoading();
|
|
|
- wx.showToast({
|
|
|
- icon: "none",
|
|
|
- title: "相机调用失败",
|
|
|
- duration: 2000
|
|
|
- })
|
|
|
- },
|
|
|
- complete: () => { }
|
|
|
- })
|
|
|
- });
|
|
|
+ });
|
|
|
+ }
|
|
|
+ })
|
|
|
})
|
|
|
},
|
|
|
// 添加监听
|
|
|
addListen() {
|
|
|
- createVKSession?.start(() => { });
|
|
|
T = Date.now();
|
|
|
- !listener && (listener = ctx?.onCameraFrame((frame: any) => {
|
|
|
+ listener = ctx?.onCameraFrame((frame: any) => {
|
|
|
const Time = daoJiShi * 1000 - (Date.now() - T);
|
|
|
if (Time % 1000 >= 50) return
|
|
|
- const s = Math.floor(Time / 1000);
|
|
|
- if (s == 10) {
|
|
|
+ const upData: {
|
|
|
+ seconds: number,
|
|
|
+ topTips?: string
|
|
|
+ } = {
|
|
|
+ seconds: Math.floor(Time / 1000)
|
|
|
+ }
|
|
|
+ if (upData.seconds == 10) {
|
|
|
innerAudioContext.src = "assets/voice/left.mp3";
|
|
|
- this.setData({
|
|
|
- topTips: topTips.left
|
|
|
- })
|
|
|
+ upData.topTips = topTips.left;
|
|
|
}
|
|
|
- if (s == 5) {
|
|
|
+ if (upData.seconds == 5) {
|
|
|
innerAudioContext.src = "assets/voice/right.mp3";
|
|
|
- this.setData({
|
|
|
- topTips: topTips.right
|
|
|
- })
|
|
|
+ upData.topTips = topTips.right;
|
|
|
}
|
|
|
- if (s % 5 === 0 && s !== 0) innerAudioContext.play();
|
|
|
- this.setData({
|
|
|
- seconds: s
|
|
|
- })
|
|
|
+ if (upData.seconds % 5 === 0 && upData.seconds !== 0) innerAudioContext?.play();
|
|
|
+ this.setData(upData)
|
|
|
|
|
|
// 识别人脸是否在画面种
|
|
|
createVKSession?.detectFace({
|
|
@@ -123,14 +124,13 @@ Page({
|
|
|
scoreThreshold: 0.5, // 评分阈值
|
|
|
sourceType: 1
|
|
|
})
|
|
|
- }));
|
|
|
+ });
|
|
|
listener?.start();
|
|
|
},
|
|
|
// 创建人脸追踪
|
|
|
createVK() {
|
|
|
// 初始化人脸识别
|
|
|
- if (this.data.initFace) return this.addListen();
|
|
|
- if (!createVKSession) createVKSession = wx.createVKSession({
|
|
|
+ createVKSession = wx.createVKSession({
|
|
|
version: "v1",
|
|
|
track: {
|
|
|
plane: {
|
|
@@ -140,13 +140,13 @@ Page({
|
|
|
},
|
|
|
})
|
|
|
// 静态图片检测模式下,每调一次 detectFace 接口就会触发一次 updateAnchors 事件
|
|
|
- createVKSession?.on('updateAnchors', (anchors)=> {
|
|
|
+ createVKSession?.on('updateAnchors', (anchors) => {
|
|
|
for (let I = 0; I < anchors.length; I++) {
|
|
|
const anchor = anchors[I];
|
|
|
const W = anchor.size.width * 100;
|
|
|
let titlet = "";
|
|
|
- if(W < 20 || W > 80 ) titlet = "请远离屏幕"
|
|
|
- if(W < 20) titlet = "请靠近屏幕"
|
|
|
+ if (W < 20 || W > 80) titlet = "请远离屏幕"
|
|
|
+ if (W < 20) titlet = "请靠近屏幕"
|
|
|
titlet && wx.showToast({
|
|
|
icon: "none",
|
|
|
title: titlet
|
|
@@ -160,16 +160,28 @@ Page({
|
|
|
});
|
|
|
this.overVideo();
|
|
|
})
|
|
|
- this.addListen();
|
|
|
+ createVKSession?.start(() => { });
|
|
|
},
|
|
|
// 结束录像
|
|
|
overVideo() {
|
|
|
- if (!ctx || !this.data.isStartVideo) return;
|
|
|
- ctx.stopRecord({
|
|
|
+ if (isOver) return;
|
|
|
+ isOver = true;
|
|
|
+ ctx?.stopRecord({
|
|
|
compressed: true,
|
|
|
- complete: () => {
|
|
|
- createVKSession?.stop();
|
|
|
- innerAudioContext?.pause();
|
|
|
+ success: () => {
|
|
|
+ ctx = undefined;
|
|
|
+ isOver = false;
|
|
|
+ listener?.stop();
|
|
|
+ this.setData({
|
|
|
+ isStartVideo: false,
|
|
|
+ bottomTips: "",
|
|
|
+ topTips: topTips.ready,
|
|
|
+ seconds: 0
|
|
|
+ })
|
|
|
+ },
|
|
|
+ fail: () => {
|
|
|
+ ctx = undefined;
|
|
|
+ isOver = false;
|
|
|
listener?.stop();
|
|
|
this.setData({
|
|
|
isStartVideo: false,
|
|
@@ -179,12 +191,12 @@ Page({
|
|
|
})
|
|
|
}
|
|
|
})
|
|
|
+ createVKSession?.stop();
|
|
|
+ innerAudioContext?.pause();
|
|
|
+ innerAudioContext?.destroy();
|
|
|
},
|
|
|
// 获取本地临时地址
|
|
|
getUrl(res: WechatMiniprogram.StartRecordTimeoutCallbackResult) {
|
|
|
- this.setData({
|
|
|
- isUpLoad: true
|
|
|
- })
|
|
|
wx.showLoading({
|
|
|
title: '上传进度:0%',
|
|
|
mask: true //是否显示透明蒙层,防止触摸穿透
|
|
@@ -230,9 +242,6 @@ Page({
|
|
|
})
|
|
|
},
|
|
|
complete: () => {
|
|
|
- this.setData({
|
|
|
- isUpLoad: false
|
|
|
- })
|
|
|
}
|
|
|
})
|
|
|
//监听上传进度变化事件
|
|
@@ -245,6 +254,7 @@ Page({
|
|
|
},
|
|
|
// 非正常中止
|
|
|
improperStop() {
|
|
|
+ this.overVideo();
|
|
|
wx.navigateBack();
|
|
|
},
|
|
|
// 未授权
|
|
@@ -252,19 +262,20 @@ Page({
|
|
|
wx.showToast({
|
|
|
title: "拒绝授权将无法录制视频信息"
|
|
|
});
|
|
|
+ this.overVideo();
|
|
|
wx.navigateBack();
|
|
|
},
|
|
|
// 初始化完成
|
|
|
initialization() { },
|
|
|
// 获取消息授权
|
|
|
- getMssage() {
|
|
|
+ getMssage(configPage: any) {
|
|
|
return new Promise((resolve) => {
|
|
|
- if (!app.globalData.configPage?.messageID || !wx.canIUse("requestSubscribeMessage")) {
|
|
|
+ if (!configPage.messageID || !wx.canIUse("requestSubscribeMessage")) {
|
|
|
resolve("reject");
|
|
|
return
|
|
|
}
|
|
|
wx.requestSubscribeMessage({
|
|
|
- tmplIds: app.globalData.configPage?.messageID || [],
|
|
|
+ tmplIds: configPage?.messageID || [],
|
|
|
success: (res: WechatMiniprogram.RequestSubscribeMessageSuccessCallbackResult) => {
|
|
|
resolve(res.p1mpCydIQ6OtxCSa62NaSFiEkQiTsb8KPFaAs1SuKMw || 'reject');
|
|
|
},
|
|
@@ -285,9 +296,7 @@ Page({
|
|
|
/**
|
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
|
*/
|
|
|
- onReady() {
|
|
|
-
|
|
|
- },
|
|
|
+ onReady() { },
|
|
|
|
|
|
/**
|
|
|
* 生命周期函数--监听页面显示
|
|
@@ -307,7 +316,7 @@ Page({
|
|
|
* 生命周期函数--监听页面卸载
|
|
|
*/
|
|
|
onUnload() {
|
|
|
-
|
|
|
+ this.overVideo();
|
|
|
},
|
|
|
|
|
|
/**
|