Skip to content

Commit

Permalink
新增显示当前正在播放的音乐
Browse files Browse the repository at this point in the history
  • Loading branch information
hanxi committed Apr 30, 2024
1 parent b9e1abf commit 050ded6
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 3 deletions.
8 changes: 6 additions & 2 deletions xiaomusic/httpserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
13 changes: 13 additions & 0 deletions xiaomusic/static/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
33 changes: 32 additions & 1 deletion xiaomusic/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
</style>
</head>
<body>
Expand All @@ -47,7 +75,10 @@ <h2>小爱音箱操控面板</h2>
<datalist id="autocomplete-list"></datalist>
<input id="music-name" type="text" placeholder="请输入搜索关键词(如:MV高清版 周杰伦 七里香)" list="autocomplete-list"></input>
<input id="music-filename" type="text" placeholder="请输入保存为的文件名称(如:周杰伦七里香)"></input>
<button id="play">播放</button>
</div>
<button id="play">播放</button>
<div class="container">
<div id="playering-music" class="text"></div>
</div>
</body>
</html>
5 changes: 5 additions & 0 deletions xiaomusic/xiaomusic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 050ded6

Please sign in to comment.