liushengqiang 2 years ago
parent
commit
e802c0cff3
2 changed files with 17 additions and 17 deletions
  1. 3 1
      src/view/audio-list/index.tsx
  2. 14 16
      src/view/evaluating/index.tsx

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

@@ -42,7 +42,9 @@ export const getAudioCurrentTime = () => {
 		const c = getMidiCurrentTime();
 		return c;
 	}
-	return audioData.songEle?.currentTime || audioData.backgroundEle?.currentTime || 0;
+	if (state.playSource === 'music') return audioData.songEle?.currentTime
+	if (state.playSource === 'background') return audioData.backgroundEle?.currentTime
+	return audioData.songEle?.currentTime
 };
 /** 获取曲谱的总时间 */
 export const getAudioDuration = () => {

+ 14 - 16
src/view/evaluating/index.tsx

@@ -25,7 +25,7 @@ import state, { IPlayState, clearSelection, handleStopPlay, resetPlaybackToStart
 import { IPostMessage } from "/src/utils/native-message";
 import { usePageVisibility } from "@vant/use";
 import { browser } from "/src/utils";
-import { getAudioCurrentTime, toggleMutePlayAudio } from "../audio-list";
+import { getAudioCurrentTime, setAudioCurrentTime, toggleMutePlayAudio } from "../audio-list";
 import testAudio from './testAudio.mp3'
 
 const browserInfo = browser();
@@ -76,7 +76,7 @@ const check_currentTime = () => {
 		preTime = state.section[0].time * 1000;
 	}
 	const currentTime = getAudioCurrentTime() * 1000 - preTime;
-	console.log('播放进度music', currentTime, 'preTime:' + preTime)
+	// console.log('播放进度music', currentTime, 'preTime:' + preTime)
 
 	if (currentTime >= 500) {
 		sendEvaluatingOffsetTime(500);
@@ -93,7 +93,6 @@ export const sendEvaluatingOffsetTime = async (currentTime: number) => {
 	if (!evaluatingData.backtime) return;
 	const nowTime = Date.now();
 	const delayTime = nowTime - evaluatingData.backtime - currentTime;
-	evaluatingData.backtime = 0;
 	console.error("真正播放延迟", delayTime, "currentTime:", currentTime);
 	await api_proxyServiceMessage({
 		header: {
@@ -207,7 +206,7 @@ export const handleStartBegin = async () => {
 	evaluatingData.evaluatings = {};
 	evaluatingData.resultData = {};
 	evaluatingData.backtime = 0;
-	// resetPlaybackToStart();
+	resetPlaybackToStart();
 	try {
 		// console.log("🚀 ~ content:", evaluatingData.contentData, JSON.stringify(evaluatingData.contentData));
 	} catch (error) {}
@@ -240,7 +239,7 @@ const playMusic = async () => {
 };
 
 let _audio: HTMLAudioElement;
-let backtime = 0
+
 /** 录音开始,记录开始时间点 */
 const recordStartTimePoint = async (res?: IPostMessage) => {
 	// 没有开始评测,不处理
@@ -250,23 +249,21 @@ const recordStartTimePoint = async (res?: IPostMessage) => {
 		inteveral *= 1000;
 	}
 	evaluatingData.backtime = inteveral || Date.now();
-	backtime = evaluatingData.backtime
 	console.log("🚀 ~ 开始时间点:", evaluatingData.backtime, "已经录的时间:", Date.now() - inteveral, '记录时间点:', Date.now());
 	// 开始播放
-	_audio.play();
-	
 	playMusic();
+	// _audio.play();
 };
 
 
 const getTestCurrent = () => {
 	const _c = _audio.currentTime * 1000
-	console.log("🚀 ~ 播放的时间:", _c)
-	if (_c > 500){
-		console.log('evaluatingData.backtime: ',  evaluatingData.backtime, 'backtime:', backtime)
-		console.error('开始播放的延迟:', Date.now() - backtime - 500)
-		_audio.pause()
+	console.log("🚀 ~ 播放的时间测试:", _c)
+	if (_c >= 500){
+		console.log('evaluatingData.backtime: ',  evaluatingData.backtime)
+		console.error('开始播放的延迟:', Date.now() - evaluatingData.backtime - 500)
 		// playMusic()
+		_audio.pause()
 		return
 	}
 	setTimeout(() => {
@@ -275,10 +272,12 @@ const getTestCurrent = () => {
 }
 
 const playTestMusic = () => {
-	_audio = new Audio()
+	// _audio = new Audio(state.music)
+	_audio = new Audio(testAudio)
+	// _audio.muted = true
 	// _audio.src = testAudio
-	_audio.src = state.accompany
 	_audio.onplay = () => {
+		console.log('开始播放测试')
 		getTestCurrent()
 	}
 	_audio.onloadedmetadata = () => {
@@ -415,7 +414,6 @@ export default defineComponent({
 			}
 		});
 		onMounted(() => {
-			playTestMusic();
 			hanlde_record();
 			evaluatingData.resultData = {};
 			// evaluatingData.resultData = {...getLeveByScore(90), score: 30, intonation: 10, cadence: 30, integrity: 40}