fix: survive mumble disconnects without restarting audio stream
Guard stream_audio with _is_audio_ready() so that PCM frames are
dropped (not crashed on) when pymumble recreates SoundOutput with
encoder=None during reconnect. The ffmpeg pipeline stays alive,
position tracking remains accurate, and audio feeding resumes once
the codec is negotiated. Listeners hear brief silence instead of
a 30+ second restart with URL re-resolution.
Also adds chat messages to _auto_resume so users see what the bot
intends ("Resuming 'X' at M:SS in a moment" / "...aborted").
This commit is contained in:
@@ -204,11 +204,24 @@ async def _auto_resume(bot) -> None:
|
||||
if data is None:
|
||||
return
|
||||
|
||||
elapsed = data.get("elapsed", 0.0)
|
||||
title = _truncate(data.get("title", data["url"]))
|
||||
pos = _fmt_time(elapsed)
|
||||
|
||||
# Let pymumble fully stabilize after reconnect
|
||||
await asyncio.sleep(10)
|
||||
|
||||
deadline = time.monotonic() + 60
|
||||
silence_needed = ps.get("duck_silence", 15)
|
||||
|
||||
ts = getattr(bot, "_last_voice_ts", 0.0)
|
||||
if ts != 0.0 and time.monotonic() - ts < silence_needed:
|
||||
await bot.send("0",
|
||||
f"Resuming '{title}' at {pos} once silent for "
|
||||
f"{silence_needed}s")
|
||||
else:
|
||||
await bot.send("0", f"Resuming '{title}' at {pos} in a moment")
|
||||
|
||||
while time.monotonic() < deadline:
|
||||
await asyncio.sleep(2)
|
||||
ts = getattr(bot, "_last_voice_ts", 0.0)
|
||||
@@ -218,6 +231,8 @@ async def _auto_resume(bot) -> None:
|
||||
break
|
||||
else:
|
||||
log.info("music: auto-resume aborted, channel not silent after 60s")
|
||||
await bot.send("0", f"Resume of '{title}' aborted -- "
|
||||
"channel not silent")
|
||||
return
|
||||
|
||||
# Re-check after waiting -- someone may have started playback manually
|
||||
|
||||
Reference in New Issue
Block a user