From 050ded6b2e9b1586977a20c5524a5c1d2ed8a23b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B6=B5=E6=9B=A6?= Date: Tue, 30 Apr 2024 13:47:45 +0000 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=98=BE=E7=A4=BA=E5=BD=93?= =?UTF-8?q?=E5=89=8D=E6=AD=A3=E5=9C=A8=E6=92=AD=E6=94=BE=E7=9A=84=E9=9F=B3?= =?UTF-8?q?=E4=B9=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- xiaomusic/httpserver.py | 8 ++++++-- xiaomusic/static/app.js | 13 +++++++++++++ xiaomusic/static/index.html | 33 ++++++++++++++++++++++++++++++++- xiaomusic/xiaomusic.py | 5 +++++ 4 files changed, 56 insertions(+), 3 deletions(-) diff --git a/xiaomusic/httpserver.py b/xiaomusic/httpserver.py index d525a8106..b0b03d6d5 100644 --- a/xiaomusic/httpserver.py +++ b/xiaomusic/httpserver.py @@ -22,17 +22,21 @@ def allcmds(): return KEY_WORD_DICT -@app.route("/getvolume") +@app.route("/getvolume", methods=["GET"]) def getvolume(): return { "volume": xiaomusic.get_volume(), } -@app.route("/searchmusic") +@app.route("/searchmusic", methods=["GET"]) def searchmusic(): name = request.args.get('name') return xiaomusic.searchmusic(name) +@app.route("/playingmusic", methods=["GET"]) +def playingmusic(): + return xiaomusic.playingmusic() + @app.route("/", methods=["GET"]) def redirect_to_index(): return send_from_directory("static", "index.html") diff --git a/xiaomusic/static/app.js b/xiaomusic/static/app.js index f68a7f458..e813c8cdb 100644 --- a/xiaomusic/static/app.js +++ b/xiaomusic/static/app.js @@ -86,4 +86,17 @@ $(function(){ } }); }); + + function get_playing_music() { + $.get("/playingmusic", function(data, status) { + console.log(data); + $("#playering-music").text(data); + }); + } + + // 每3秒获取下正在播放的音乐 + get_playing_music(); + setInterval(() => { + get_playing_music(); + }, 3000); }); diff --git a/xiaomusic/static/index.html b/xiaomusic/static/index.html index e7a1f2435..582a97844 100644 --- a/xiaomusic/static/index.html +++ b/xiaomusic/static/index.html @@ -28,6 +28,34 @@ width: 300px; height: 40px; } + + .container{ + width: 280px; + overflow: hidden; + display: inline-block; + } + @keyframes text-scroll { + 0% { + left: 100%; + } + 25% { + left: 50%; + } + 50% { + left: 0%; + } + 75% { + left: -50%; + } + 100% { + left: -100%; + } + } + .text { + font-weight: bold; + position: relative; + animation: text-scroll 10s linear infinite; + } @@ -47,7 +75,10 @@

小爱音箱操控面板

- + + +
+
diff --git a/xiaomusic/xiaomusic.py b/xiaomusic/xiaomusic.py index fa7413f6a..28f8bf442 100644 --- a/xiaomusic/xiaomusic.py +++ b/xiaomusic/xiaomusic.py @@ -580,3 +580,8 @@ def searchmusic(self, name): search_list = fuzzyfinder(name, self._play_list) self.log.debug("searchmusic. name:%s search_list:%s", name, search_list) return search_list + + # 正在播放中的音乐 + def playingmusic(self): + self.log.debug("playingmusic. cur_music:%s", self.cur_music) + return self.cur_music