Add DEBUG statements to investigate issue #11

This commit is contained in:
Keith Edmunds 2021-06-06 16:52:12 +01:00
parent caf78df17f
commit 6310dfd5c7

View File

@ -30,7 +30,7 @@ class Music:
to hold up the UI during the fade. to hold up the UI during the fade.
""" """
DEBUG("music.fade()") DEBUG("music.fade()", True)
if not self.playing(): if not self.playing():
return None return None
@ -45,7 +45,11 @@ class Music:
Implementation of fading the current track in a separate thread. Implementation of fading the current track in a separate thread.
""" """
DEBUG("music._fade()") # Take a copy of current player to allow another track to be
# started without interfering here
p = self.player
DEBUG(f"music._fade(), {self.player=}", True)
fade_time = Config.FADE_TIME / 1000 fade_time = Config.FADE_TIME / 1000
steps = Config.FADE_STEPS steps = Config.FADE_STEPS
@ -58,9 +62,6 @@ class Music:
# (n**2 + n) / 2 # (n**2 + n) / 2
total_measures_count = (steps**2 + steps) / 2 total_measures_count = (steps**2 + steps) / 2
# Take a copy of current player to allow another track to be
# started without interfering here
p = self.player
measures_to_reduce_by = 0 measures_to_reduce_by = 0
for i in range(1, steps + 1): for i in range(1, steps + 1):
measures_to_reduce_by += i measures_to_reduce_by += i
@ -69,6 +70,7 @@ class Music:
sleep(sleep_time) sleep(sleep_time)
p.stop() p.stop()
DEBUG(f"Releasing play {p=}", True)
p.release() p.release()
self.fading = False self.fading = False
@ -83,7 +85,7 @@ class Music:
def get_position(self): def get_position(self):
"Return current position" "Return current position"
DEBUG("music.get_position") DEBUG("music.get_position", True)
return self.player.get_position() return self.player.get_position()
@ -94,8 +96,6 @@ class Music:
Log and return if path not found. Log and return if path not found.
""" """
DEBUG(f"music.play({path})")
if not os.access(path, os.R_OK): if not os.access(path, os.R_OK):
ERROR(f"play({path}): path not found") ERROR(f"play({path}): path not found")
return return
@ -104,6 +104,7 @@ class Music:
self.player = self.VLC.media_player_new(path) self.player = self.VLC.media_player_new(path)
self.player.audio_set_volume(self.max_volume) self.player.audio_set_volume(self.max_volume)
DEBUG(f"music.play({path=}), {self.player}", True)
self.player.play() self.player.play()
self.current_track_start_time = datetime.now() self.current_track_start_time = datetime.now()
@ -140,15 +141,17 @@ class Music:
def stop(self): def stop(self):
"Immediately stop playing" "Immediately stop playing"
DEBUG("music.stop()") DEBUG("music.stop()", True)
if not self.player: if not self.player:
return None return None
position = self.player.get_position() position = self.player.get_position()
self.player.stop() self.player.stop()
self.player.release() p = self.player
# Ensure we don't reference player after release # Ensure we don't reference player after release
self.player = None self.player = None
DEBUG(f"Releasing play {p=}", True)
p.release()
return position return position