Selaa lähdekoodia

fix: midi播放

TIANYONG 1 vuosi sitten
vanhempi
commit
06d23cb378

+ 8 - 0
src/components/the-audio/index.module.less

@@ -0,0 +1,8 @@
+.wrap {
+    background: goldenrod;
+    position: fixed;
+    left: 0;
+    bottom: 0;
+    width: 100%;
+    z-index: 999;
+}

+ 6 - 1
src/components/the-audio/index.tsx

@@ -1,4 +1,4 @@
-import { defineComponent, reactive, ref } from "vue";
+import { defineComponent, reactive, ref, onMounted } from "vue";
 import styles from "./index.module.less";
 import { Icon } from "vant";
 export default defineComponent({
@@ -11,6 +11,11 @@ export default defineComponent({
     },
 	setup(props) {
         const videoRef = ref()
+		onMounted(() => {
+			var audio: any = document.querySelector('audio');
+			audio.volume = 0.1;
+			
+		})
 		return () => (
 			<div class={styles.wrap}>
 				<audio ref={videoRef} preload="auto" controls src={props.src}></audio>

+ 4 - 0
src/page-instrument/view-detail/index.tsx

@@ -30,6 +30,8 @@ import ToggleMusicSheet from "/src/view/plugins/toggleMusicSheet";
 import { setCustomGradual, setCustomNoteRealValue } from "/src/helpers/customMusicScore"
 import { usePageVisibility } from "@vant/use";
 import { initMidi } from "/src/helpers/midiPlay"
+import TheAudio from "/src/components/the-audio"
+import tickWav from "/src/assets/tick.wav";
 
 /**
  * 特殊教材分类id
@@ -373,6 +375,8 @@ export default defineComponent({
         {/* 播放 */}
         {!detailData.isLoading && <AudioList />}
 
+        {/* {!detailData.isLoading && <TheAudio src={tickWav} />} */}
+
         {/* 评测 */}
         {state.modeType === "evaluating" && (
           <>

+ 13 - 3
src/state.ts

@@ -9,7 +9,7 @@ import { handleStartTick } from "./view/tick";
 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";
+import { api_cloudGetMediaStatus, api_createMusicPlayer, api_cloudChangeSpeed, api_cloudSuspend, api_cloudSetCurrentTime } from "./helpers/communication";
 import { verifyCanRepeat, getDuration } from "./helpers/formateMusic";
 import { getMusicSheetDetail } from "./utils/baseApi"
 import { getQuery } from "/src/utils/queryString";
@@ -576,7 +576,7 @@ const handlePlaying = () => {
   metronomeData.metro?.sound(currentTime);
 };
 /** 跳转到指定音符开始播放 */
-export const skipNotePlay = (itemIndex: number, isStart = false) => {
+export const skipNotePlay = async (itemIndex: number, isStart = false) => {
   const item = state.times[itemIndex];
   let itemTime = item.time;
   if (isStart) {
@@ -587,6 +587,10 @@ export const skipNotePlay = (itemIndex: number, isStart = false) => {
     gotoNext(item);
     metronomeData.metro?.sound(itemTime);
     if (state.isAppPlay) {
+      await api_cloudSetCurrentTime({
+        currentTime: itemTime * 1000,
+        songID: state.examSongId,
+      })
       audioData.progress = itemTime
     }
   }
@@ -599,7 +603,13 @@ export const skipNotePlay = (itemIndex: number, isStart = false) => {
 export const togglePlay = async (playState?: "play" | "paused") => {
   // midi播放
   if (state.isAppPlay) {
-    if( playState === "paused" ) return
+    if( playState === "paused" ) {
+      await api_cloudSuspend({
+        songID: state.examSongId,
+      })
+      state.playState = 'paused'
+      return
+    }
     await api_cloudChangeSpeed({
       speed: state.modeType === "evaluating" ? state.originSpeed : state.speed,
       originalSpeed: state.originSpeed,