瀏覽代碼

评测修改

liushengqiang 2 年之前
父節點
當前提交
bf08cfc209
共有 4 個文件被更改,包括 57 次插入15 次删除
  1. 2 2
      src/helpers/communication.ts
  2. 3 2
      src/state.ts
  3. 13 0
      src/view/audio-list/index.tsx
  4. 39 11
      src/view/evaluating/index.tsx

+ 2 - 2
src/helpers/communication.ts

@@ -71,11 +71,11 @@ export const api_proxyServiceMessage = (content: any): Promise<IPostMessage | un
 };
 /** 监听app真正开始录音 */
 export const api_recordStartTime = (callback: CallBack) => {
-	listenerMessage("sendResult", callback);
+	listenerMessage("recordStartTime", callback);
 }
 /** 卸载监听app真正开始录音 */
 export const api_remove_recordStartTime = (callback: CallBack) => {
-	removeListenerMessage("sendResult", callback);
+	removeListenerMessage("recordStartTime", callback);
 }
 
 /** 上传评测 音 视频 */

+ 3 - 2
src/state.ts

@@ -196,11 +196,12 @@ export const onPlay = () => {
 		if (state.isSelectMeasureMode) {
 			currentTime = currentTime - state.section[0].time;
 		}
-		sendEvaluatingOffsetTime(currentTime);
 	}
 };
 /** 播放中事件 */
-export const onTimeupdate = (evt: Event) => {};
+export const onTimeupdate = (evt: Event) => {
+	sendEvaluatingOffsetTime(getAudioCurrentTime())
+};
 
 /** 播放模式结束自动重播 */
 const autoResetPlay = () => {

+ 13 - 0
src/view/audio-list/index.tsx

@@ -65,6 +65,19 @@ export const setAudioCurrentTime = (time: number, index = 0) => {
 	audioData.backgroundEle && (audioData.backgroundEle.currentTime = time);
 };
 
+/** 设置当前没有播放的音频静音 */
+export const toggleMutePlayAudio = () => {
+	if(state.playSource === 'music'){
+		if (audioData.songEle) {
+			audioData.songEle.muted = !audioData.songEle.muted
+		}
+	} else if (state.playSource === 'background') {
+		if (audioData.backgroundEle) {
+			audioData.backgroundEle.muted = !audioData.backgroundEle.muted
+		}
+	}
+}
+
 export default defineComponent({
 	name: "audio-list",
 	setup() {

+ 39 - 11
src/view/evaluating/index.tsx

@@ -17,11 +17,13 @@ import {
 	api_stopRecording,
 	api_recordStartTime,
 	api_remove_recordStartTime,
+	api_videoUpdate,
 } from "/src/helpers/communication";
 import state, { clearSelection, handleStopPlay, resetPlaybackToStart, togglePlay } from "/src/state";
 import { IPostMessage } from "/src/utils/native-message";
 import { usePageVisibility } from "@vant/use";
 import { browser } from "/src/utils";
+import { toggleMutePlayAudio } from "../audio-list";
 
 const browserInfo = browser();
 export const evaluatingData = reactive({
@@ -65,8 +67,11 @@ export const handleStartEvaluat = () => {
 
 /** 开始播放发送延迟时间 */
 export const sendEvaluatingOffsetTime = async (currentTime: number) => {
+	// 没有开始时间点, 没有开始播放, 不处理
+	if (!evaluatingData.backtime || !currentTime) return;
 	const nowTime = Date.now();
-	const delayTime = nowTime - evaluatingData.backtime - currentTime * 1000;
+	const delayTime = nowTime - evaluatingData.backtime
+	evaluatingData.backtime = 0
 	console.log("真正播放延迟", delayTime);
 	await api_proxyServiceMessage({
 		header: {
@@ -183,7 +188,7 @@ export const handleStartBegin = async () => {
 	evaluatingData.backtime = 0;
 	resetPlaybackToStart();
 	try {
-		console.log("🚀 ~ content:", evaluatingData.contentData, JSON.stringify(evaluatingData.contentData));
+		// console.log("🚀 ~ content:", evaluatingData.contentData, JSON.stringify(evaluatingData.contentData));
 	} catch (error) {}
 	const res = await startEvaluating(evaluatingData.contentData);
 	if (res?.api !== "startEvaluating") {
@@ -191,24 +196,35 @@ export const handleStartBegin = async () => {
 		evaluatingData.startBegin = false;
 		return;
 	}
+	// 开始播放
+	playMusic();
 	// 开始录音
 	api_startRecording();
 };
 
-/** 录音开始,开始播放音频 */
-const recordedPlayMusic = async (res?: IPostMessage) => {
-	let inteveral = res?.content?.inteveral || 0;
-	if (browserInfo.ios) {
-		inteveral *= 1000;
-	}
-	evaluatingData.backtime = inteveral || Date.now();
+/** 播放音乐 */
+const playMusic = async () => {
+	toggleMutePlayAudio()
 	const playState = await togglePlay("play");
 	// 取消播放
 	if (!playState) {
 		evaluatingData.startBegin = false;
 		handleCancelEvaluat();
+		toggleMutePlayAudio()
 		return;
 	}
+}
+
+/** 录音开始,记录开始时间点 */
+const recordStartTimePoint = async (res?: IPostMessage) => {
+	let inteveral = res?.content?.inteveral || 0;
+	if (browserInfo.ios) {
+		inteveral *= 1000;
+	}
+	console.log("🚀 ~ 开始时间点:", inteveral)
+	evaluatingData.backtime = inteveral || Date.now();
+	toggleMutePlayAudio()
+	resetPlaybackToStart();
 };
 
 /**
@@ -232,6 +248,8 @@ export const handleEndEvaluat = (isComplete = false) => {
 		forbidClick: true,
 	});
 	evaluatingData.isComplete = isComplete;
+	// 保存视频到相册
+	saveVideoToAlbum();
 };
 
 /**
@@ -287,6 +305,16 @@ export const handleViewReport = (key: "recordId" | "recordIdStr", type: "gym" |
 		isOpenLight: true,
 	});
 };
+
+/** 保存视频到相册 */
+const saveVideoToAlbum = async () => {
+	if (state.setting.saveToAlbum && state.setting.camera){
+		const res = await api_videoUpdate()
+		console.log("保存视频到相册回调:", res)
+	}
+}
+
+
 export default defineComponent({
 	name: "evaluating",
 	setup() {
@@ -306,14 +334,14 @@ export default defineComponent({
 			evaluatingData.checkStep = 0;
 			evaluatingData.rendered = true;
 			sendResult(handleScoreResult);
-			api_recordStartTime(recordedPlayMusic);
+			api_recordStartTime(recordStartTimePoint);
 			if (!state.isSelectMeasureMode) {
 				clearSelection();
 			}
 		});
 		onUnmounted(() => {
 			removeResult(handleScoreResult);
-			api_remove_recordStartTime(recordedPlayMusic);
+			api_remove_recordStartTime(recordStartTimePoint);
 		});
 		return () => <div></div>;
 	},