Fall back between audio engines instead of crashing; CI installs libpulse

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01J7imThHV9BMkG24GaxPDeq
This commit is contained in:
Claude 2026-10-09 23:20:38 -05:00
commit 5ca8f0b4e2
No known key found for this signature in database
3 changed files with 20 additions and 7 deletions

View file

@ -79,7 +79,7 @@ jobs:
with:
python-version: "3.12"
- name: System packages
run: sudo apt-get update && sudo apt-get install -y libegl1 libxkbcommon0 libxcb-cursor0 desktop-file-utils file
run: sudo apt-get update && sudo apt-get install -y libegl1 libxkbcommon0 libxcb-cursor0 libpulse0 desktop-file-utils file
- name: Install dependencies
run: |
python -m pip install --upgrade pip

View file

@ -179,6 +179,8 @@ class MainWindow(QMainWindow):
if settings.get("library/scan_on_start") and settings.get("library/folders"):
QTimer.singleShot(1500, lambda: L.library.scan(False))
QTimer.singleShot(0, self._resume)
if self.player.backend_error and not os.environ.get("MULBERRY_SELFTEST"):
QTimer.singleShot(500, lambda: QMessageBox.warning(self, "Audio", self.player.backend_error))
# ================================================================ menus
def _build_menus(self):

View file

@ -469,14 +469,25 @@ class Player(QObject):
Player.instance = self
self.mgr = manager
self.backend: Backend
if preferred_backend() == "mpv":
self.backend_error = ""
order = ["mpv", "qt"] if preferred_backend() == "mpv" else ["qt", "mpv"]
errors = []
for name in order:
try:
self.backend = MpvBackend()
except Exception as e: # noqa: BLE001
print("mpv backend failed, using Qt:", e)
self.backend = QtBackend()
if name == "mpv":
if not mpv_available():
raise RuntimeError("libmpv not found")
self.backend = MpvBackend()
else:
self.backend = QtBackend()
break
except Exception as e: # noqa: BLE001 (e.g. ImportError: libpulse.so.0 missing)
errors.append(f"{name}: {e}")
print(f"{name} backend unavailable:", e)
else:
self.backend = QtBackend()
self.backend = Backend() # silent placeholder: UI still works
self.backend_error = ("No audio engine could start.\n" + "\n".join(errors) +
"\n\nInstall mpv, or PulseAudio/PipeWire's libpulse (pipewire-pulse).")
b = self.backend
b.position.connect(self._on_pos)
b.duration.connect(self._on_dur)