Hopefully addressing segfault in issue #3

This commit is contained in:
Keith Edmunds 2021-05-30 21:50:02 +01:00
parent 8366fed1be
commit b10e729627

View File

@ -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