瀏覽代碼

fix: midi评测问题修复

TIANYONG 1 年之前
父節點
當前提交
b174ba380e
共有 4 個文件被更改,包括 18 次插入10 次删除
  1. 5 3
      src/helpers/midiPlay.tsx
  2. 5 2
      src/state.ts
  3. 3 3
      src/view/audio-list/index.tsx
  4. 5 2
      src/view/evaluating/index.tsx

+ 5 - 3
src/helpers/midiPlay.tsx

@@ -86,10 +86,9 @@ export const changeMode = async (val: IMode, type?: string | undefined) => {
  * 切换midi播放状态
  */
 export const cloudToggleState = async (type: "play" | "paused") => {
-  console.log('api','midi状态2')
   const cloudGetMediaStatus = await api_cloudGetMediaStatus();
   const status = cloudGetMediaStatus?.content.status
-  console.log('api','midi状态3',status)
+  // console.log('api','midi状态',status)
   if (status === 'init') {
     return
   }
@@ -105,10 +104,13 @@ export const cloudToggleState = async (type: "play" | "paused") => {
     // startCapture()
     onPlay()
   } else {
-    audioData.progress = 0
     await api_cloudSuspend({
       songID: state.examSongId,
     })
+    // 如果是评测终止状态,需要重置进度s
+    if (state.modeType === "evaluating") {
+      audioData.progress = 0
+    }
     // endCapture()
   }
   const cloudGetMediaStatused = await api_cloudGetMediaStatus()

+ 5 - 2
src/state.ts

@@ -6,7 +6,7 @@ import { GradualNote, GradualTimes, GradualVersion } from "./type";
 import { handleEndEvaluat, handleStartEvaluat } from "./view/evaluating";
 import { IFingering, mappingVoicePart, subjectFingering, matchVoicePart } from "/src/view/fingering/fingering-config";
 import { handleStartTick } from "./view/tick";
-import { audioListStart, getAudioCurrentTime, getAudioDuration, setAudioCurrentTime, setAudioPlaybackRate } from "./view/audio-list";
+import { audioListStart, getAudioCurrentTime, getAudioDuration, setAudioCurrentTime, setAudioPlaybackRate, audioData } from "./view/audio-list";
 import { toggleFollow } from "./view/follow-practice";
 import { browser, setStorageSpeed, setGlobalData } from "./utils";
 import { api_cloudGetMediaStatus, api_createMusicPlayer, api_cloudChangeSpeed } from "./helpers/communication";
@@ -627,7 +627,6 @@ export const togglePlay = async (playState?: "play" | "paused") => {
       clearSelection();
     }
   }
-  console.log('api','midi状态0')
   audioListStart(state.playState);
   return true;
 };
@@ -752,6 +751,10 @@ export const getNote = (currentTime: number) => {
 
 /** 重播 */
 export const handleResetPlay = () => {
+  // 如果是midi需要重置播放进度
+  if (state.isAppPlay) {
+    audioData.progress = 0
+  }
   resetPlaybackToStart();
   // 如果是暂停, 直接播放
   togglePlay("play");

+ 3 - 3
src/view/audio-list/index.tsx

@@ -17,8 +17,8 @@ export const audioData = reactive({
 	songEle: null as unknown as HTMLAudioElement,
 	backgroundEle: null as unknown as HTMLAudioElement,
 	midiRender: false,
-	progress: 0,
-	duration: 0
+	progress: 0, // midi播放进度(单位:秒)
+	duration: 0 // 音频总时长(单位:秒)
 });
 const midiRef = ref();
 /** 播放或暂停 */
@@ -27,7 +27,7 @@ export const audioListStart = (type: "play" | "paused") => {
 	if (type === "play" && state.originSpeed !== 0) {
 		setAudioPlaybackRate(state.speed / state.originSpeed);
 	}
-	console.log('api','midi状态1',type,state.isAppPlay)
+	// console.log('api','midi状态1',type,state.isAppPlay)
 	// 如果是midi播放
 	if (state.isAppPlay) {
 		// handleTogglePlayMidi(type);

+ 5 - 2
src/view/evaluating/index.tsx

@@ -43,7 +43,7 @@ import state, {
 import { IPostMessage } from "/src/utils/native-message";
 import { usePageVisibility } from "@vant/use";
 import { browser } from "/src/utils";
-import { getAudioCurrentTime, toggleMutePlayAudio, audioListStart } from "../audio-list";
+import { getAudioCurrentTime, toggleMutePlayAudio, audioListStart, audioData } from "../audio-list";
 import { handleStartTick, tickData } from "../tick";
 import AbnormalPop from "../abnormal-pop";
 import { storeData } from "../../store";
@@ -376,7 +376,9 @@ export const handleStartBegin = async (preTimes?: number) => {
 		firstNoteTime: preTimes || 0,
 	}, () => {
 		if (state.isAppPlay) {
-			sendOffsetTime(0)
+			setTimeout(() => {
+				sendOffsetTime(0)
+			}, 300);
 		}
 	})
 	// 如果开启了摄像头, 开启录制视频
@@ -386,6 +388,7 @@ export const handleStartBegin = async (preTimes?: number) => {
 	}
 	// 如果是midi音频评测,需要调用cloudPlay
 	if (state.isAppPlay) {
+		audioData.progress = 0
 		audioListStart(state.playState);
 	}
 };