|
@@ -504,6 +504,10 @@ const state = reactive({
|
|
|
loadingText: '音频资源加载中,请稍后…',
|
|
|
/** 是否是简单的单行谱模式页面 */
|
|
|
isSimplePage: false,
|
|
|
+ /** xml的速度和后台设置的速度,计算出的基础音频播放倍率 */
|
|
|
+ originAudioPlayRate: 1,
|
|
|
+ /** 开始播放时,记录的mp3播放倍率,用户当前设置的速度/当前小节的速度 */
|
|
|
+ basePlayRate: 1,
|
|
|
});
|
|
|
const browserInfo = browser();
|
|
|
let offset_duration = 0;
|
|
@@ -579,6 +583,35 @@ export const onEnded = () => {
|
|
|
autoResetPlay();
|
|
|
};
|
|
|
|
|
|
+// 根据当前小节动态设置,右上角展示的速度
|
|
|
+const dynamicShowPlaySpeed = (index: number) => {
|
|
|
+ const item: any = state.times[index];
|
|
|
+ if (item && item.measureSpeed ) {
|
|
|
+ state.playIngSpeed = Math.floor(state.basePlayRate * item.measureSpeed)
|
|
|
+ state.speed = state.playIngSpeed
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// 开始播放时,计算mp3的播放倍率
|
|
|
+export const initSetPlayRate = () => {
|
|
|
+ const item: any = (state.sectionStatus && state.section.length === 2) ? state.sectionFirst || state.section[0] : state.times[state.activeNoteIndex];
|
|
|
+ if (item && item.measureSpeed) {
|
|
|
+ const ratio = state.speed / item.measureSpeed
|
|
|
+ // state.audiosInstance?.setSpeed(ratio)
|
|
|
+ state.basePlayRate = ratio || 1;
|
|
|
+ console.log('播放倍率',state.basePlayRate)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// 重置播放倍率
|
|
|
+export const resetBaseRate = () => {
|
|
|
+ const currentItem: any = state.times[0];
|
|
|
+ const currentSpeed = currentItem?.measureSpeed ? currentItem.measureSpeed : state.originSpeed;
|
|
|
+ state.speed = currentSpeed
|
|
|
+ //state.activeNoteIndex = 0
|
|
|
+ state.basePlayRate = 1;
|
|
|
+}
|
|
|
+
|
|
|
/**
|
|
|
* 播放一直触发的事件
|
|
|
*/
|
|
@@ -587,17 +620,8 @@ const handlePlaying = () => {
|
|
|
const duration = getAudioDuration();
|
|
|
state.playProgress = (currentTime / duration) * 100;
|
|
|
let item = getNote(currentTime);
|
|
|
- // console.log(11111,currentTime,duration,state.playSource, item)
|
|
|
- // console.log(item?.i,item?.noteId,item?.measureSpeed,'播放')
|
|
|
- // 练习模式下,实时刷新小节速度
|
|
|
- if (item && state.modeType === "practise" && state.playState === "play" && item.measureSpeed && item.measureSpeed !== state.playIngSpeed) {
|
|
|
- const ratio = state.speed / state.originSpeed
|
|
|
- state.playIngSpeed = Math.ceil(ratio * item.measureSpeed) || state.speed
|
|
|
- } else if (state.modeType === "practise" && state.playState === "play" && item && !item.measureSpeed) {
|
|
|
- state.playIngSpeed = state.speed
|
|
|
- }
|
|
|
- state.playIngSpeed = state.playIngSpeed || state.speed;
|
|
|
if (item) {
|
|
|
+ dynamicShowPlaySpeed(item.i);
|
|
|
// 选段状态下
|
|
|
if (state.sectionStatus && state.section.length === 2) {
|
|
|
// 如果开启了预备拍
|
|
@@ -669,6 +693,10 @@ export const skipNotePlay = async (itemIndex: number, isStart = false) => {
|
|
|
itemTime = 0;
|
|
|
}
|
|
|
if (item) {
|
|
|
+ // 非选段模式,点击音符,动态设置右下角的速度
|
|
|
+ if (item.measureSpeed && state.section.length < 2) {
|
|
|
+ state.speed = Math.floor(state.basePlayRate * item.measureSpeed)
|
|
|
+ }
|
|
|
setAudioCurrentTime(itemTime, itemIndex);
|
|
|
// 一行谱,点击音符,或者播放完成,需要跳转音符位置
|
|
|
gotoNext(item, true);
|
|
@@ -752,6 +780,7 @@ export const togglePlay = async (playState?: "play" | "paused", sourceType?: str
|
|
|
clearSelection();
|
|
|
}
|
|
|
}
|
|
|
+ initSetPlayRate();
|
|
|
audioListStart(state.playState);
|
|
|
return true;
|
|
|
};
|
|
@@ -994,13 +1023,14 @@ export const handleResetPlay = () => {
|
|
|
if (state.isAppPlay) {
|
|
|
audioData.progress = 0
|
|
|
}
|
|
|
+ resetBaseRate();
|
|
|
resetPlaybackToStart();
|
|
|
// 如果是暂停, 直接播放
|
|
|
togglePlay("play");
|
|
|
};
|
|
|
/** 设置速度 */
|
|
|
export const handleSetSpeed = (speed: number) => {
|
|
|
- setStorageSpeed(state.examSongId, speed);
|
|
|
+ // setStorageSpeed(state.examSongId, speed);
|
|
|
state.speed = speed;
|
|
|
};
|
|
|
/** 清除选段状态 */
|