index-a7349f60.js 2.9 KB

1
  1. import{d as e,g as i,r as t,o as a,s as n,H as s,v as o,c as r,M as l,Q as d,R as u,S as c,U as m,L as p,n as g,V as v,W as M,O as S,X as _,Y as I,Z as x}from"./instrument-6b3af15f.js";import"./node_modules-67104e44.js";import"./src-49690391.js";const T="_detail_li4n4_15",y="_mask_li4n4_23",L="_container_li4n4_29",N="_whiteBg_li4n4_48",b=e({name:"simple-detail",setup(){const e=i(),b=t({isLoading:!0,currentTime:0,totalTime:0,backgroundRendMode:""}),h=e=>{var i,t,a,s;let o={};try{o="string"==typeof(null==e?void 0:e.data)?JSON.parse(e.data):e.data}catch(r){console.error("parse_error: Invalid JSON data received")}if("api_play"===(null==o?void 0:o.api)&&(console.log("h5开始播放"),n.playState="play",P()),"api_paused"===(null==o?void 0:o.api)){const e=null==(i=null==o?void 0:o.content)?void 0:i.currentTime;console.log("暂停播放",e),n.playState="paused",0===e&&setTimeout((()=>{b.currentTime=0,n.activeNoteIndex=0,n.activeMeasureIndex=n.times[0].MeasureNumberXML,f(!0)}),200)}if("api_updateProgress"===(null==o?void 0:o.api)&&(console.log("拖动的进度",n.playState),"paused"===n.playState&&(b.currentTime=null!=(a=null==(t=null==o?void 0:o.content)?void 0:t.currentTime)?a:b.currentTime,n.activeNoteIndex=0,n.activeMeasureIndex=n.times[0].MeasureNumberXML,f(!0))),"api_playProgress"===(null==o?void 0:o.api)){const e=null==(s=null==o?void 0:o.content)?void 0:s.currentTime;if(e){if(e<b.currentTime){n.activeNoteIndex=0;let i=d(e)||n.times[0];i.i===n.activeNoteIndex&&(n.activeMeasureIndex=i.MeasureNumberXML);e<=n.times[0].fixtime&&u(!0)}b.currentTime=e}}};a((async()=>{const i=e.id||"",t=e.userMusicId||"";b.backgroundRendMode=e.backgroundRendMode,n.isSimplePage=!0,n.partIndex=e["part-index"]?Number(e["part-index"]):0,await s(i,"open",t),b.isLoading=!1,n.isSingleLine=!0,window.addEventListener("message",h)})),o((()=>{n.isSimplePage=!1,window.removeEventListener("message",h)}));const w=async e=>{var i;const t=null==(i=document.getElementById("scrollContainer"))?void 0:i.getBoundingClientRect().height;n.osmd=e,0===n.originSpeed&&(n.originSpeed=n.speed=e.bpm||e.Sheet.userStartTempoInBPM||100);const a=(c.get("speeds")||{})[n.examSongId]||n.speed||e.bpm||e.Sheet.userStartTempoInBPM;a&&m(a),n.times=p(e),console.log("🚀 ~ state.times:",n.times,n),g((()=>{n.activeMeasureIndex=n.times[0].MeasureNumberXML})),v(n.times),M(),S(),console.log("渲染完成",t),window.parent.postMessage({api:"api_musicPage",height:t},"*"),_({height:t})},f=e=>{const i=b.currentTime;let t=d(i)||n.times[0];t&&I(t,e),n.activeNoteIndex=(null==t?void 0:t.i)||0,n.isSingleLine&&x(i,!0)},P=()=>{if("play"!==n.playState)return void console.log("暂停播放");let e=Date.now();requestAnimationFrame((()=>{Date.now()-e<16.7?(f(),P()):setTimeout((()=>{f(),P()}),16.7)}))};return()=>r("div",{class:[T,"video"===b.backgroundRendMode&&N]},[r("div",{class:y},null),r("div",{id:"scrollContainer",class:[L]},[!b.isLoading&&r(l,{onRendered:w,musicColor:"#000000"},null)])])}});export{b as default};