Skip to content

Commit

Permalink
fix: 优化日志输出,尝试排查延迟播放的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
hanxi committed Jul 28, 2024
1 parent 12f54e3 commit 5b5f957
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions xiaomusic/xiaomusic.py
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,7 @@ async def play(self, name="", search_key=""):
async def _play(self, name="", search_key=""):
if search_key == "" and name == "":
if self.check_play_next():
await self.play_next()
await self._play_next()
return
else:
name = self.cur_music
Expand Down Expand Up @@ -888,7 +888,7 @@ async def _play_next(self):
or (name not in self._play_list)
):
name = self.get_next_music()
self.log.info(f"play_next. name:{name}, cur_music:{self.cur_music}")
self.log.info(f"_play_next. name:{name}, cur_music:{self.cur_music}")
if name == "":
await self.do_tts("本地没有歌曲")
return
Expand All @@ -899,7 +899,7 @@ async def playlocal(self, name):
self._last_cmd = "playlocal"
if name == "":
if self.check_play_next():
await self.play_next()
await self._play_next()
return
else:
name = self.cur_music
Expand All @@ -914,6 +914,9 @@ async def playlocal(self, name):
await self._playmusic(name)

async def _playmusic(self, name):
# 取消组内所有的下一首歌曲的定时器
self.cancel_group_next_timer()

self._playing = True
self.cur_music = name
self.log.info(f"cur_music {self.cur_music}")
Expand All @@ -928,10 +931,8 @@ async def _playmusic(self, name):
await self._play_next()
return

self.log.info("已经开始播放了")
self.log.info(f"【{name}已经开始播放了")

# 取消组内所有的下一首歌曲的定时器
self.cancel_group_next_timer()
# 设置下一首歌曲的播放定时器
sec = sec + self.config.delay_sec
await self.set_next_music_timeout(sec)
Expand Down Expand Up @@ -1084,14 +1085,17 @@ def get_next_music(self):
def check_play_next(self):
# 当前歌曲不在当前播放列表
if self.cur_music not in self._play_list:
self.log.info(f"当前歌曲 {self.cur_music} 不在当前播放列表")
return True

# 当前没我在播放的歌曲
if self.cur_music == "":
self.log.info("当前没我在播放的歌曲")
return True
else:
# 当前播放的歌曲不存在了
if not self.xiaomusic.is_music_exist(self.cur_music):
self.log.info(f"当前播放的歌曲 {self.cur_music} 不存在了")
return True
return False

Expand Down

0 comments on commit 5b5f957

Please sign in to comment.