Browse Source

feat: endTune使用checkPlayEnd进行监听

TIANYONG 1 year ago
parent
commit
e0c56dc095

+ 10 - 0
src/helpers/communication.ts

@@ -321,4 +321,14 @@ export const api_onoffAccompaniment = () => {
 			state: 0,
 		},
 	});
+};
+
+
+/** 延迟检测校音,校音音频播放完成回调 */
+export const addCheckPlayEnd = (callback: CallBack) => {
+	listenerMessage("checkPlayEnd", callback);
+};
+/** 取消监听延迟检测校返回 */
+export const removeCheckPlayEnd = (callback: CallBack) => {
+	removeListenerMessage("checkPlayEnd", callback);
 };

+ 15 - 7
src/page-instrument/evaluat-model/delay-check/index.tsx

@@ -1,7 +1,7 @@
 import { Button, Popup } from "vant";
 import styles from "./index.module.less";
 import { defineComponent, onMounted, onUnmounted, reactive, ref } from "vue";
-import { api_toggleTune, getEarphone, removeResult, sendResult } from "/src/helpers/communication";
+import { api_toggleTune, getEarphone, removeResult, sendResult, addCheckPlayEnd, removeCheckPlayEnd } from "/src/helpers/communication";
 import { Vue3Lottie } from "vue3-lottie";
 import bg from "./json/bg.json";
 import bg1 from "./json/bg1.json";
@@ -94,22 +94,30 @@ export default defineComponent({
 						toggleTune("start");
 					}, 100);
 				}
-				// startTune效音通过返回后,调用endTune
-				if (header?.commond === "result") {
-					clearTimeout(data.startAbnormalTimer);
-					data.startTuneResult = true
-					toggleTune("stop");
-				}
 			}
 		};
+
+		// 监听到校音音频播放完成
+		const checkAudioPlayEnd = (res?: IPostMessage) => {
+			console.log("🚀 ~ res:校音音频", res);
+			// startTune效音通过返回后,调用endTune
+			if (res) {
+				clearTimeout(data.startAbnormalTimer);
+				data.startTuneResult = true
+				toggleTune("stop");
+			}
+		}
+
 		onMounted(() => {
 			data.show = true;
 			sendResult(listenerResult);
+			addCheckPlayEnd(checkAudioPlayEnd);
 			keepCheckEarphone();
 		});
 		onUnmounted(() => {
 			data.show = false;
 			removeResult(listenerResult);
+			removeCheckPlayEnd(checkAudioPlayEnd);
 		});
 
 		const handleStartTune = async () => {