From b10e72962796b27d19433add842bf41b7e0a8da1 Mon Sep 17 00:00:00 2001 From: Keith Edmunds Date: Sun, 30 May 2021 21:50:02 +0100 Subject: [PATCH] Hopefully addressing segfault in issue #3 --- app/music.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/app/music.py b/app/music.py index 36cff7a..4ca45c9 100644 --- a/app/music.py +++ b/app/music.py @@ -30,7 +30,7 @@ class Music: to hold up the UI during the fade. """ - DEBUG("fade()") + DEBUG("music.fade()") if not self.playing(): return None @@ -45,7 +45,7 @@ class Music: Implementation of fading the current track in a separate thread. """ - DEBUG("_fade()") + DEBUG("music._fade()") fade_time = Config.FADE_TIME / 1000 steps = Config.FADE_STEPS @@ -75,11 +75,16 @@ class Music: def get_playtime(self): "Return elapsed play time" + if not self.player: + return None + return self.player.get_time() def get_position(self): "Return current position" + DEBUG("music.get_position") + return self.player.get_position() def play(self, path): @@ -89,7 +94,7 @@ class Music: Log and return if path not found. """ - DEBUG(f"play({path})") + DEBUG(f"music.play({path})") if not os.access(path, os.R_OK): ERROR(f"play({path}): path not found") @@ -135,8 +140,15 @@ class Music: def stop(self): "Immediately stop playing" + DEBUG("music.stop()") + + if not self.player: + return None + position = self.player.get_position() self.player.stop() self.player.release() + # Ensure we don't reference player after release + self.player = None return position