Browse Source

feat: 速度逻辑修改

TIANYONG 2 months ago
parent
commit
23be941edc
3 changed files with 19 additions and 8 deletions
  1. 1 1
      osmd-extended
  2. 2 1
      src/page-instrument/header-top/speed/index.tsx
  3. 16 6
      src/state.ts

+ 1 - 1
osmd-extended

@@ -1 +1 @@
-Subproject commit 134d7aba9db4a46180220ee256d8a4e3f05c1a2e
+Subproject commit 171236fa9c896ba1de9b84e327a226410947760d

+ 2 - 1
src/page-instrument/header-top/speed/index.tsx

@@ -39,7 +39,8 @@ export default defineComponent({
 				state.speed = Math.floor(speed.value);
 				// handleSetSpeed(speed.value);
 				if (state.playState === 'paused') {
-					const currentItem: any = (state.sectionStatus && state.section.length === 2) ? state.sectionFirst || state.section[0] : state.times[state.activeNoteIndex];
+					// const currentItem: any = (state.sectionStatus && state.section.length === 2) ? state.sectionFirst || state.section[0] : state.times[state.activeNoteIndex];
+					const currentItem: any = state.times[state.activeNoteIndex];
 					state.basePlayRate = currentItem?.measureSpeed ? state.speed / currentItem.measureSpeed : state.speed / state.originSpeed;
 				}
 			}

+ 16 - 6
src/state.ts

@@ -586,6 +586,8 @@ const state = reactive({
   isWorkDone: false,
   /** xml的第一个measure标签的number */
   firstMeasureNumber: 1,
+  /** 是否是自动重播,练习模式开启自动重播时,播放前不需要再次计算播放倍率了,还是按照上次的播放倍率播放音频 */
+  isAutoRePlay: false,
 });
 const browserInfo = browser();
 let offset_duration = 0;
@@ -636,6 +638,8 @@ const autoResetPlay = () => {
   offsetTop = 0;
   scrollViewNote();
   setTimeout(() => {
+    // 自动播放,不需要再次计算播放倍率
+    state.isAutoRePlay = true;
     togglePlay("play");
   }, 1000);
 };
@@ -664,25 +668,31 @@ export const onEnded = () => {
 
 // 根据当前小节动态设置,右上角展示的速度
 const dynamicShowPlaySpeed = (index: number) => {
-  if (!headerColumnHide.value) {
-    // console.log('动态计算速度')
+  //if (!headerColumnHide.value) {
     const item: any = state.times[index];
     if (item && item.measureSpeed ) {
       // console.log('速度1',item.measureSpeed)
-      const newSpeed = Math.floor(state.basePlayRate * item.measureSpeed)
+      const newSpeed = state.basePlayRate * item.measureSpeed
       if (state.speed !== newSpeed) {
         state.speed = newSpeed;
       }
     }
-  }
+  //}
 
 }
 
 // 开始播放时,计算mp3的播放倍率
 export const initSetPlayRate = () => {
-  const item: any = (state.sectionStatus && state.section.length === 2) ? state.sectionFirst || state.section[0] : state.times[state.activeNoteIndex];
+  // 自动播放,不需要再次计算播放倍率
+  if (state.isAutoRePlay) {
+    state.isAutoRePlay = false
+    return
+  }  
+  // const item: any = (state.sectionStatus && state.section.length === 2) ? state.sectionFirst || state.section[0] : state.times[state.activeNoteIndex];
+  let item: any = state.times[state.activeNoteIndex];
+  console.log('播放状态',state.playState)  
   if (item && item.measureSpeed) {
-    const ratio = state.speed / Math.floor(item.measureSpeed)
+    const ratio = state.speed / item.measureSpeed
     // state.audiosInstance?.setSpeed(ratio)
     state.basePlayRate = ratio || 1;
     console.log('播放倍率',state.basePlayRate)