From 0cee9777bc56b520f14a68b0c4bfe7c2a12e4f4f Mon Sep 17 00:00:00 2001 From: pdxlocations Date: Fri, 24 Jul 2026 23:39:46 -0700 Subject: [PATCH] Improve sound playback handling by adding support for multiple audio players and enhancing error logging --- contact/message_handlers/rx_handler.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/contact/message_handlers/rx_handler.py b/contact/message_handlers/rx_handler.py index 6ffb1e5..746c15a 100644 --- a/contact/message_handlers/rx_handler.py +++ b/contact/message_handlers/rx_handler.py @@ -74,16 +74,26 @@ def play_sound(): logging.warning("Configured notification sound is unavailable: %s", sound_path) return - executable = "afplay" if platform.system() == "Darwin" else shutil.which("ffplay") or shutil.which("mpg123") + executable = "afplay" if platform.system() == "Darwin" else next( + (shutil.which(player) for player in ("ffplay", "mpg123", "mpv", "cvlc", "paplay") if shutil.which(player)), + None, + ) if executable and sound_path: + player = os.path.basename(executable) cmd = [executable, sound_path] - if executable == "ffplay": + if player == "ffplay": cmd = [executable, "-nodisp", "-autoexit", sound_path] + elif player == "mpv": + cmd = [executable, "--no-video", sound_path] + elif player == "cvlc": + cmd = [executable, "--play-and-exit", sound_path] subprocess.run(cmd, check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) return - logging.warning("No suitable sound player found for notification sound") + logging.warning( + "No suitable sound player found for notification sound; install ffmpeg (ffplay), mpg123, mpv, or VLC." + ) except subprocess.CalledProcessError as e: logging.error(f"Sound playback failed: {e}")