diff --git a/xiaomusic/httpserver.py b/xiaomusic/httpserver.py index ed0d2bf39..c4339a198 100644 --- a/xiaomusic/httpserver.py +++ b/xiaomusic/httpserver.py @@ -144,10 +144,14 @@ def playingmusic(did: str = "", Verifcation=Depends(verification)): is_playing = xiaomusic.isplaying(did) cur_music = xiaomusic.playingmusic(did) + # 播放进度 + offset,duration = xiaomusic.get_offset_duration(did) return { "ret": "OK", "is_playing": is_playing, "cur_music": cur_music, + "offset": offset, + "duration": duration, } diff --git a/xiaomusic/static/app.js b/xiaomusic/static/app.js index 981ece201..c36aa891b 100644 --- a/xiaomusic/static/app.js +++ b/xiaomusic/static/app.js @@ -23,6 +23,9 @@ $(function(){ append_op_button_name("30分钟后关机"); append_op_button_name("60分钟后关机"); + var offset = 0; + var duration = 0; + // 拉取现有配置 $.get("/getsetting", function(data, status) { console.log(data, status); @@ -271,7 +274,26 @@ $(function(){ } else { $("#playering-music").text(`【空闲中】 ${data.cur_music}`); } + offset = data.offset; + duration = data.duration; } }); } + setInterval(()=>{ + if (duration > 0) { + offset++; + $("#progress").val(offset / duration * 100); + $("#play-time").text(`${formatTime(offset)}/${formatTime(duration)}`) + }else{ + $("#play-time").text(`${formatTime(0)}/${formatTime(0)}`) + } + },1000) + function formatTime(seconds) { + var minutes = Math.floor(seconds / 60); + var remainingSeconds =Math.floor(seconds % 60); + return `${minutes.toString().padStart(2, '0')}:${remainingSeconds.toString().padStart(2, '0')}`; +} }); + + + diff --git a/xiaomusic/static/index.html b/xiaomusic/static/index.html index 455089f49..dba8a39f2 100644 --- a/xiaomusic/static/index.html +++ b/xiaomusic/static/index.html @@ -44,6 +44,10 @@