From f0d7757f0c6d383c4443e20557317f0c997023fb Mon Sep 17 00:00:00 2001 From: miruka Date: Mon, 1 Mar 2021 09:45:28 -0400 Subject: [PATCH] Catch simpleaudio playback errors Because of course sound isn't just gonna work on linux and especially flatpak. Make sure to not spawn an error popup every time we try to play a notification. Maybe use mpv in the future for SFX playback (when we'll have a media player implemented), since it has support for all these backends out of the box. --- src/backend/backend.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/backend/backend.py b/src/backend/backend.py index ed3d9d31..1a502d9f 100644 --- a/src/backend/backend.py +++ b/src/backend/backend.py @@ -149,6 +149,7 @@ class Backend: self.notification_avatar_cache: Dict[str, Path] = {} # {mxc: path} self.notifications_working: bool = True + self.audio_working: bool = True def __repr__(self) -> str: @@ -600,7 +601,16 @@ class Backend: try: content = pyotherside.qrc_get_file_contents(path) except ValueError: - simpleaudio.WaveObject.from_wave_file(path).play() + sa = simpleaudio.WaveObject.from_wave_file(path) else: wave_read = wave.open(io.BytesIO(content)) - simpleaudio.WaveObject.from_wave_read(wave_read).play() + sa = simpleaudio.WaveObject.from_wave_read(wave_read) + + try: + sa.play() + self.audio_working = True + except Exception as e: # noqa + if self.audio_working: + trace = traceback.format_exc().rstrip() + log.error("Playing audio failed\n%s", trace) + self.audio_working = False