Another fix for join sounds not playing, should be working in all cases now.

This commit is contained in:
Storm Dragon
2026-07-14 20:54:51 -04:00
parent 14163bdbc1
commit 213aa3770a
3 changed files with 109 additions and 9 deletions
+15 -3
View File
@@ -510,6 +510,8 @@ class MumbleBot:
uri = music_wrapper.uri()
self.log.info("bot: play music " + music_wrapper.format_debug_string())
self.last_ffmpeg_err = ""
self.ffmpeg_fatal_error = ""
# Only announce if configured and not a silent item (e.g., join sounds)
if var.config.getboolean('bot', 'announce_current_music') and not music_wrapper.silent:
@@ -643,8 +645,10 @@ class MumbleBot:
self._loop_status = f'Wait for buffer {self.mumble.sound_output.get_buffer_size():.3f}'
time.sleep(0.01)
had_ffmpeg_thread = self.thread is not None
ffmpeg_returncode = None
raw_music = None
if self.thread:
if had_ffmpeg_thread:
# I get raw from ffmpeg thread
# move playhead forward
self._loop_status = 'Reading raw'
@@ -678,15 +682,20 @@ class MumbleBot:
time.sleep(0.1)
self.on_interrupting = False
else:
ffmpeg_returncode = self.thread.poll()
time.sleep(0.1)
else:
time.sleep(0.1)
if not self.is_pause and not raw_music:
self._cleanup_ffmpeg_process()
cleanup_returncode = self._cleanup_ffmpeg_process()
if ffmpeg_returncode is None:
ffmpeg_returncode = cleanup_returncode
# bot is not paused, but ffmpeg thread has gone.
# indicate that last song has finished, or the bot just resumed from pause, or something is wrong.
if self.read_pcm_size < self.pcm_buffer_size \
if had_ffmpeg_thread \
and ffmpeg_returncode not in (None, 0) \
and self.read_pcm_size < self.pcm_buffer_size \
and var.playlist.current_index != -1 \
and self.last_ffmpeg_err:
current = var.playlist.current_item()
@@ -884,6 +893,7 @@ class MumbleBot:
def _cleanup_ffmpeg_process(self):
"""Properly cleanup FFmpeg process and associated resources"""
returncode = None
if self.thread:
try:
# Check if process is already terminated to avoid double cleanup
@@ -898,6 +908,7 @@ class MumbleBot:
else:
# Process already terminated, just wait to reap it
self.thread.wait()
returncode = self.thread.returncode
except Exception as e:
self.log.error(f"bot: Error cleaning up FFmpeg process: {e}")
finally:
@@ -909,6 +920,7 @@ class MumbleBot:
except Exception as e:
self.log.error(f"bot: Error closing stderr pipe: {e}")
self.thread = None
return returncode
def interrupt(self):
# Kill the ffmpeg thread