From 2422adea21edff2a4b8d489af660d708ae12b08e Mon Sep 17 00:00:00 2001 From: Keith Edmunds Date: Fri, 10 Mar 2023 22:34:23 +0000 Subject: [PATCH] Fix play sometimes stopping almost immediately --- app/config.py | 1 + app/musicmuster.py | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/config.py b/app/config.py index fe3590f..3934c3d 100644 --- a/app/config.py +++ b/app/config.py @@ -67,6 +67,7 @@ class Config(object): MINIMUM_ROW_HEIGHT = 30 MYSQL_CONNECT = os.environ.get('MYSQL_CONNECT') or "mysql+mysqldb://musicmuster:musicmuster@localhost/musicmuster_v2" # noqa E501 NOTE_TIME_FORMAT = "%H:%M:%S" + PLAY_SETTLE = 500000 ROOT = os.environ.get('ROOT') or "/home/kae/music" IMPORT_DESTINATION = os.path.join(ROOT, "Singles") SCROLL_TOP_MARGIN = 3 diff --git a/app/musicmuster.py b/app/musicmuster.py index 6958099..4c3c8a4 100755 --- a/app/musicmuster.py +++ b/app/musicmuster.py @@ -1613,7 +1613,14 @@ class Window(QMainWindow, Ui_MainWindow): return # If track is playing, update track clocks time and colours - if self.music.player and self.music.player.is_playing(): + # There is a discrete time between starting playing a track and + # player.is_playing() returning True, so assume playing if less + # than Config.PLAY_SETTLE microseconds have passed since + # starting play. + if self.music.player and self.current_track.start_time and ( + self.music.player.is_playing() or + (datetime.now() - self.current_track.start_time) + < timedelta(microseconds=Config.PLAY_SETTLE)): playtime = self.music.get_playtime() time_to_fade = (self.current_track.fade_at - playtime) time_to_silence = (