From a97fe2e0cf97a0124b3d2dfa160a2709fa332512 Mon Sep 17 00:00:00 2001 From: EKNr1 Date: Sat, 21 Dec 2024 20:58:28 +0100 Subject: [PATCH] Fixed "crash" when the last track of the playlist finished. --- wobuzz/player/player.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/wobuzz/player/player.py b/wobuzz/player/player.py index 824f95a..5400780 100644 --- a/wobuzz/player/player.py +++ b/wobuzz/player/player.py @@ -56,13 +56,18 @@ class Player: def track_finished(self): self.current_playlist_index += 1 - self.playing_track = self.current_playlist[self.current_playlist_index] - self.playing_segment = self.playing_track.sound - self.playing_segment_duration = self.playing_track.duration + if self.current_playlist_index < len(self.current_playlist): + self.playing_track = self.current_playlist[self.current_playlist_index] + self.playing_segment = self.playing_track.sound + self.playing_segment_duration = self.playing_track.duration - self.music_channel.play(self.playing_track.sound) - self.track_progress.start() - self.app.gui_communication.on_track_start() + self.music_channel.play(self.playing_track.sound) + self.track_progress.start() + self.app.gui_communication.on_track_start() + + else: + self.current_playlist_index -= 1 + self.stop() def start_playing(self): self.music_channel.play(self.playing_track.sound) @@ -114,6 +119,7 @@ class Player: self.music_channel.stop() self.track_progress.stop() self.playing = False + self.playing_segment_duration = self.playing_track.duration def seek(self, position: int): self.searched = True