|
@@ -1,4 +1,4 @@
|
|
|
-import { computed, defineComponent, onMounted, reactive, ref, watch } from "vue";
|
|
|
+import { computed, defineComponent, onMounted, onUnmounted, reactive, ref, watch } from "vue";
|
|
|
import styles from "./index.module.less";
|
|
|
import {
|
|
|
getMidiCurrentTime,
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
setMidiCurrentTime,
|
|
|
} from "./midiPlayer";
|
|
|
import state, { IPlayState, onEnded, onPlay } from "/src/state";
|
|
|
-import { api_playProgress, api_cloudTimeUpdae } from "/src/helpers/communication";
|
|
|
+import { api_playProgress, api_cloudTimeUpdae, api_cloudplayed, api_remove_cloudplayed } from "/src/helpers/communication";
|
|
|
import { evaluatingData } from "/src/view/evaluating";
|
|
|
import { cloudToggleState } from "/src/helpers/midiPlay"
|
|
|
|
|
@@ -173,15 +173,27 @@ export default defineComponent({
|
|
|
// midi播放进度回调
|
|
|
const midiProgress = (res: any) => {
|
|
|
// console.log('api',res)
|
|
|
+ if (audioData.duration == 0) {
|
|
|
+ const songEndTime = state.times[state.times.length - 1 || 0]?.endtime || 0
|
|
|
+ audioData.duration = songEndTime
|
|
|
+ }
|
|
|
const currentTime = res?.currentTime || res?.content?.currentTime;
|
|
|
const total = res?.totalDuration || res?.content?.totalDuration;
|
|
|
const time = currentTime / 1000;
|
|
|
audioData.progress = time;
|
|
|
- audioData.duration = total / 1000;
|
|
|
- if (
|
|
|
- res?.content?.totalDuration > 1000 &&
|
|
|
- currentTime >= total
|
|
|
- ) {
|
|
|
+ // if (
|
|
|
+ // audioData.duration > 1000 &&
|
|
|
+ // currentTime >= audioData.duration * 1000
|
|
|
+ // ) {
|
|
|
+ // console.log('midi结束')
|
|
|
+ // onEnded();
|
|
|
+ // }
|
|
|
+ }
|
|
|
+ // midi播放结束回调
|
|
|
+ const midiPlayEnd = (res: any) => {
|
|
|
+ if (res) {
|
|
|
+ console.log('midi结束')
|
|
|
+ audioData.progress = 0
|
|
|
onEnded();
|
|
|
}
|
|
|
}
|
|
@@ -209,9 +221,17 @@ export default defineComponent({
|
|
|
);
|
|
|
|
|
|
api_playProgress(progress);
|
|
|
+ } else {
|
|
|
+ const songEndTime = state.times[state.times.length - 1 || 0]?.endtime || 0
|
|
|
+ audioData.duration = songEndTime
|
|
|
+ // 监听midi播放进度
|
|
|
+ api_cloudTimeUpdae(midiProgress);
|
|
|
+ // 监听midi播放结束
|
|
|
+ api_cloudplayed(midiPlayEnd);
|
|
|
}
|
|
|
- // 监听midi播放进度
|
|
|
- api_cloudTimeUpdae(midiProgress);
|
|
|
+ });
|
|
|
+ onUnmounted(() => {
|
|
|
+ api_remove_cloudplayed(midiPlayEnd);
|
|
|
});
|
|
|
|
|
|
// console.log(state.playMode, state.midiUrl);
|