From 6f67f515b2ec8610475ed2f7822733466f7a3030 Mon Sep 17 00:00:00 2001 From: hui <55790859+grayana@users.noreply.github.com> Date: Thu, 12 Sep 2024 17:46:21 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E6=92=AD=E6=94=BE?= =?UTF-8?q?=E8=BF=9B=E5=BA=A6=20(#160)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: windows下保存配置失败 * feat: 增加播放进度 --- xiaomusic/httpserver.py | 4 ++++ xiaomusic/static/app.js | 22 ++++++++++++++++++++++ xiaomusic/static/index.html | 4 ++++ xiaomusic/xiaomusic.py | 18 ++++++++++++++++++ 4 files changed, 48 insertions(+) diff --git a/xiaomusic/httpserver.py b/xiaomusic/httpserver.py index ed0d2bf..c4339a1 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 981ece2..c36aa89 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 455089f..dba8a39 100644 --- a/xiaomusic/static/index.html +++ b/xiaomusic/static/index.html @@ -44,6 +44,10 @@ var vConsole = new window.VConsole(); +