From d32d30b795bf19a654713d2d0f08c56209f9ad28 Mon Sep 17 00:00:00 2001 From: Terry Geng Date: Thu, 2 Apr 2020 18:27:15 +0800 Subject: [PATCH] fix: fixed #118, weird threading issue --- command.py | 7 +++---- media/playlist.py | 2 +- mumbleBot.py | 6 +++--- templates/index.html | 1 - 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/command.py b/command.py index f64ddfd..a263903 100644 --- a/command.py +++ b/command.py @@ -68,8 +68,8 @@ def register_all_commands(bot): # Just for debug use bot.register_command('rtrms', cmd_real_time_rms, True) - bot.register_command('loop', cmd_loop_state, True) - bot.register_command('item', cmd_item, True) + #bot.register_command('loop', cmd_loop_state, True) + #bot.register_command('item', cmd_item, True) def send_multi_lines(bot, lines, text, linebreak="
"): @@ -1191,5 +1191,4 @@ def cmd_loop_state(bot, user, text, command, parameter): def cmd_item(bot, user, text, command, parameter): - print(bot.wait_for_downloading) - print(var.playlist.current_item().to_dict()) + var.playlist._debug_print() diff --git a/media/playlist.py b/media/playlist.py index 41798f1..b515703 100644 --- a/media/playlist.py +++ b/media/playlist.py @@ -202,7 +202,7 @@ class BasePlaylist(list): self.from_list(music_wrappers, current_index) def _debug_print(self): - print("===== Playlist(%d)=====" % self.current_index) + print("===== Playlist(%d) =====" % self.current_index) for index, item_wrapper in enumerate(self): if index == self.current_index: print("-> %d %s" % (index, item_wrapper.format_debug_string())) diff --git a/mumbleBot.py b/mumbleBot.py index 601b308..ac3ec83 100644 --- a/mumbleBot.py +++ b/mumbleBot.py @@ -443,7 +443,7 @@ class MumbleBot: else: time.sleep(0.1) - if not self.is_pause and (self.thread is None or not raw_music): + if not self.is_pause and (self.thread is None or self.thread.poll() is not None): # ffmpeg thread has gone. indicate that last song has finished, or something is wrong. if self.read_pcm_size < 481 and len(var.playlist) > 0 and var.playlist.current_index != -1 \ and self.last_ffmpeg_err: @@ -567,14 +567,13 @@ class MumbleBot: self.log.info("bot: music paused at %.2f seconds." % self.playhead) def resume(self): - self.is_pause = False - if var.playlist.current_index == -1: var.playlist.next() music_wrapper = var.playlist.current_item() if not music_wrapper or not music_wrapper.id == self.pause_at_id or not music_wrapper.is_ready(): + self.is_pause = False self.playhead = 0 return @@ -602,6 +601,7 @@ class MumbleBot: self.thread = sp.Popen(command, stdout=sp.PIPE, stderr=pipe_wd, bufsize=480) self.last_volume_cycle_time = time.time() self.pause_at_id = "" + self.is_pause = False def start_web_interface(addr, port): diff --git a/templates/index.html b/templates/index.html index 155ae97..17cc72d 100644 --- a/templates/index.html +++ b/templates/index.html @@ -495,7 +495,6 @@ statusCode : { 200 : function(data) { if (data.ver !== playlist_ver) { - playlist_ver = data.ver; checkForPlaylistUpdate(); } updateControls(data.empty, data.play, data.mode);