Ver código fonte

录制视频,退到后台停止播放,并结束评测

liushengqiang 1 ano atrás
pai
commit
c764588058

+ 19 - 0
src/helpers/communication.ts

@@ -183,3 +183,22 @@ export const api_setCache = (content: any) => {
 		content,
 	});
 };
+
+/** app切换到后台 */
+export const api_suspendPlay = (callback: CallBack) => {
+	listenerMessage("suspendPlay", callback);
+}
+
+/** 开始录制视频 */
+export const api_startCapture = () => {
+	postMessage({
+		api: 'startCapture'
+	})
+}
+
+/** 结束录制视频 */
+export const api_endCapture = () => {
+	postMessage({
+		api: 'endCapture'
+	})
+}

+ 1 - 1
src/page-orchestra/detail/index.tsx

@@ -11,7 +11,7 @@ import { sysMusicScoreAccompanimentQueryPage } from "../api";
 import EvaluatModel from "../evaluat-model";
 import HeaderTop from "../header-top";
 import styles from "./index.module.less";
-import { api_cloudLoading, api_openCamera, api_setStatusBarVisibility, isSpecialShapedScreen } from "/src/helpers/communication";
+import { api_cloudLoading, api_openCamera, api_setStatusBarVisibility, api_suspendPlay, isSpecialShapedScreen } from "/src/helpers/communication";
 import { getQuery } from "/src/utils/queryString";
 import Evaluating, { evaluatingData } from "/src/view/evaluating";
 import MeasureSpeed from "/src/view/plugins/measure-speed";

+ 12 - 2
src/page-orchestra/header-top/index.tsx

@@ -6,13 +6,13 @@ import icons from "./image/headerTop.json";
 import { Badge, Circle, Popover, Popup } from "vant";
 import { metronomeData } from "../../helpers/metronome";
 import Speed from "./speed";
-import { handleStartEvaluat } from "/src/view/evaluating";
+import { handleEndBegin, handleStartEvaluat } from "/src/view/evaluating";
 import Settting from "./settting";
 import ModeTypeMode from "./mode-type-mode";
 import state, { handleChangeSection, handleResetPlay, handleRessetState, togglePlay } from "/src/state";
 import { getAudioCurrentTime } from "/src/view/audio-list";
 import { toggleFollow } from "/src/view/follow-practice";
-import { api_back } from "/src/helpers/communication";
+import { api_back, api_suspendPlay } from "/src/helpers/communication";
 import MusicType from "./music-type";
 import { handleNoEndExit } from "../custom-plugins/recording-time";
 
@@ -75,6 +75,16 @@ export default defineComponent({
 			api_back();
 		};
 
+		onMounted(() => {
+			api_suspendPlay(() => {
+				if (state.modeType === 'practise') {
+					togglePlay('paused')
+				} else if (state.modeType === 'evaluating'){
+					handleEndBegin()
+				}
+			})
+		})
+
 		return () => (
 			<div ref={headRef} class={styles.headerTop}>
 				<div class={styles.back} onClick={handleBack}>

+ 12 - 1
src/view/evaluating/index.tsx

@@ -18,6 +18,8 @@ import {
 	api_recordStartTime,
 	api_remove_recordStartTime,
 	api_videoUpdate,
+	api_startCapture,
+	api_endCapture,
 } from "/src/helpers/communication";
 import state, { clearSelection, handleStopPlay, resetPlaybackToStart, togglePlay } from "/src/state";
 import { IPostMessage } from "/src/utils/native-message";
@@ -213,6 +215,11 @@ const playMusic = async () => {
 		toggleMutePlayAudio()
 		return;
 	}
+	// 如果开启了摄像头, 开启录制视频
+	if (state.setting.camera && state.setting.saveToAlbum){
+		console.log('开始录制视频')
+		api_startCapture()
+	}
 }
 
 /** 录音开始,记录开始时间点 */
@@ -248,11 +255,15 @@ export const handleEndEvaluat = (isComplete = false) => {
 		forbidClick: true,
 	});
 	evaluatingData.isComplete = isComplete;
+	// 如果开启了摄像头, 结束录制视频
+	if (state.setting.camera && state.setting.saveToAlbum){
+		console.log('结束录制视频')
+		api_endCapture()
+	}
 };
 
 /**
  * 结束评测
- * @param isEnd 是否是自动播放停止, 默认: false
  */
 export const handleEndBegin = () => {
 	handleEndEvaluat();