From 4a927084c96762dc8921ca1ec26bfd008e2dd963 Mon Sep 17 00:00:00 2001 From: Keith Edmunds Date: Fri, 14 Apr 2023 11:12:13 +0100 Subject: [PATCH] Fix (workaround) volume going to zero after track starts --- app/music.py | 5 +++- app/musicmuster.py | 58 ++++++++++++++++++++++++++++------------------ 2 files changed, 39 insertions(+), 24 deletions(-) diff --git a/app/music.py b/app/music.py index 28e94a0..8161551 100644 --- a/app/music.py +++ b/app/music.py @@ -130,7 +130,7 @@ class Music: return status - def set_volume(self, volume, set_default=True): + def set_volume(self, volume=None, set_default=True): """Set maximum volume used for player""" if not self.player: @@ -139,6 +139,9 @@ class Music: if set_default: self.max_volume = volume + if volume is None: + volume = Config.VOLUME_VLC_DEFAULT + self.player.audio_set_volume(volume) def stop(self) -> float: diff --git a/app/musicmuster.py b/app/musicmuster.py index c822421..967b101 100755 --- a/app/musicmuster.py +++ b/app/musicmuster.py @@ -301,6 +301,29 @@ class Window(QMainWindow, Ui_MainWindow): self.timer.start(Config.TIMER_MS) self.connect_signals_slots() + def about(self) -> None: + """Get git tag and database name""" + + try: + git_tag = str( + subprocess.check_output( + ['git', 'describe'], stderr=subprocess.STDOUT + ) + ).strip('\'b\\n') + except subprocess.CalledProcessError as exc_info: + git_tag = str(exc_info.output) + + with Session() as session: + if session.bind: + dbname = session.bind.engine.url.database + + QMessageBox.information( + self, + "About", + f"MusicMuster {git_tag}\n\nDatabase: {dbname}", + QMessageBox.StandardButton.Ok + ) + def cart_configure(self, cart: Carts, btn: CartButton) -> None: """Configure button with cart data""" @@ -821,29 +844,6 @@ class Window(QMainWindow, Ui_MainWindow): self.stop_playing(fade=True) - def about(self) -> None: - """Get git tag and database name""" - - try: - git_tag = str( - subprocess.check_output( - ['git', 'describe'], stderr=subprocess.STDOUT - ) - ).strip('\'b\\n') - except subprocess.CalledProcessError as exc_info: - git_tag = str(exc_info.output) - - with Session() as session: - if session.bind: - dbname = session.bind.engine.url.database - - QMessageBox.information( - self, - "About", - f"MusicMuster {git_tag}\n\nDatabase: {dbname}", - QMessageBox.StandardButton.Ok - ) - def get_one_track(self, session: scoped_session) -> Optional[Tracks]: """Show dialog box to select one track and return it to caller""" @@ -1234,6 +1234,18 @@ class Window(QMainWindow, Ui_MainWindow): # Play (new) current track self.current_track.start() self.music.play(self.current_track.path, position) + # For as-yet unknown reasons. sometimes the volume gets + # reset to zero within 200mS or so of starting play. This + # only happened since moving to Debian 12, which uses + # Pipewire for sound (which may be irrelevant). + for _ in range(3): + if self.music.player: + volume = self.music.player.audio_get_volume() + if volume < 10: + self.music.set_volume() + log.error(f"Reset from {volume=}") + break + sleep(0.1) # Tell database to record it as played Playdates(session, self.current_track.track_id)