diff --git a/xiaomusic/httpserver.py b/xiaomusic/httpserver.py index d525a81..b0b03d6 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 f68a7f4..e813c8c 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 e7a1f24..582a978 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 @@ - + + +